Skip to content

Commit 86cfdad

Browse files
authored
Fix reading left side bearings
Before this change php-font-lib would only populate as many glyph metrics as were present in the hmtx table. However, per the spec, "if numberOfHMetrics is less than the total number of glyphs, then the hMetrics array is followed by an array for the left side bearing values of the remaining glyphs."
1 parent 7136291 commit 86cfdad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/FontLib/Table/Type/hmtx.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ protected function _parse() {
3535
}
3636

3737
if ($numOfLongHorMetrics < $numGlyphs) {
38-
$lastWidth = end($data);
39-
$data = array_pad($data, $numGlyphs, $lastWidth);
38+
$lastWidth = end($data)[0];
39+
$numLeft = $numGlyphs - $numOfLongHorMetrics;
40+
$metrics = $font->readUInt16Many($numLeft);
41+
for($i = 0; $i < $numLeft; $i++) {
42+
$gid = $numOfLongHorMetrics + $i;
43+
$leftSideBearing = isset($metrics[$i]) ? $metrics[$i] : 0;
44+
$data[$gid] = array($lastWidth, $leftSideBearing);
45+
}
4046
}
4147

4248
$this->data = $data;

0 commit comments

Comments
 (0)