web engine - experimental web browser

Parse glyf and OS/2 tables for glyph outline extraction #24

open opened by pierrelf.com

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 loca table to find glyph byte ranges within glyf

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#

  • GlyphOutline with contours as Vec<Contour>
  • Contour as Vec<Point> with on-curve/off-curve flags
  • Point { 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 warnings passes
  • cargo fmt --all --check passes
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mflhjb34bn2y