Skip to content
text

text

Mojo package 🡭

text

Modules

  • bidi: Unicode bidirectional layout for mixed-direction text.
  • bidi_data: Unicode data for bidi.mojo, generated – do not hand-edit.
  • cff: CFF (Compact Font Format) outlines, for OpenType-CFF (OTTO) fonts: the CFF table’s INDEX and DICT structures, and a Type 2 charstring interpreter that turns a glyph’s program into a RawGlyphOutline of cubic contours. Layout and operator semantics follow Adobe Technical Notes #5176 (CFF) and #5177 (Type 2 charstrings).
  • font_cache: Caller-owned cache for font resolution, parsed faces, and glyph masks.
  • font_discovery: Font discovery: resolves a family/slant/weight request to a font file path on disk, with no linked library. One of the three parts of text rendering, alongside glyph resolution and metrics (ttf.mojo) and rasterization (fill_path_aa, see path.mojo).
  • glyph_outline: Glyph outlines and metrics: the adapter between font_discovery.mojo, which resolves a family/slant/weight to a file, and ttf.mojo, which parses that file’s binary tables. Exposes the LineMetrics/GlyphMetrics/face_line_metrics/has_glyph/ glyph_metrics/glyph_path surface render.mojo calls, each of the last two paired with a glyph_index_* form addressing a glyph directly, which is what a GSUB ligature – a glyph no single codepoint names – is laid out through.
  • joining: Arabic joining: which contextual form – isolated, initial, medial or final – each letter of a run takes from the letters beside it. An Arabic font ships four glyphs for a dual-joining letter and states the choice between them as GSUB isol/init/medi/fina features; this module decides which of the four each character is eligible for, so ttf.mojo can enable that one feature on that one glyph.
  • render: Text rendering: font matching from font_discovery.mojo, glyph outlines and metrics from ttf.mojo via glyph_outline.mojo, and rasterization from fill_path_aa (path.mojo) under FillRule.NONZERO, the rule TrueType outlines are drawn with, which also puts every glyph on the exact-area rasterizer (canvas.aa_area). The glyph path is unhinted. Glyphs fill through the same fill_path_aa every other shape uses, so translucent text composites through set_pixel like any other fill.
  • text_align: TextAlign, in its own module so it can be referenced by canvas.vector.draw_target – and transitively by canvas.buffer’s Canvas – without pulling in render.mojo’s font-touching imports (font_discovery.mojo/ttf.mojo/glyph_outline.mojo/bidi.mojo). from canvas.text.render import TextAlign also works: render.mojo re-exports this same type.
  • text_run: TextRun, in its own module for the reason text_align.mojo gives: canvas.vector.draw_target and canvas.buffer name it in a signature and cannot import render.mojo, which imports canvas.buffer itself. from canvas.text.render import TextRun also works: render.mojo re-exports this type beside the function that lays a list of them out.
  • ttf: Native TrueType (sfnt/glyf) font file parser: reads a font file’s binary tables directly (table directory, head, maxp, hhea, hmtx, cmap, glyf, loca, kern, GPOS, GSUB) rather than linking a font library. Field offsets and decode algorithms follow Microsoft’s OpenType 1.9.1 specification (learn.microsoft.com/ typography/opentype/spec/{otff,head,maxp,hhea,hmtx,cmap,loca,glyf,kern, gpos,gsub,chapter2}).