Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/FontLib/AdobeFontMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions src/FontLib/TrueType/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down