Skip to content

Commit 433396c

Browse files
committed
Fix glyph sizes to a multiple of 4 bytes
Before this change when the font loca table was using the short format (glyph size / 2), an odd-numbered glyph byte length would be incorrectly record. To prevent this issue, when writing a font we will padd glyphs to align with a 4-byte boundary. Note: Official guidance needed. The 4-byte boundary is based on table requirements, as well as being a multiple of 2.
1 parent 73d7f50 commit 433396c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/FontLib/Table/Type/glyf.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,16 @@ protected function _encode() {
143143
$length = 0;
144144
foreach ($subset as $gid) {
145145
$loca[] = $length;
146-
$length += $data[$gid]->encode();
146+
147+
$bytes = $data[$gid]->encode();
148+
149+
$pad = 0;
150+
$mod = $bytes % 4;
151+
if ($mod != 0) {
152+
$pad = 4 - $mod;
153+
$font->write(str_pad("", $pad, "\0"), $pad);
154+
}
155+
$length += $bytes + $pad;
147156
}
148157

149158
$loca[] = $length; // dummy loca

0 commit comments

Comments
 (0)