Skip to main content

Module subset

Module subset 

Source
Expand description

§TrueType Font Subsetter

Strips a TrueType font to only the glyphs actually used in the document. This dramatically reduces PDF size — a typical font is 50-200KB but a subset with ~100 glyphs is usually 5-15KB.

The subsetter rebuilds a valid TrueType file with remapped glyph IDs (contiguous starting from 0). This is important because PDF CIDFont width arrays and content stream glyph references must use the new IDs.

§Approach

  1. Collect all needed glyphs (used glyphs + composite glyph dependencies)
  2. Remap old GIDs to new contiguous GIDs
  3. Rebuild required TrueType tables (glyf, loca, hmtx, cmap, etc.)
  4. Write a valid TrueType file with correct checksums and alignment

Structs§

SubsetResult
Result of subsetting a font.

Functions§

subset_ttf
Subset a TrueType font to only include the given glyph IDs.