Text

edit

The library draws text with fonts it reads itself: TrueType, OpenType, WOFF and WOFF2 files. It lays out the text (shaping, line breaking, bidirectional ordering, vertical lines) and fills the outlines of the glyphs like any other shape of the drawing API. Nothing comes from the operating system unless you ask for an installed font, so a text gives the same pixels on every machine.

The text types are in the Meziantou.Framework.Imaging.Typography namespace:

TypeWhat it is
FontOne face of a font file, immutable and thread-safe
FontStackA font and the fonts used for the characters it does not have
TextStyleHow a text is set: its fonts, its size, its paint, its features and decorations
RichTextA text whose parts have their own style, built with RichTextBuilder
TextLayoutOptionsHow lines are wrapped, aligned, cut and directed
TextLayoutA text laid out: what is measured is what FillText and StrokeText draw

The usual flow is: load a font once, create a TextLayout, measure it if you need to place it, then draw it with canvas.FillText inside image.Draw.

Pages of this section

  • Fonts: load font files and installed fonts, variable fonts and their instances, color glyphs, and the limits that protect you from hostile fonts.
  • Drawing text: draw a string, place it by a point of its box, wrap paragraphs, give parts of the text their own style, and fit a text in a box.
  • Text layout: fallback fonts, right-to-left and vertical text, alignment and hyphenation, synthetic bold and oblique, the language of a text and how it is shaped.
  • Text on paths and measuring: make a text follow a curve, measure it, find the character under a point, draw carets and selections, draw your own glyph runs, and hint small text.