diff --git a/src/FontLib/AdobeFontMetrics.php b/src/FontLib/AdobeFontMetrics.php index e902e3e..613117d 100644 --- a/src/FontLib/AdobeFontMetrics.php +++ b/src/FontLib/AdobeFontMetrics.php @@ -82,23 +82,24 @@ function write($file, $encoding = null) { $glyf = $font->getData("glyf"); $glyphIndexArray = $font->getUnicodeCharMap(); + $hasGlyphs = $glyf instanceof glyf && is_array($glyphIndexArray); // capHeight is based on capital H - if (\array_key_exists(72, $glyphIndexArray)) { + if ($hasGlyphs && \array_key_exists(72, $glyphIndexArray)) { $upperH = $glyf[$glyphIndexArray[72]]; $upperH->parseData(); $this->addPair("CapHeight", $font->normalizeFUnit($upperH->yMax)); } // xHeight is based on lowercase x - if (\array_key_exists(120, $glyphIndexArray)) { + if ($hasGlyphs && \array_key_exists(120, $glyphIndexArray)) { $lowerX = $glyf[$glyphIndexArray[120]]; $lowerX->parseData(); $this->addPair("XHeight", $font->normalizeFUnit($lowerX->yMax)); } // ascender is based on lowercase d - if (\array_key_exists(100, $glyphIndexArray)) { + if ($hasGlyphs && \array_key_exists(100, $glyphIndexArray)) { $lowerD = $glyf[$glyphIndexArray[100]]; $lowerD->parseData(); $this->addPair("Ascender", $font->normalizeFUnit($lowerD->yMax)); @@ -110,11 +111,11 @@ function write($file, $encoding = null) { } // descender is based on lowercase p - if (\array_key_exists(112, $glyphIndexArray)) { + if ($hasGlyphs && \array_key_exists(112, $glyphIndexArray)) { $lowerP = $glyf[$glyphIndexArray[112]]; $lowerP->parseData(); $this->addPair("Descender", $font->normalizeFUnit($lowerP->yMin)); - } elseif (isset($hhea["ascent"])) { + } elseif (isset($hhea["descent"])) { $this->addPair("Descender", $font->normalizeFUnit($hhea["descent"])); } else { diff --git a/src/FontLib/TrueType/File.php b/src/FontLib/TrueType/File.php index f32d067..b1c7cd8 100644 --- a/src/FontLib/TrueType/File.php +++ b/src/FontLib/TrueType/File.php @@ -310,11 +310,11 @@ function setSubset($subset) { /** @var glyf $glyf */ $glyf = $this->getTableObject("glyf"); - $gids = $glyf->getGlyphIDs($gids); - - sort($gids); - - $this->glyph_subset = $gids; + if ($glyf) { + $gids = $glyf->getGlyphIDs($gids); + sort($gids); + $this->glyph_subset = $gids; + } $this->glyph_all = array_values($glyphIndexArray); // FIXME } @@ -443,7 +443,10 @@ protected function readTable($tag) { * @return Table */ public function getTableObject($name) { - return $this->data[$name]; + if (\array_key_exists($name, $this->data)) { + return $this->data[$name]; + } + return null; } public function setTableObject($name, Table $data) {