@@ -75,12 +75,49 @@ function write($file, $encoding = null) {
75
75
76
76
if (isset ($ hhea ["ascent " ])) {
77
77
$ this ->addPair ("FontHeightOffset " , $ font ->normalizeFUnit ($ hhea ["lineGap " ]));
78
- $ this ->addPair ("Ascender " , $ font ->normalizeFUnit ($ hhea ["ascent " ]));
79
- $ this ->addPair ("Descender " , $ font ->normalizeFUnit ($ hhea ["descent " ]));
80
78
}
81
79
else {
82
80
$ this ->addPair ("FontHeightOffset " , $ font ->normalizeFUnit ($ os2 ["typoLineGap " ]));
81
+ }
82
+
83
+ $ glyf = $ font ->getData ("glyf " );
84
+ $ glyphIndexArray = $ font ->getUnicodeCharMap ();
85
+
86
+ // capHeight is based on capital H
87
+ if (\array_key_exists (72 , $ glyphIndexArray )) {
88
+ $ upperH = $ glyf [$ glyphIndexArray [72 ]];
89
+ $ upperH ->parseData ();
90
+ $ this ->addPair ("CapHeight " , $ font ->normalizeFUnit ($ upperH ->yMax ));
91
+ }
92
+
93
+ // xHeight is based on lowercase x
94
+ if (\array_key_exists (120 , $ glyphIndexArray )) {
95
+ $ lowerX = $ glyf [$ glyphIndexArray [120 ]];
96
+ $ lowerX ->parseData ();
97
+ $ this ->addPair ("XHeight " , $ font ->normalizeFUnit ($ lowerX ->yMax ));
98
+ }
99
+
100
+ // ascender is based on lowercase d
101
+ if (\array_key_exists (100 , $ glyphIndexArray )) {
102
+ $ lowerD = $ glyf [$ glyphIndexArray [100 ]];
103
+ $ lowerD ->parseData ();
104
+ $ this ->addPair ("Ascender " , $ font ->normalizeFUnit ($ lowerD ->yMax ));
105
+ } elseif (isset ($ hhea ["ascent " ])) {
106
+ $ this ->addPair ("Ascender " , $ font ->normalizeFUnit ($ hhea ["ascent " ]));
107
+ }
108
+ else {
83
109
$ this ->addPair ("Ascender " , $ font ->normalizeFUnit ($ os2 ["typoAscender " ]));
110
+ }
111
+
112
+ // descender is based on lowercase p
113
+ if (\array_key_exists (112 , $ glyphIndexArray )) {
114
+ $ lowerP = $ glyf [$ glyphIndexArray [112 ]];
115
+ $ lowerP ->parseData ();
116
+ $ this ->addPair ("Descender " , $ font ->normalizeFUnit ($ lowerP ->yMin ));
117
+ } elseif (isset ($ hhea ["ascent " ])) {
118
+ $ this ->addPair ("Descender " , $ font ->normalizeFUnit ($ hhea ["descent " ]));
119
+ }
120
+ else {
84
121
$ this ->addPair ("Descender " , -abs ($ font ->normalizeFUnit ($ os2 ["typoDescender " ])));
85
122
}
86
123
@@ -92,8 +129,6 @@ function write($file, $encoding = null) {
92
129
$ font ->normalizeFUnit ($ head ["yMax " ]),
93
130
));
94
131
95
- $ glyphIndexArray = $ font ->getUnicodeCharMap ();
96
-
97
132
if ($ glyphIndexArray ) {
98
133
$ hmtx = $ font ->getData ("hmtx " );
99
134
$ names = $ font ->getData ("post " , "names " );
0 commit comments