Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| FontFaceData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\FontParser; |
| 6 | |
| 7 | /** |
| 8 | * Common shape for a parsed font face — the fields any downstream |
| 9 | * consumer needs to lay out, shape, and embed text. |
| 10 | * |
| 11 | * Subclassed by {@see OpenTypeData} (CFF outlines, sfVersion `OTTO`) |
| 12 | * and {@see TrueTypeData} (glyf/loca outlines, sfVersion `0x00010000`). |
| 13 | * Both carry the same metric and glyph-mapping fields; the format- |
| 14 | * specific parts (CFF table bytes vs raw TTF glyf data) live on the |
| 15 | * subclass. |
| 16 | * |
| 17 | * The base class itself is `abstract readonly` so the field set is |
| 18 | * fixed at construction and the type hierarchy stays narrow: code |
| 19 | * that hits a metric or a glyph lookup uses `FontFaceData`, and code |
| 20 | * that has to embed the bytes into a PDF stream does an `instanceof` |
| 21 | * check on the subclass to pick the CFF or TrueType embed path. |
| 22 | * |
| 23 | * Optional fields on the base — `verticalWidths`, `underlinePosition`, |
| 24 | * `underlineThickness`, `mathTable` — live here so any code that |
| 25 | * reads them via the polymorphic type can do so safely. Subclasses |
| 26 | * that don't carry the source table just leave the field null at |
| 27 | * construction. |
| 28 | */ |
| 29 | abstract readonly class FontFaceData |
| 30 | { |
| 31 | /** |
| 32 | * @param array<int, int> $fontBBox [xMin, yMin, xMax, yMax] in 1000 units/em |
| 33 | * @param array<int, int> $charWidths WinAnsi byte (32-255) → advance (1000 units/em) |
| 34 | * @param array<int, int> $unicodeMap WinAnsi byte → Unicode codepoint |
| 35 | * @param array<int, int> $fullUnicodeToGid Unicode codepoint → GID |
| 36 | * @param array<int, int> $glyphWidths GID → advance (design units, unscaled) |
| 37 | * @param ?array<int, array<int, int>> $kernPairs leftGid → [rightGid → xAdvanceAdjust] |
| 38 | * @param ?array<int, list<array{components: int[], ligature: int}>> $ligatures firstGid → ligature rules |
| 39 | * @param ?array<int, int> $verticalWidths GID → vertical advance (design units) |
| 40 | * @param ?int $underlinePosition `post` table FWord — offset of the underline's top edge from |
| 41 | * the baseline (design units; negative = below baseline). Null if the table is missing. |
| 42 | * @param ?int $underlineThickness `post` table FWord — underline stroke thickness in design units. |
| 43 | * @param ?MathTableData $mathTable Parsed `MATH` table when the font has one. |
| 44 | */ |
| 45 | public function __construct( |
| 46 | public string $postScriptName, |
| 47 | public string $familyName, |
| 48 | public int $ascent, |
| 49 | public int $descent, |
| 50 | public int $capHeight, |
| 51 | public int $xHeight, |
| 52 | public float $italicAngle, |
| 53 | public int $stemV, |
| 54 | public int $flags, |
| 55 | public array $fontBBox, |
| 56 | public array $charWidths, |
| 57 | public array $unicodeMap, |
| 58 | public string $fontBytes, |
| 59 | public bool $embeddingAllowed, |
| 60 | public int $unitsPerEm = 1000, |
| 61 | public array $fullUnicodeToGid = [], |
| 62 | public array $glyphWidths = [], |
| 63 | public ?array $kernPairs = null, |
| 64 | public ?array $ligatures = null, |
| 65 | public ?array $verticalWidths = null, |
| 66 | public ?int $underlinePosition = null, |
| 67 | public ?int $underlineThickness = null, |
| 68 | public ?MathTableData $mathTable = null, |
| 69 | ) {} |
| 70 | } |