Native CFF2 text and PDF font embedding

Starting in version 2.1102.0, ordinary native text can use a registered CFF2 font without relying on Windows to install or select that outline format. SetFont recognizes the registered font's original family, full, PostScript and typographic family names and selects its frozen static font bytes

PDF.BeginDoc;
PDF.SetVariableFontAxis('wght', 650);
PDF.RegisterUnicodeTTF(FontPath);
PDF.CurrentPage.SetFont(FamilyName, [], 12, DEFAULT_CHARSET);
PDF.CurrentPage.UnicodeTextOut(72, 100, 0, Text);
PDF.EndDoc;

The registered cmap and hmtx tables supply glyph IDs and advances. BMP characters, supplementary characters and synthetic shaping carriers retain per-font Unicode mappings; switching fonts or pages does not make another embedded font update the registered font's subset state

GetWideTextWidth and GetWideCharAdvances use the selected byte-backed font's metrics, including one advance for a UTF-16 surrogate pair. Pending variable-axis changes continue to affect future registration rather than the current instance

PDF font program

PDF text uses the original glyph IDs as CIDs. The writer converts static CFF2 outlines to a CID-keyed CFF1 stream, embeds it through FontFile3 with subtype CIDFontType0C and uses a CIDFontType0 descendant with Identity-H or Identity-V encoding

The CFF charset preserves CID = original GID, including empty and unused slots. PDF widths, CFF advances and ToUnicode mappings refer to that same geometry. The converted descendant has no TrueType CIDToGIDMap and is excluded from the later registered TrueType font-stream replacement hook

Conversion currently retains the complete glyph set, whether EnableFontSubsetting is enabled or disabled. No-subsetting permissions are therefore preserved. Original copyright and license records, the original name table and embedding flags are retained in the CFF Notice; restricted or bitmap-only embedding is rejected under the existing native outline-embedding policy

The converter is Pascal code and adds no HarfBuzz or system-font installation dependency. It does not change the separate headless appearance conversion workflow

Portable conversion API

function HPDFConvertCFF2ToCFF(const FontBytes: TBytes;
  const AxisValues: THPDFVariableFontAxisValueArray;
  Control: THPDFVariableFontControl = nil): TBytes;

This HPDFOpenTypeAdvanced function returns a raw CID-keyed CFF1 program rather than an sfnt container. Variable input is resolved through geometry-only static instancing, including selected outlines and advances; static input accepts an empty selection

The output uses FontMatrix = [1/UnitsPerEm 0 0 1/UnitsPerEm 0 0] and an explicit width operand relative to nominalWidthX = 32768, retaining the full unsigned 16-bit advance range. Large relative moves and lines are split into representable steps, and cubic curves are subdivided while preserving geometry

Invalid input, unsupported axis selections or denied outline embedding returns an empty byte array. Non-finite selections are rejected. The control object preserves cancellation, allocation and output checks, and budget or cancellation exceptions remain visible

Default limits include a 128 MiB font/output bound, a 1 GiB cumulative working admission bound and the CFF1 65535-byte CharString limit. These are finite conversion limits rather than a claim that every valid CFF2 font is representable as CFF1

Focused verification

The portable converter passes 944 independent checks across 40 cases, covering 70 glyphs and 253 source outline commands. Coverage includes cubic and flex boundaries, empty glyphs, selected TEST and wght/avar coordinates, UnitsPerEm 2048, zero and 65535 advances, large relative coordinates, embedding restrictions and controlled cancellation/budget failures

Ordinary text controls use independent CFF2 and TrueType font geometry, separate native processes, default and selected axes, BMP/SMP content, font switching, two-page output and both source subsetting settings. All 296 checks and 1152 MuPDF/Poppler samples pass across eight executions. Two additional TrueType subset-on executions pass 62 checks, and a separate cross-font isolation probe passes 43 behavior/structure/representative-pixel assertions

The preceding source records four subset-on process failures and 522 failures among 576 available reader samples. Final coverage includes additional outputs that could not be saved on that baseline; the two totals are not a same-size test comparison. Original failures and intermediate findings remain preserved

The same integration repairs sfnt checksum arithmetic in the native TrueType subset writer: both table and whole-font sums and checkSumAdjustment retain modulo-32 behavior under overflow checking

See CFF2 color glyph outlines, selected-axis color glyphs and RegisterUnicodeTTF