ttf
Mojo module 🡭
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}).
Scope:
- TrueType (
glyf) and CFF outlines. AnOTTOfont’sCFFtable is read by cff.mojo, whose Type 2 charstring interpreter produces cubic contours whereglyfgives quadratic ones with implied midpoints;RawGlyphOutline.cubicsays which, andoutline_to_pathdecomposes accordingly.CFF2is not read. - Pair kerning, through
kern_adjustment:GPOSlookup type 2 (PairPos formats 1 and 2, including behind an extension lookup type 9) under thekernfeature, and thekerntable’s format 0 horizontal subtables. No mark attachment, no contextual positioning, and lookup flags such as IgnoreMarks are not honored – an intervening mark glyph breaks a pair here where a full shaper would kern through it. - Single and ligature substitution, through
substitute_glyphs:GSUBlookup types 1 and 4 (including behind an extension lookup type 7) – enough for the Latin “fi”/“fl”/“ffi” ligatures and for Arabic contextual forms. The multiple, alternate, contextual and chained-context substitutions the same features also use are skipped, and lookup flags (IgnoreMarks and the rest) are not honored. Features are selected from one script’s default language system:ccmpandligaforlatn, and forarabthe OpenType Arabic orderccmp,isol,fina,medi,init,rlig,liga,calt. Each glyph carries a mask of the features enabled on it, so one sweep offinareaches only the letters a caller marked final. Substitution runs in logical order, per bidi run. - No hinting. Every glyph goes through
fill_path_aa’s supersampled coverage AA instead, which keeps unhinted outlines correct at the sizes a chart uses. - Variable fonts (
fvar/gvar) read as their default instance:glyf/locahold the non-varied outlines andgvar’s per-instance deltas are never read. - Composite glyphs (“é” = “e” + combining acute) are supported,
including the scale/2x2-transform component flags. Point-matching
placement (
ARGS_ARE_XY_VALUESunset) raises.
Structs
ShapedRun: A glyph sequence afterGSUBsubstitution.clusters[i]is how many of the input glyphsglyphs[i]stands for – 1 for a glyph left alone or substituted one for one, 3 for an “ffi” ligature – so a caller can walk back to the characters each output glyph came from. The two lists are the same length, and the clusters sum to the input length.changedis False when no lookup fired, which lets a caller skip that walk entirely.RawGlyphOutline: A decoded glyph outline in plain-Listform: on-curve/off-curve points plus per-contour end indices – FreeType’sFT_Outlineshape (points, tags, contour ends) as ownedLists rather than raw C pointers, so this module has no pointer surface.BitmapMetrics: A color bitmap glyph’s placement, in the strike’s own pixels:foundis False when the glyph has no bitmap.bearing_yis the distance from the baseline up to the bitmap’s top edge, as in thesbitmetrics.TTFFace: A parsed TrueType font file: the raw file bytes plus the table offsets and global metrics this module reads.