Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
OpenTypeData
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\FontParser;
6
7/**
8 * Parsed OpenType CFF font data — metrics, glyph widths, and raw CFF bytes.
9 *
10 * Mirrors TrueTypeData but adds the CFF table bytes and stores the
11 * full raw font file for potential whole-file embedding. Both extend
12 * {@see FontFaceData} so consumers that don't care about the outline
13 * format (Shaper, FontResolver, layout) can take the base type, and
14 * the PdfWriter dispatches CFF vs glyf embedding via `instanceof`.
15 */
16readonly class OpenTypeData extends FontFaceData
17{
18    /**
19     * @param string $postScriptName  PostScript name (name table ID 6)
20     * @param string $familyName      Family name (name table ID 1)
21     * @param int    $ascent          Typographic ascender (1000 units/em)
22     * @param int    $descent         Typographic descender (negative, 1000 units/em)
23     * @param int    $capHeight       Cap height (1000 units/em)
24     * @param int    $xHeight         x-height (1000 units/em)
25     * @param float  $italicAngle     Italic angle in degrees
26     * @param int    $stemV           Estimated vertical stem width
27     * @param int    $flags           PDF font flags bitmask
28     * @param array<int, int>  $fontBBox        [xMin, yMin, xMax, yMax] (1000 units/em)
29     * @param array<int, int>  $charWidths      WinAnsi byte (32-255) → width (1000 units/em)
30     * @param array<int, int>  $unicodeMap      WinAnsi byte (32-255) → Unicode codepoint
31     * @param string $cffBytes        Raw CFF table bytes (for /FontFile3 /Subtype /CIDFontType0C)
32     * @param string $fontBytes       Raw OTF file bytes (for /FontFile3 /Subtype /OpenType)
33     * @param bool   $embeddingAllowed fsType restriction check
34     * @param int    $unitsPerEm      Font design units per em
35     * @param array<int, int>  $fullUnicodeToGid All Unicode → GID mappings
36     * @param array<int, int>  $glyphWidths     GID → advance width (design units)
37     * @param ?array<int, array<int, int>> $kernPairs leftGid => [rightGid => xAdvanceAdjust] (design units)
38     * @param ?array<int, list<array{components: int[], ligature: int}>> $ligatures firstGid => ligature rules
39     * @param ?array<int, int> $verticalWidths GID => vertical advance width (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 (Latin Modern Math,
44     *        STIX Two Math, Cambria Math, ...). Null for non-math fonts.
45     */
46    public function __construct(
47        string $postScriptName,
48        string $familyName,
49        int $ascent,
50        int $descent,
51        int $capHeight,
52        int $xHeight,
53        float $italicAngle,
54        int $stemV,
55        int $flags,
56        array $fontBBox,
57        array $charWidths,
58        array $unicodeMap,
59        public string $cffBytes,
60        string $fontBytes,
61        bool $embeddingAllowed,
62        int $unitsPerEm = 1000,
63        array $fullUnicodeToGid = [],
64        array $glyphWidths = [],
65        ?array $kernPairs = null,
66        ?array $ligatures = null,
67        ?array $verticalWidths = null,
68        ?int $underlinePosition = null,
69        ?int $underlineThickness = null,
70        ?MathTableData $mathTable = null,
71    ) {
72        parent::__construct(
73            $postScriptName,
74            $familyName,
75            $ascent,
76            $descent,
77            $capHeight,
78            $xHeight,
79            $italicAngle,
80            $stemV,
81            $flags,
82            $fontBBox,
83            $charWidths,
84            $unicodeMap,
85            $fontBytes,
86            $embeddingAllowed,
87            $unitsPerEm,
88            $fullUnicodeToGid,
89            $glyphWidths,
90            $kernPairs,
91            $ligatures,
92            $verticalWidths,
93            $underlinePosition,
94            $underlineThickness,
95            $mathTable,
96        );
97    }
98}