PaperForge.Fonts.TrueType.Subsetter (PaperForge v0.6.0)

Copy Markdown View Source

Builds physical TrueType subsetting plans.

The subset preserves original glyph identifiers, so the PDF Type 0 font can continue to use its existing CID mapping. Unused glyph programs are removed while composite dependencies are retained. This trades the smallest possible font for a safe, deterministic physical subset that needs no CID remapping.

Summary

Functions

Rebuilds a physical TrueType subset containing only requested glyph programs and their composite dependencies.

Types

plan()

@type plan() :: %{
  binary_hash: binary(),
  requested_glyphs: [non_neg_integer()],
  glyphs: [non_neg_integer()],
  composite_dependencies: [non_neg_integer()],
  rebuild_tables: [binary()],
  checksums: %{optional(binary()) => non_neg_integer()}
}

Functions

binary_hash(data)

@spec binary_hash(binary()) :: binary()

checksum(data)

@spec checksum(binary()) :: non_neg_integer()

checksums(tables)

@spec checksums(%{optional(binary()) => binary()}) :: %{
  optional(binary()) => non_neg_integer()
}

plan(font, glyph_ids)

subset(font, glyph_ids)

@spec subset(PaperForge.Fonts.TrueType.t(), Enumerable.t()) :: %{
  data: binary(),
  plan: plan(),
  checksums: map()
}

Rebuilds a physical TrueType subset containing only requested glyph programs and their composite dependencies.

The rebuilt font preserves the original glyph count and hmtx metrics. This makes it safe for a PDF that already addresses glyphs by their original CID. glyf, loca, hmtx, and maxp are included in the reconstructed table directory and every table checksum is recalculated.