Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
MathTableData
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasMathConstants
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasMathGlyphInfo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasMathVariants
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\FontParser;
6
7/**
8 * Parsed `MATH` table from an OpenType math font (Latin Modern Math,
9 * STIX Two Math, Cambria Math, ...). Defined in the OpenType spec
10 * https://learn.microsoft.com/en-us/typography/opentype/spec/math.
11 *
12 * The MATH table holds the per-font constants and glyph metadata
13 * MathML and TeX-style typesetting need to lay out fractions,
14 * scripts, radicals, large operators, and stretchy delimiters with
15 * font-correct proportions instead of guessed em-fractions.
16 *
17 * v1 of this value object captures just the table header and the
18 * three sub-table byte ranges. Each sub-table parses on demand in
19 * a follow-up slice:
20 *
21 *   - `MathConstants`   - ~50 layout constants (script percent,
22 *                         axis height, fraction shape, etc.).
23 *   - `MathGlyphInfo`   - per-glyph italic correction, top-accent
24 *                         attachment, extended-shape membership,
25 *                         glyph-script percent overrides.
26 *   - `MathVariants`    - stretchy delimiter chains + glyph
27 *                         assembly recipes.
28 *
29 * Storing the raw bytes for each sub-table keeps this slice tight:
30 * the OpenTypeParser only locates them; the parsers for each
31 * sub-table live in their own classes that consume these byte
32 * ranges and return strongly-typed values.
33 */
34final readonly class MathTableData
35{
36    /**
37     * @param int    $majorVersion          MATH table major version (1).
38     * @param int    $minorVersion          MATH table minor version (0).
39     * @param string $mathConstantsBytes    Raw bytes of the MathConstants sub-table.
40     *                                      Empty when the offset is zero (sub-table absent).
41     * @param string $mathGlyphInfoBytes    Raw bytes of the MathGlyphInfo sub-table.
42     * @param string $mathVariantsBytes     Raw bytes of the MathVariants sub-table.
43     */
44    public function __construct(
45        public int $majorVersion,
46        public int $minorVersion,
47        public string $mathConstantsBytes,
48        public string $mathGlyphInfoBytes,
49        public string $mathVariantsBytes,
50    ) {}
51
52    public function hasMathConstants(): bool
53    {
54        return $this->mathConstantsBytes !== '';
55    }
56
57    public function hasMathGlyphInfo(): bool
58    {
59        return $this->mathGlyphInfoBytes !== '';
60    }
61
62    public function hasMathVariants(): bool
63    {
64        return $this->mathVariantsBytes !== '';
65    }
66}