Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
MathConstants
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\FontParser;
6
7/**
8 * Parsed MathConstants sub-table from an OpenType MATH table.
9 *
10 * Spec: https://learn.microsoft.com/en-us/typography/opentype/spec/math#mathconstants-table
11 *
12 * Every value is in font design units (FUnit) unless otherwise
13 * noted; the consumer scales by (size / unitsPerEm) to get points.
14 * Percent-scale fields are signed Int16 percentages (so a 0.7
15 * scale-down is stored as 70).
16 *
17 * The painter consumes these constants to replace the hardcoded
18 * em-fractions baked into the tracer-bullet (SCRIPT_FONT_SCALE,
19 * SUP_RAISE_EM, fraction-bar thickness, etc.) with font-correct
20 * values that match the rendered glyph metrics.
21 *
22 * v1 of this parser handles the FWord half of each MathValueRecord
23 * field. The Device-table half (per-PPEM corrections for hinting)
24 * is read but discarded - hinting at math-typesetting sizes is
25 * negligible and adds parser surface area for no observable gain.
26 */
27final readonly class MathConstants
28{
29    public function __construct(
30        // ----- script size scaling -----------------------------------
31        /** Percent scale-down for script-level glyphs (e.g. 70 => 70%). */
32        public int $scriptPercentScaleDown,
33        /** Percent scale-down for script-script-level glyphs (e.g. 55). */
34        public int $scriptScriptPercentScaleDown,
35        /** Minimum height (in design units) at which a delimiter is
36         *  drawn as the next stretched variant. Used by stretchy
37         *  brackets and radicals. */
38        public int $delimitedSubFormulaMinHeight,
39        /** Minimum height (design units) at which an operator switches
40         *  to its display (large) form. */
41        public int $displayOperatorMinHeight,
42
43        // ----- vertical metrics --------------------------------------
44        /** Recommended gap between top of a math row and the top of
45         *  its tallest glyph. */
46        public int $mathLeading,
47        /** Vertical position of the mathematical axis (the centerline
48         *  for fraction bars, sum operators, etc.) above baseline. */
49        public int $axisHeight,
50        /** Vertical alignment for an accent's bottom relative to the
51         *  base glyph's top. */
52        public int $accentBaseHeight,
53        /** Vertical alignment for a flattened accent's bottom. */
54        public int $flattenedAccentBaseHeight,
55
56        // ----- subscripts --------------------------------------------
57        public int $subscriptShiftDown,
58        public int $subscriptTopMax,
59        public int $subscriptBaselineDropMin,
60
61        // ----- superscripts ------------------------------------------
62        public int $superscriptShiftUp,
63        public int $superscriptShiftUpCramped,
64        public int $superscriptBottomMin,
65        public int $superscriptBaselineDropMax,
66
67        // ----- sub+sup gap -------------------------------------------
68        public int $subSuperscriptGapMin,
69        public int $superscriptBottomMaxWithSubscript,
70
71        // ----- space around super/sub --------------------------------
72        public int $spaceAfterScript,
73
74        // ----- upper / lower limit attachments (sum, integral) -------
75        public int $upperLimitGapMin,
76        public int $upperLimitBaselineRiseMin,
77        public int $lowerLimitGapMin,
78        public int $lowerLimitBaselineDropMin,
79
80        // ----- stack layout (binomial-like) --------------------------
81        public int $stackTopShiftUp,
82        public int $stackTopDisplayStyleShiftUp,
83        public int $stackBottomShiftDown,
84        public int $stackBottomDisplayStyleShiftDown,
85        public int $stackGapMin,
86        public int $stackDisplayStyleGapMin,
87
88        // ----- stretch stack (under-over with stretchy op) -----------
89        public int $stretchStackTopShiftUp,
90        public int $stretchStackBottomShiftDown,
91        public int $stretchStackGapAboveMin,
92        public int $stretchStackGapBelowMin,
93
94        // ----- fractions ---------------------------------------------
95        public int $fractionNumeratorShiftUp,
96        public int $fractionNumeratorDisplayStyleShiftUp,
97        public int $fractionDenominatorShiftDown,
98        public int $fractionDenominatorDisplayStyleShiftDown,
99        public int $fractionNumeratorGapMin,
100        public int $fractionNumDisplayStyleGapMin,
101        /** Thickness of the horizontal bar in fractions. */
102        public int $fractionRuleThickness,
103        public int $fractionDenominatorGapMin,
104        public int $fractionDenomDisplayStyleGapMin,
105
106        // ----- skewed fractions --------------------------------------
107        public int $skewedFractionHorizontalGap,
108        public int $skewedFractionVerticalGap,
109
110        // ----- overbars / underbars ----------------------------------
111        public int $overbarVerticalGap,
112        public int $overbarRuleThickness,
113        public int $overbarExtraAscender,
114        public int $underbarVerticalGap,
115        public int $underbarRuleThickness,
116        public int $underbarExtraDescender,
117
118        // ----- radicals ----------------------------------------------
119        public int $radicalVerticalGap,
120        public int $radicalDisplayStyleVerticalGap,
121        public int $radicalRuleThickness,
122        public int $radicalExtraAscender,
123        public int $radicalKernBeforeDegree,
124        public int $radicalKernAfterDegree,
125        /** Percent of radical sign height the degree base rises (e.g. 60). */
126        public int $radicalDegreeBottomRaisePercent,
127    ) {}
128}