Retained-ID TrueType font subsetting
FPdfFontSubset supplies a portable concrete backend for SubsetExistingPdfFont, without a native font-subsetting dependency
Public API
TPdfTrueTypeSubsetBackend = class(TInterfacedObject,
IPdfFontSubsetBackend, IPdfFontSubsetClosureBackend)
function Subset(const FontProgram: TBytes; const Glyphs: TPdfGlyphInfos;
out SubsetProgram: TBytes): Boolean;
function SubsetWithClosure(const FontProgram: TBytes;
const Glyphs: TPdfGlyphInfos; out SubsetProgram: TBytes;
out GlyphClosure: TPdfGlyphInfos; out ErrorMessage: string): Boolean;
end;
The backend accepts standalone static TrueType SFNT programs with glyf, loca, head, maxp, hhea and hmtx tables, within 64 MiB and 65536 requested glyph records
Glyph zero and recursively referenced composite components are retained, glyph IDs and the original glyph count remain stable, and unrequested outlines become empty slots
Retained glyph bytes, metrics, character mappings, font names and hint tables are preserved; the backend rebuilds long-format loca, table offsets, table checksums and head.checksumAdjustment, and removes the obsolete DSIG table
Composite graphs are bounded to depth 128 and 1048576 visits, and cycles, invalid components, overlapping tables and invalid ranges are rejected
TrueType Collections, CFF/CFF2, variable fonts, color/bitmap outlines and embedding policies that prohibit outline subsetting are rejected with empty backend output and an error message
Since v3.206.0, InstantiatePdfVariableFont can first pin a variable TrueType font or selected collection face to a static instance through optional HarfBuzz; this backend can then subset that standalone static result while retaining its glyph IDs
For an optional native alternative with qualified CBDT/CBLC font-program support and native dependency closure, use TPdfHarfBuzzSubsetBackend; bitmap-program output does not establish native PDFium bitmap embedding support
SubsetWithClosure reports a sorted unique dependency closure and preserves the first supplied metadata for duplicate requested IDs; added dependencies have zero UnicodeValue and Width metadata
Use SubsetExistingPdfFont to apply byte/glyph budgets and minimum-saving thresholds with original-program preservation, or SubsetPdfDocumentFonts to replace proven document resources
Backend := TPdfTrueTypeSubsetBackend.Create; Options := TPdfFontSubsetOptions.Default; Applied := SubsetExistingPdfFont(Original, UsedGlyphs, Backend, Options, SubsetProgram, Closure, Report);
This backend preserves the requested glyph repertoire and its composite dependencies; using new characters outside that repertoire requires a new font program