PDFium Delphi Component Docs

AddCidType2Text method

Component: TPdf  ·  Unit: PDFium

Syntax

function AddCidType2Text(const FontData: TBytes; const Glyphs: TPdfCidGlyphs; FontSize: Single; X, Y: Double; out Report: TPdfCidFontReport; Color: TColor = clBlack; Alpha: Byte = $FF): Boolean; overload;
function AddCidType2Text(const FontData: TBytes; const Glyphs: TPdfCidGlyphs; FontSize: Single; X, Y: Double; const Options: TPdfCidFontOptions; out Report: TPdfCidFontReport; Color: TColor = clBlack; Alpha: Byte = $FF): Boolean; overload;

Description

Loads caller-supplied TrueType or TrueType Collection data through PDFium's native CID Type 2 font loader and appends one or more positioned text objects to the active page

Each TPdfCidGlyph supplies a source glyph identifier, Unicode text, advance, and optional horizontal or vertical offset

Sequential CIDs isolate repeated glyph instances so the same glyph identifier can carry different Unicode cluster mappings

Embedding and subsetting

pcfemFull embeds the complete selected font, pcfemSubsetPreferred attempts a glyph-list subset and falls back to the complete font, and pcfemSubsetRequired rejects the operation if a safe subset cannot be produced

Subsetting always retains glyph zero, rejects output that would grow the font, and verifies that every requested original GID still exists before the data reaches PDFium

Native Free Pascal on Linux and macOS uses the optional HarfBuzz subset library with retained glyph IDs. An unavailable library or unsafe subset is reported through SubsetErrorCode; the selected embedding mode decides whether full-font fallback is allowed

TTCIndex selects a member of a TrueType Collection and must remain zero for a standalone font

Variable-font qualification

Focused Windows probes verify the default instances of the local Segoe UI Variable and Bahnschrift TrueType programs by supplying their original bytes, explicit glyph IDs, Unicode mappings and default-instance advances with pcfemFull, then using saSubsetNewFonts at save time

The full and subset PDFs retain exact text and rendered pixels after reload; this caller-supplied path bypasses system font resolution. Since v3.205.1, AddText can also resolve exact installed variable families through optional DirectWrite instead of the earlier GDI substitution

This evidence does not qualify arbitrary variation-axis selection, other variable fonts, bitmap fonts or the Windows legacy embedding-time subsetter; callers must supply glyph mappings and advances for the same instance they embed

For explicit axis coordinates since v3.206.0, first use InstantiatePdfVariableFont to produce a static TrueType instance, then supply that instance's glyph IDs and advances to this method; CID embedding itself does not select axis coordinates

Unicode and verification

A generated ToUnicode CMap maps every sequential CID to the supplied UnicodeText, including multi-code-unit ligature and supplementary-plane mappings

An empty mapping becomes U+200B so every CID remains extractable and observable

When VerifyExtraction is enabled, the method reopens the page text model, reads only the inserted objects, compares the result with ExpectedText, and rolls back all inserted objects on mismatch

Options and report

TPdfCidFontOptions.Default picks pcfemSubsetPreferred as the EmbeddingMode, verifies extraction, limits font data to 64 MiB, glyph instances to 65,534, and MaxUnicodeCharacters to 1,048,576 mapped Unicode code units

TPdfCidFontReport records total glyph count and UniqueGlyphCount, OriginalFontBytes and EmbeddedFontBytes, SubsetAttempted, SubsetApplied, UsedFullFontFallback, SubsetErrorCode, FontEmbedded, expected and extracted text, and ExtractionMatches

Atomicity and performance

Glyph positions are generated in linear time and glyphs sharing one baseline are emitted as one native text object

Differing vertical offsets use isolated text objects while preserving logical object order

Validation and subsetting finish before insertion, and any later native failure removes every object added by the call before page content is regenerated

See Also

BuildToUnicodeCMap, AddShapedText, AddText, GetStructuredText