Skip to main content

Overview

PinataLabs.Typography is a .NET library that loads fonts and lays out and measures text. It is written in C# and has no native dependencies, so it runs the same way on Windows, Linux and macOS.

The library does not draw pixels. It tells you where each glyph goes, how big the text is, and the outline of each glyph. You send those outlines to your own drawing code, for example a PDF writer, an image library or a GPU renderer.

What you can do​

  • Load fonts from files, streams and the fonts installed on the machine. The library reads TrueType (.ttf), OpenType with CFF1 and CFF2 outlines (.otf), TrueType collections (.ttc), and WOFF and WOFF2 web fonts. See Loading fonts and System fonts.
  • Read font information such as the family name, the style, the version and the copyright, without loading the whole font. See Font descriptions.
  • Measure text: its size, its advance, its ink bounds, the number of lines, and the position of each character. See Measuring text.
  • Lay out paragraphs: wrap lines at a width, align and justify them, set line spacing and tab width. Lines break by the rules of UAX #14. See Wrapping and alignment.
  • Mix styles in one string: change the font, underline, strike out, or raise and lower parts of the text. See Rich text.
  • Set text in many scripts: right-to-left and bidirectional text, joined Arabic letters, Indic, Hangul and other complex scripts, and fallback fonts for characters the main font does not have. See International text and Fallback fonts.
  • Set vertical text for Chinese, Japanese and Korean. See Vertical text.
  • Use OpenType features: ligatures, kerning, small capitals, old-style figures and more, from the font's GSUB and GPOS tables. See OpenType features.
  • Get glyph outlines as lines and Bézier curves, including the layers of color emoji. See Glyph renderers and Color fonts.

How the parts fit together​

FontCollection / SystemFonts -> FontFamily -> Font (family + size + style)
|
v
"your text" + TextOptions (font, wrapping, alignment, direction, features, ...)
|
+--------------------------------+-------------------------------+
v v
TextMeasurer TextRenderer
sizes, bounds, line count, per-character positions glyph outlines sent to your IGlyphRenderer
  1. You get a FontFamily from a FontCollection that you fill, or from SystemFonts.
  2. You create a Font from the family. A font is a family at one size and one style.
  3. You put the font in a TextOptions object, and set how the text is laid out.
  4. You give the text and the options to TextMeasurer to measure it, or to TextRenderer to get the glyph outlines.

Concepts explains the words that the rest of these pages use, such as point, DPI, advance and bounds.

Where to go next​

Origin​

PinataLabs.Typography is derived from SixLabors.Fonts. It was forked at commit 32bef429 and has been changed by PinataLabs. It is not affiliated with or endorsed by Six Labors. If you use SixLabors.Fonts today, read Migrating from SixLabors.Fonts.