Font Files
Font-file support is organized as a source-defined parsing stack: a TrueType Collection identifies member offsets, each member is represented by a File, the file produces a header and table directory, and table entries are materialized through typed binary-table classes.
Parsing relationship
flowchart TD
c["TrueType Collection::parse"] --> o["collectionOffsets"]
o -->|member offset| g["TrueType Collection::getFont($fontId)"]
g -->|creates member| f["TrueType File"]
f --> h["File::parseHeader"]
h --> hd["TrueType Header::parse"]
f --> p["File::parse"]
p --> d["File::parseTableEntries"]
d --> dir["directory[tag]"]
p --> r["File::readTable($tag)"]
dir -->|directory entry| r
r --> t["FontLib Table::parse"]
t --> data["data[tag]"]
Format-specific structures
[
{
"title": "TrueType Collection",
"body": "Source: `pdf/lib/php-font-lib/src/FontLib/TrueType/Collection.php`.\n\n**Collection::parse** reads a four-byte collection tag, a fixed-point **version**, and a 32-bit **numFonts** value. Its loop runs from zero while the iterator index is less than **numFonts**, appending one 32-bit value to `collectionOffsets` per iteration.\n\n**Collection::getFont($fontId)** parses the collection first. It throws `OutOfBoundsException` when `collectionOffsets[$fontId]` is absent, returns the cached member when present, and otherwise creates a **File**, assigns the collection stream to the new file's `f` property, sets its table offset from `collectionOffsets[$fontId]`, and caches the member."
},
{
"title": "TrueType header and directory entries",
"body": "Sources: `pdf/lib/php-font-lib/src/FontLib/TrueType/Header.php`, `pdf/lib/php-font-lib/src/FontLib/TrueType/TableDirectoryEntry.php`.\n\n**TrueType Header** defines **format** as `uint32`, followed by **numTables**, **searchRange**, **entrySelector**, and **rangeShift** as `uint16` fields. Its **parse** method calls the parent parser and derives **formatText** from the parsed format value.\n\n**TrueType TableDirectoryEntry::parse** calls its parent parser, then reads **checksum**, **offset**, and **length** as 32-bit values. It increases `entryLength` by 12."
},
{
"title": "OpenType directory entries",
"body": "Source: `pdf/lib/php-font-lib/src/FontLib/OpenType/TableDirectoryEntry.php`.\n\n**OpenType TableDirectoryEntry** extends the TrueType table-directory entry implementation and declares no overriding fields or methods. The TrueType entry parsing behavior therefore supplies the implementation represented by this class."
},
{
"title": "WOFF header and directory entries",
"body": "Sources: `pdf/lib/php-font-lib/src/FontLib/WOFF/Header.php`, `pdf/lib/php-font-lib/src/FontLib/WOFF/TableDirectoryEntry.php`.\n\n**WOFF Header** extends the TrueType header and defines **format**, **flavor**, and **length** as `uint32`; **numTables** and an additional unnamed `uint16`; **totalSfntSize** as `uint32`; **majorVersion** and **minorVersion** as `uint16`; and **metaOffset**, **metaLength**, **metaOrigLength**, **privOffset**, and **privLength** as `uint32` fields.\n\n**WOFF TableDirectoryEntry::parse** calls its parent parser, then reads **offset**, **length**, **origLength**, and **checksum** as 32-bit values."
}
]
Materialize and access binary tables
In pdf/lib/php-font-lib/src/FontLib/TrueType/File.php:
- parseHeader returns when a header already exists. Otherwise, it seeks to
tableOffset, creates a Header, and calls Header::parse. - parseTableEntries calls parseHeader before inspecting the directory. It returns without rebuilding entries when the directory is nonempty, and returns without creating entries when the parsed numTables value is empty. Otherwise, it derives the font type, constructs the corresponding type-specific
TableDirectoryEntryclass name, parses one entry per numTables, and stores each entry under its tag. - parse initializes the file's data array, iterates over the directory, and calls readTable($tag) for each tag whose data is empty.
- readTable($tag) parses table entries first. When
self::$rawis falsey, it canonicalizes the tag by lowercasing it and removing non-alphanumeric characters, then selects the correspondingFontLib\\Table\\Type\\$name_canonclass. It returns when the directory entry or typed class is unavailable. Whenself::$rawis truthy, it selects FontLib\Table\Table instead. After selection, it constructs the table with the directory entry, calls Table::parse, and stores the table object indata[$tag].
In pdf/lib/php-font-lib/src/FontLib/Table/Table.php:
- Table::parse starts the directory-entry read, invokes the typed _parse method, ends the read, and does not select _parseRaw through the source's
false && empty($this->def)branch. - Table::_parse assigns
datafrom the associated font'sunpackoperation using the table definition array. The generic raw-byte parser exists as _parseRaw, but its enclosing constant-false branch is not selected as written. - File::getData($name, $key = null) parses table entries and lazily calls readTable($name) when the named data is empty. It returns
nullwhen the table remains absent; otherwise, it returns the whole table data when$keyis falsey; otherwise, it returns the selected keyed value.
[!WARNING] The inspected classes prove declarations and source-defined call/data edges only; no execution record proves that a bundled font was processed at runtime.
pdf/lib/fonts/Courier.afm,pdf/lib/fonts/DejaVuSans-Bold.ufm, andpublic/pdf/lib/php-font-lib/src/FontLib/TrueType/Collection.phpshould not be treated as runtime evidence. The WOFF sources establish header and directory-record fields, but not a complete WOFF decompression, transfer, or runtime-processing pipeline.
Updated