CFF and OpenType Font Subsetting Functions

PDF Filter Support

 

Top  EnableFontSubsetting  Contents

These unit-level functions expose the public CFF, OpenType-CFF, and sfnt font-inspection surface used by HotPDF's embedded font pipeline. HotPDF also ships reusable Type 1 PFB and CFF parser units for callers that need lower-level font inspection

 

Delphi syntax

function HPDFSubsetCFF(const CFFBytes: TBytes; const KeepGlyph: array of Boolean): TBytes;

function HPDFIsCFF2Font(const FontBytes: TBytes): Boolean;

function HPDFInstantiateCFF2Font(const FontBytes: TBytes; const AxisValues: THPDFVariableFontAxisValueArray): TBytes;

function HPDFSubsetCFF2Font(const FontBytes: TBytes; const KeepGlyph: array of Boolean): TBytes;

function HPDFIsTrueTypeVariableFont(const FontBytes: TBytes): Boolean;

function HPDFInstantiateTrueTypeVariableFont(const FontBytes: TBytes; const AxisValues: THPDFVariableFontAxisValueArray): TBytes;

function HPDFSfntIsOTF(const Data: TBytes): Boolean;

function HPDFOTFFindCFFTable(const Data: TBytes; out TableOff: Cardinal; out TableLen: Cardinal): Boolean;

function HPDFSubsetOTFContainer(const OTFBytes: TBytes; const KeepGlyph: array of Boolean): TBytes;

function HPDFExtractTTFPostScriptName(const Data: TBytes): AnsiString;

 

Description

HPDFSubsetCFF rewrites a CFF font payload in place, preserving glyph IDs and replacing unused CharStrings and subroutines with minimal stubs. This is the helper for callers that already extracted a CFF table from a font container

 

HPDFIsCFF2Font detects an sfnt with a CFF2 table. HPDFInstantiateCFF2Font resolves selected fvar coordinates through avar 1.0 or 2.0, evaluates VariationStore-backed blend operations across recursive subroutines, bakes HVAR, VVAR, and MVAR metrics, removes variable tables, and returns a checksum-correct static sfnt

 

HPDFSubsetCFF2Font performs the same default-coordinate instancing whilst replacing unused glyph programs with empty CharStrings. It preserves glyph IDs, multi-FD dictionaries, private hint data, and font matrices

 

HPDFIsTrueTypeVariableFont detects an sfnt containing fvar, glyf, and loca. HPDFInstantiateTrueTypeVariableFont maps selected axes through avar, evaluates gvar tuples and IUP interpolation, updates simple and composite outlines plus phantom-point metrics, applies HVAR, VVAR, and MVAR where applicable, removes variation tables, and returns a checksum-correct static sfnt

 

HPDFSfntIsOTF detects an sfnt container whose version is OTTO. HPDFOTFFindCFFTable locates the embedded 'CFF ' table. HPDFSubsetOTFContainer subsets embedded CFF or CFF2 data and returns an OTF container with valid sfnt checksums. HPDFExtractTTFPostScriptName reads name ID 6 from the sfnt name table and returns the PostScript font name when present

 

The subsetter recognises both name-keyed CFF (single Private DICT, single Local Subr INDEX) and CID-keyed CFF (Top DICT ROS operator, FDArray of multiple sub-font Private DICTs, FDSelect glyph-to-FD map, per-FD Local Subr INDEXes). CID support covers CJK / Indic / Arabic OpenType-CFF fonts; the closure scan tracks each kept CharString's FD context so per-FD Local Subr INDEXes are independently subsetted

 

The lower-level CFF integer decoders, FDArray / FDSelect parsers, and subroutine scanners are implementation details behind this public helper surface

 

Type 1 and CFF parser units

HPDFType1Core, HPDFType1Glyphs, HPDFType1CFFHandler, and HPDFType1PFBHandler provide reusable byte-array readers, Type 1 glyph-outline command extraction, CFF Header / INDEX / dictionary / charset / encoding parsing, and Type 1 PFB metadata plus glyph lookup helpers. HPDFType1CFFHandler resolves SyntheticBase inheritance across a FontSet for Top and Private DICT values, CharStrings, charset, Encoding, and Local Subrs whilst rejecting invalid indices, cycles, and excessive depth. HPDFType1CB provides a C++Builder-friendly parser entry point. The units are included in the Delphi and C++Builder package projects so applications can inspect Type 1 PFB and CFF data without reimplementing the binary parsers

 

See also: EnableFontSubsetting, FontEmbedding, PDF Filter Support

Type 2 stack operations and subroutine safety

The native glyph renderer implements standard Type 2 Boolean, arithmetic, conditional, transient-array and stack operations, including put, get, ifelse, random, dup, exch, index and roll

Transient values reset for each glyph, random values are reproducible, and operand, transient-array, recursion and execution limits reject malformed programs without returning a partial outline

The subset scanner resolves arithmetic and transient-array expressions used by local and global subroutine calls, including Type 2 16.16 fixed-point operands

When random values, unknown transient state or interprocedural stack effects make a call target uncertain, subsetting retains every candidate subroutine rather than dropping a potentially reachable outline dependency

Reserved and deprecated Multiple Master operations remain unsupported and fail explicitly