text
text
Mojo package 🡭
text
Modules
bidi: Unicode bidirectional layout for mixed-direction text.bidi_data: Unicode data forbidi.mojo, generated – do not hand-edit.cff: CFF (Compact Font Format) outlines, for OpenType-CFF (OTTO) fonts: theCFFtable’s INDEX and DICT structures, and a Type 2 charstring interpreter that turns a glyph’s program into aRawGlyphOutlineof 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, seepath.mojo).glyph_outline: Glyph outlines and metrics: the adapter betweenfont_discovery.mojo, which resolves a family/slant/weight to a file, andttf.mojo, which parses that file’s binary tables. Exposes theLineMetrics/GlyphMetrics/face_line_metrics/has_glyph/glyph_metrics/glyph_pathsurfacerender.mojocalls, each of the last two paired with aglyph_index_*form addressing a glyph directly, which is what aGSUBligature – 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 asGSUBisol/init/medi/finafeatures; this module decides which of the four each character is eligible for, sottf.mojocan enable that one feature on that one glyph.render: Text rendering: font matching fromfont_discovery.mojo, glyph outlines and metrics fromttf.mojoviaglyph_outline.mojo, and rasterization fromfill_path_aa(path.mojo) underFillRule.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 samefill_path_aaevery other shape uses, so translucent text composites throughset_pixellike any other fill.text_align: TextAlign, in its own module so it can be referenced bycanvas.vector.draw_target– and transitively bycanvas.buffer’sCanvas– without pulling in render.mojo’s font-touching imports (font_discovery.mojo/ttf.mojo/glyph_outline.mojo/bidi.mojo).from canvas.text.render import TextAlignalso works: render.mojo re-exports this same type.text_run: TextRun, in its own module for the reasontext_align.mojogives:canvas.vector.draw_targetandcanvas.buffername it in a signature and cannot import render.mojo, which importscanvas.bufferitself.from canvas.text.render import TextRunalso 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}).