Phase 2: Pure Rust Font Engine#
Parse the remaining font tables needed for glyph rendering:
glyf table (Glyph Data)#
Extract TrueType glyph outlines from the glyf table:
- Simple glyphs: Parse glyph header (numberOfContours, xMin, yMin, xMax, yMax), endPtsOfContours array, instruction bytes, flags array, and x/y coordinate arrays (with delta decoding)
- Compound/composite glyphs: Parse component records with glyph indices, transformation matrices (scale, rotation, translation), and flags (ARG_1_AND_2_ARE_WORDS, WE_HAVE_A_SCALE, etc.)
- Handle flag bits: ON_CURVE_POINT, X_SHORT_VECTOR, Y_SHORT_VECTOR, REPEAT_FLAG, X_IS_SAME_OR_POSITIVE, Y_IS_SAME_OR_POSITIVE
- Use the already-parsed
locatable to find glyph byte ranges withinglyf
OS/2 table#
Parse the OS/2 table for font-wide metrics:
- sTypoAscender, sTypoDescender, sTypoLineGap
- usWeightClass, usWidthClass
- fsType (embedding restrictions)
- sxHeight, sCapHeight (if version >= 2)
- yStrikeoutSize, yStrikeoutPosition
- ySuperscriptYOffset, ySubscriptYOffset
Data structures#
GlyphOutlinewith contours asVec<Contour>ContourasVec<Point>with on-curve/off-curve flagsPoint { x: i16, y: i16, on_curve: bool }- Public API:
Font::glyph_outline(glyph_id) -> Option<GlyphOutline>
Acceptance criteria#
- Simple glyph outlines are correctly extracted (test with known glyphs)
- Compound glyphs are flattened to simple outlines
- OS/2 table metrics are parsed and accessible
- All existing tests continue to pass
-
cargo clippy --workspace -- -D warningspasses -
cargo fmt --all --checkpasses