PDFium Delphi Component Docs

Variable TrueType font instances

FPdfFontVariation adds an optional native preparation step in v3.206.0: freeze every variation axis to produce a standalone static TrueType program before existing embedding or subsetting operations

Public API

TPdfFontVariation = record
  Tag: AnsiString;
  Value: Single;
end;
TPdfFontVariations = array of TPdfFontVariation;

function InstantiatePdfVariableFont(const FontProgram: TBytes;
  const Variations: TPdfFontVariations; out InstanceProgram: TBytes;
  out ErrorMessage: string; FaceIndex: Word = 0;
  const LibraryName: string = ''): Boolean;

Axis selection and output

Tag is a case-sensitive four-byte printable ASCII OpenType axis tag such as wght, wdth or opsz; Value is a finite design-space coordinate within that axis's declared minimum and maximum

Requested axes use the supplied coordinates and every omitted axis is fixed to its source default; an empty Variations array produces the default instance

Every original glyph identifier and the glyph count are retained; the result is a standalone static TrueType program with no remaining variation axes. Since v3.216.0 the native input flags also explicitly preserve the .notdef outline, keeping visible missing-glyph rendering when GID zero is referenced

FaceIndex selects a zero-based face in a TrueType Collection and must be zero for a standalone font; an out-of-range index rejects instead of accepting the native backend's face fallback

InstanceProgram is assigned only after complete validation, with an empty ErrorMessage on success; expected validation, loading or backend failures return False with empty output and an English diagnostic

Source bytes are not modified; ordinary allocation or operating-system exceptions can still propagate

Optional native dependency

The helper is available on Windows and native Free Pascal Unix builds; existing text creation does not require this helper or its dependencies

LibraryName selects the HarfBuzz subset library for this call; when a directory is supplied, the matching core library is loaded from the same directory

Default names are libharfbuzz-subset-0.dll and libharfbuzz-0.dll on Windows, libharfbuzz-subset.so.0 and libharfbuzz.so.0 on Linux, and libharfbuzz-subset.0.dylib and libharfbuzz.0.dylib on Darwin

A suitable matching library pair must supply every required symbol, including hb_subset_input_pin_axis_location; the helper checks exports and releases its objects and module references after each call

Embedding and subsetting

Pass the instance bytes to AddCidType2Text with explicit glyph mappings and advances computed for that instance, or use TPdfTrueTypeSubsetBackend to subset the static program

Retaining IDs permits source glyph selection to remain stable, but variation axes can change advances and outlines; metrics from another instance are not interchangeable

This helper does not change system font lookup, AddText axis selection, shaping configuration or font embedding-policy fields

SetLength(Axes, 1);
Axes[0].Tag := 'wght';
Axes[0].Value := 700;
if not InstantiatePdfVariableFont(SourceFont, Axes, StaticFont, Error) then
  raise Exception.Create(Error);

Limits and verification

Input and published output are limited to 64 MiB each, with one to 64 source axes, at most 64 requested axes and one to 65,535 glyphs; duplicate or unknown tags, malformed input, static inputs, programs without variable TrueType outlines, non-finite coordinates and out-of-range values reject

These checks bound accepted data, not every allocation or operation inside the native parser and instancer; no timeout or native-memory ceiling is promised

Focused evidence covers Segoe UI Variable and Bahnschrift axis coordinates, selected TTC faces, independent outline/advance comparisons, retained cmap/GIDs, static subsetting and exact PDF save/reload text and pixels on Delphi Win64; the helper also executes on native WSL Linux x64 with FPC

Other fonts, colour/bitmap programs, Win32 native HarfBuzz, physical Linux hosts, Darwin execution and complex-script shaping at arbitrary axis locations require separate qualification

Retained-GID collection-face extraction

Since v3.264.0, ExtractPdfTrueTypeFace(FontProgram, FaceProgram, ErrorMessage, FaceIndex, LibraryName) extracts a bounded standalone glyf TrueType face from a font or collection with every original GID retained; the zero-based face defaults to 0 and input/output are limited to 64 MiB

This preparation API preserves variable tables until explicit instantiation and does not grant embedding permission; document optimisation additionally validates both source policies, mapped glyphs and native appearance through FontSelections

The physical Ubuntu x64 FPC 3.3.1/Qt6 profile at v3.217.0 verifies default, requested, partial and selected-collection instances, preserved GIDs/cmap/advances/outlines, optional dependency rejection and native embedding/save/reopen; this does not qualify other native targets or the separate existing-document optimiser