@@ -82,23 +82,24 @@ function write($file, $encoding = null) {
8282
8383 $ glyf = $ font ->getData ("glyf " );
8484 $ glyphIndexArray = $ font ->getUnicodeCharMap ();
85+ $ hasGlyphs = $ glyf instanceof glyf && is_array ($ glyphIndexArray );
8586
8687 // capHeight is based on capital H
87- if (\array_key_exists (72 , $ glyphIndexArray )) {
88+ if ($ hasGlyphs && \array_key_exists (72 , $ glyphIndexArray )) {
8889 $ upperH = $ glyf [$ glyphIndexArray [72 ]];
8990 $ upperH ->parseData ();
9091 $ this ->addPair ("CapHeight " , $ font ->normalizeFUnit ($ upperH ->yMax ));
9192 }
9293
9394 // xHeight is based on lowercase x
94- if (\array_key_exists (120 , $ glyphIndexArray )) {
95+ if ($ hasGlyphs && \array_key_exists (120 , $ glyphIndexArray )) {
9596 $ lowerX = $ glyf [$ glyphIndexArray [120 ]];
9697 $ lowerX ->parseData ();
9798 $ this ->addPair ("XHeight " , $ font ->normalizeFUnit ($ lowerX ->yMax ));
9899 }
99100
100101 // ascender is based on lowercase d
101- if (\array_key_exists (100 , $ glyphIndexArray )) {
102+ if ($ hasGlyphs && \array_key_exists (100 , $ glyphIndexArray )) {
102103 $ lowerD = $ glyf [$ glyphIndexArray [100 ]];
103104 $ lowerD ->parseData ();
104105 $ this ->addPair ("Ascender " , $ font ->normalizeFUnit ($ lowerD ->yMax ));
@@ -110,11 +111,11 @@ function write($file, $encoding = null) {
110111 }
111112
112113 // descender is based on lowercase p
113- if (\array_key_exists (112 , $ glyphIndexArray )) {
114+ if ($ hasGlyphs && \array_key_exists (112 , $ glyphIndexArray )) {
114115 $ lowerP = $ glyf [$ glyphIndexArray [112 ]];
115116 $ lowerP ->parseData ();
116117 $ this ->addPair ("Descender " , $ font ->normalizeFUnit ($ lowerP ->yMin ));
117- } elseif (isset ($ hhea ["ascent " ])) {
118+ } elseif (isset ($ hhea ["descent " ])) {
118119 $ this ->addPair ("Descender " , $ font ->normalizeFUnit ($ hhea ["descent " ]));
119120 }
120121 else {
0 commit comments