Skip to content

C# Font Reader (TrueType / OpenType / OpenFont / CFF / woff / woff2) , Glyphs Layout and Rendering

License

Notifications You must be signed in to change notification settings

woodssh/Typography

 
 

Repository files navigation

Typography, this image was rendered with this library, in subpixel rendering mode

Pure C# TrueType/OpenType/OpenFont Reader, Glyph Layout and Rendering.

During developing the PixelFarm Rendering library, I think 'How-to-render-a-font-glyph' may be useful for other libraries.

So, I spinned off the 'How-to-render-a-font-glyph' part to here, the Typography library.

The Typography lib does NOT need the PixelFarm Rendering library.

gdiplus_sample1

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)).

Concept

  • 1.Load .ttf, .otf, .ttc, .otc, .woff, .woff2 files, with OpenFontReader.

  • 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

What are each project used for?

See => LayoutFarm#99

Screenshots

Some screenshots of the current master.

Enable TrueType Hinting, Tahoma, 8 pts

enable_truetype_hinting


Tahoma, 72 pts (TrueType Hinting: disabled)

compare1_tahoma_72pts


Tahoma, 8 pts, (TrueType Hinting: disabled)

compare2_tahoma_8pts


Tahoma, 11 pts (TrueType Hinting: disabled)

compare3_tahoma_11pts


Kerning: Enabled

enable_kerning1


Subpixel Rendering

lcd_09

Tahoma, grey-scale vs lcd-effect subpixel rendering

typography_thanamas

lcd-effect subpixel rendering, Sov_Tahanamas font from https://www.f0nt.com/release/sov_thanamas/


A Multi-channel signed distance field (Msdf) Texture (https://github.com/Chlumsky/msdfgen)

msdfgen


Another Msdf Texture

msdfgen2


A Msdf Texture Sample msdf_test_03


An Android GLES2-based demo

gles_android_emu

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.

gles_android_emu

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

ligature

pic 1: Showing GSUB's glyph ligature, see f-i

(see more : LayoutFarm#80 (comment))


2. GPOS

gpos

pic 2: Testing with Thai (complex script) glyph that require gpos table


3. GSUB : ccmp

gsub

pic 3: Testing with Thai glyphs (complex script), showing glyph substitution


4. GSUB and GPOS

th_glyph

th_glyph2

pic 4: testing with Thai glyph (complex script)

th_sarabun

pic 5: complex GSUB-GPOS, Sarabun font from https://github.com/cadsondemak/Sarabun

(see more: LayoutFarm#82 (comment))


Fun with Emojis!

Emojis and related features were contributed by @samhocevar.

typo_symbol

pic 1: Segoe UI Symbol Normal, on Windows 7

typo_symbol2

pic 2: FireFoxEmoji.ttf from https://github.com/mozilla/fxemoji

typo_symbol3

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:

image

And here it is with ccmp:

image

pic 4: Say with Emoji?

(see: LayoutFarm#18)

(see more sam's work at https://github.com/samhocevar/emoji.wpf)


CFF Font and MathTable

Typography can read CFF font(.otf)

In this version, the results are not hinted by CFF instructions, so they are not pixel-perfect.

latin_long_compare

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


Web Open Font Format (WOFF1 and WOFF2)

woff2

Roboto-Regular.woff2, Typography reads and restores woff2

see LayoutFarm#27


The HtmlRenderer example!

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).

html_renderer_with_selection2

pic 1: HtmlRenderer on GLES2 surface, text are renderered with the Typography

Also, please note the text selection on the Html Surface.


License

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

About

C# Font Reader (TrueType / OpenType / OpenFont / CFF / woff / woff2) , Glyphs Layout and Rendering

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.9%
  • Other 0.1%