While developing the PixelFarm Rendering library, I figured that the way to render a glyph from a font may be useful for other libraries.
So, I spinned off the way to render a glyph from a font to here, the Typography library.
The Typography library does NOT need the PixelFarm Rendering library.
Typography project's Solution Explorer View
As shown in the above screenshot, an example (marked with (1)
) that uses Typography with WinGdiPlus is provided,
and an example (marked with (2)
) the uses Typography with a 'mini' snapshot of PixelFarm Rendering library (marked with (3)
).
- 1.Load .ttf, .otf, .ttc, .otc, .woff, .woff2 files, with OpenFontReader.
System.IO.Stream stream = ...;
var reader = new Typography.OpenFont.OpenFontReader();
var typeface = reader.Read(stream); // stream is disposed inside Read
if (typeface is null &&
reader.ReadPreview(stream) is var preview &&
preview.IsFontCollection) {
// .ttc or .otc
for (int i = 0; i < preview.MemberCount; i++) {
typeface = reader.Read(stream, preview.GetMember(i).ActualStreamOffset); // choose a font...
}
}
// use typeface
-
2.Rasterize a character to a bitmap with a pure software renderer which has Agg(anti grain geometry) Quality! with our PixelFarm's MiniAgg :) (https://github.com/PaintLab/PixelFarm)
-
Supported platforms: .Net Framework >= 2.0 or .Net Standard >= 1.3
See => LayoutFarm#99
Some screenshots of the current master.
Enable TrueType Hinting, Tahoma, 8 pts
Tahoma, 72 pts (TrueType Hinting: disabled)
Tahoma, 8 pts, (TrueType Hinting: disabled)
Tahoma, 11 pts (TrueType Hinting: disabled)
Kerning: Enabled
Subpixel Rendering
Tahoma, grey-scale vs lcd-effect subpixel rendering
lcd-effect subpixel rendering, Sov_Thanamas font from https://www.f0nt.com/release/sov_thanamas/
A Multi-channel signed distance field (Msdf) Texture (https://github.com/Chlumsky/msdfgen)
Another Msdf Texture
An Android GLES2-based demo
pic 1: GLES2-based android demo, DroidSans.ttf. Each glyph is tesselated to GlyphRun mesh (with C# Tesselator), and is rendered directly to GLES2 shader.
pic 2: The same technique as pic1, msjh.ttf, '啊rAbc' ,
Please note that baseline of 啊 is not correct
Advanced OpenFont Text Shaping
1. GSUB : Ligature features
pic 1: Showing GSUB's glyph ligature, see f-i
(see more : LayoutFarm#80 (comment))
2. GPOS
pic 2: Testing with Thai (complex script) glyph that require gpos table
3. GSUB : ccmp
pic 3: Testing with Thai glyphs (complex script), showing glyph substitution
4. GSUB and GPOS
pic 4: testing with Thai glyph (complex script)
pic 5: complex GSUB-GPOS, Sarabun font from https://github.com/cadsondemak/Sarabun
(see more: LayoutFarm#82 (comment))
Emojis and related features were contributed by @samhocevar.
pic 1: Segoe UI Symbol Normal, on Windows 7
pic 2: FirefoxEmoji.ttf from https://github.com/mozilla/fxemoji
pic 3: Segoe UI Emoji Normal, on Windows 10
Advanced Emoji Ligatures
This is 👩🏾👨🏾👧🏾👶🏾 “Family - Woman: Medium-Dark Skin Tone, Man: Medium-Dark Skin Tone, Girl: Medium-Dark Skin Tone, Baby: Medium-Dark Skin Tone” without
ccmp
ligatures:
And here it is with
ccmp
:
pic 4: Say with Emoji?
(see: LayoutFarm#18)
(see more sam's work at https://github.com/samhocevar/emoji.wpf)
Typography can read CFF font(.otf)
In this version, the results are not hinted by CFF instructions, so they are not pixel-perfect.
pic 1: compare with Win7's NotePad, latin-modern-math-regular.otf, 18 pts
Further more=> Typography can read all advanced MathTable.
See its action here => CSharpMath
Roboto-Regular.woff2, Typography reads and restores woff2
see LayoutFarm#27
This is a snapshot of Html drawboard from (https://github.com/LayoutFarm/HtmlRenderer). The glyphs are generated/layouted with Typography, and rendered with PixelFarm (https://github.com/PaintLab/PixelFarm).
pic 1: HtmlRenderer on GLES2 surface, text are renderered with the Typography
Also, please note the text selection on the Html Surface.
The project is based on multiple open-sourced projects (listed below) all using permissive licenses.
A license for a whole project is MIT.
But if you use some part of the codebase, please check each source file's header for the licensing info if available.
Font
Apache2, 2014-2016, Samuel Carlsson, Big thanks for https://github.com/vidstige/NRasterizer
MIT, 2015, Michael Popoloski, https://github.com/MikePopoloski/SharpFont
The FreeType Project LICENSE (3-clauses BSD style),2003-2016, David Turner, Robert Wilhelm, and Werner Lemberg and others, https://www.freetype.org/
MIT, 2016, Viktor Chlumsky, https://github.com/Chlumsky/msdfgen
Apache2, 2018, Apache/PDFBox Authors, https://github.com/apache/pdfbox
Geometry
BSD, 2002-2005, Maxim Shemanarev, Anti-Grain Geometry - Version 2.4 http://www.antigrain.com
BSD, 2007-2014, Lars Brubaker, agg-sharp, https://github.com/MatterHackers/agg-sharp
MIT, 2016, Viktor Chlumsky, https://github.com/Chlumsky/msdfgen
BSD, 2009-2010, Poly2Tri Contributors, https://github.com/PaintLab/poly2tri-cs
Apache2, 2016-2017, WinterDev, https://github.com/PaintLab/PixelFarm
Platforms
MIT, 2015-2015, Xamarin, Inc., https://github.com/mono/SkiaSharp
MIT, 2006-2009, Stefanos Apostolopoulos and other Open Tool Kit Contributors, https://github.com/opentk/opentk
MIT, 2013, Antonie Blom, https://github.com/andykorth/Pencil.Gaming
MIT, 2004, 2007, Novell Inc., for System.Drawing
Unpack, Zlib,Brotli
MIT, 2018, SharpZipLib, https://github.com/icsharpcode/SharpZipLib
MIT, 2009, 2010, 2013-2016 by the Brotli Authors., https://github.com/google/brotli
MIT, 2017, brezza92 (C# port from original code, by hand), https://github.com/brezza92/brotli
MIT, 2019, master131, https://github.com/master131/BrotliSharpLib
Demo
MIT, 2017, Zou Wei, https://github.com/zwcloud, see more Zou Wei's GUI works at here and here