Shaping-Aware Font Subsetting and Dependency Closure with HarfBuzz
Why Naive Glyph Stripping Breaks Ligatures and Composite Accents
Multi-script corporate and open-source typefaces routinely span 2,000 to 15,000 glyphs covering Cyrillic, Greek, Vietnamese, and technical math symbols, inflating unsubsetted TTF files past 400 KB. Partitioning a font by CSS unicode-range intervals lets browsers download only the slices required by characters actually rendered on the current page.
Safe subsetting requires graph closure across OpenType tables. When you request U+0041 and U+0100 through harfbuzz-subset.wasm, HarfBuzz traces cmap mappings, follows TrueType composite component pointers (retaining the unmapped macron contour needed by Ā), prunes GSUB/GPOS lookups to kept glyph indices, re-indexes glyph IDs compactly, and preserves Name IDs 0, 13, and 14 for license compliance.
- Accepts single hex scalars (U+0100), closed intervals (U+0020-007E), and ? wildcard masks.
- Runs standalone zero-import harfbuzz-subset.wasm inside a memory-safe Worker.
- Reports retained cmap count, unmapped component glyphs, and missing code points.
- Generates synchronized CSS unicode-range descriptors ready to paste into @font-face.