Skip to content
Merged
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
43 changes: 39 additions & 4 deletions src/FontLib/AdobeFontMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,49 @@ function write($file, $encoding = null) {

if (isset($hhea["ascent"])) {
$this->addPair("FontHeightOffset", $font->normalizeFUnit($hhea["lineGap"]));
$this->addPair("Ascender", $font->normalizeFUnit($hhea["ascent"]));
$this->addPair("Descender", $font->normalizeFUnit($hhea["descent"]));
}
else {
$this->addPair("FontHeightOffset", $font->normalizeFUnit($os2["typoLineGap"]));
}

$glyf = $font->getData("glyf");
$glyphIndexArray = $font->getUnicodeCharMap();

// capHeight is based on capital H
if (\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)) {
$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)) {
$lowerD = $glyf[$glyphIndexArray[100]];
$lowerD->parseData();
$this->addPair("Ascender", $font->normalizeFUnit($lowerD->yMax));
} elseif (isset($hhea["ascent"])) {
$this->addPair("Ascender", $font->normalizeFUnit($hhea["ascent"]));
}
else {
$this->addPair("Ascender", $font->normalizeFUnit($os2["typoAscender"]));
}

// descender is based on lowercase p
if (\array_key_exists(112, $glyphIndexArray)) {
$lowerP = $glyf[$glyphIndexArray[112]];
$lowerP->parseData();
$this->addPair("Descender", $font->normalizeFUnit($lowerP->yMin));
} elseif (isset($hhea["ascent"])) {
$this->addPair("Descender", $font->normalizeFUnit($hhea["descent"]));
}
else {
$this->addPair("Descender", -abs($font->normalizeFUnit($os2["typoDescender"])));
}

Expand All @@ -92,8 +129,6 @@ function write($file, $encoding = null) {
$font->normalizeFUnit($head["yMax"]),
));

$glyphIndexArray = $font->getUnicodeCharMap();

if ($glyphIndexArray) {
$hmtx = $font->getData("hmtx");
$names = $font->getData("post", "names");
Expand Down