phpdftk API Documentation

Font
in package
implements RegisteredFont

FinalYes

Opaque font handle returned by PdfWriter::addFont().

Encapsulates the PDF resource name (F1, F2, ...), parsed font data, and the text encoder (when the font uses a single-byte encoding such as WinAnsi). Pass to ContentStream::setFont() to select the font for a subsequent text run; passing the handle (rather than just the resource name) is what makes showText() accept UTF-8 directly.

Table of Contents

Interfaces

RegisteredFont
A font that has been registered with a writer and assigned a resource name. ContentStream::setFont() accepts this so callers can pass UTF-8 to showText() and have the encoder do the byte-level translation for them.

Methods

__construct()  : mixed
getFamily()  : string
getOldToNewGidMap()  : array<int, int>
Pre-subset GID → post-subset GID map. Empty for non-subsetted fonts.
getTextEncoder()  : TextEncoder|null
The text encoder that converts UTF-8 input into the byte sequence the underlying PDF font expects. Null for composite/CID fonts, which use the GID-hex path (ContentStream::showTextHex / showUnicodeText).
getUnicodeToGidMap()  : array<int, int>
Unicode codepoint → post-subset GID map for composite (Type 0) fonts.

Methods

__construct()

public __construct(string $resourceName, string $family[, TrueTypeData|OpenTypeData|null $parsedData = null ][, TextEncoder|null $encoder = null ][, array<int, int> $unicodeToGid = [] ][, array<int, int> $oldToNewGid = [] ]) : mixed
Parameters
$resourceName : string
$family : string
$parsedData : TrueTypeData|OpenTypeData|null = null
$encoder : TextEncoder|null = null
$unicodeToGid : array<int, int> = []

Unicode codepoint → post-subset GID. Only populated for composite (Type 0) fonts; empty for everything else. Use this when emitting glyph IDs into a content stream rather than the unsubset map on TrueTypeData, which points at glyphs that no longer exist in the embedded subset.

$oldToNewGid : array<int, int> = []

Pre-subset GID → post-subset GID. Used by external shapers (phpdftk/text) that produce GIDs against the full font; translate through this map before emitting into a content stream so the resulting hex string points at the subset's renumbered glyphs.

getFamily()

public getFamily() : string
Return values
string

getOldToNewGidMap()

Pre-subset GID → post-subset GID map. Empty for non-subsetted fonts.

public getOldToNewGidMap() : array<int, int>

External shapers that bind glyph IDs against the full OpenTypeData::fullUnicodeToGid translate through this when emitting.

Return values
array<int, int>

getTextEncoder()

The text encoder that converts UTF-8 input into the byte sequence the underlying PDF font expects. Null for composite/CID fonts, which use the GID-hex path (ContentStream::showTextHex / showUnicodeText).

public getTextEncoder() : TextEncoder|null
Return values
TextEncoder|null

getUnicodeToGidMap()

Unicode codepoint → post-subset GID map for composite (Type 0) fonts.

public getUnicodeToGidMap() : array<int, int>

Use this when building a hex glyph string for showTextHex; the map on the parsed font data points at pre-subset GIDs that no longer match the embedded subset. Returns an empty array for standard or simple TrueType fonts that don't go through subsetting.

Return values
array<int, int>

        
On this page

Search results