Skip to content

Commit

Permalink
Fix glyph sizes to a multiple of 4 bytes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bsweeney committed Dec 12, 2023
1 parent a172789 commit c5f7810
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/FontLib/Table/Type/glyf.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,16 @@ protected function _encode() {
$length = 0;
foreach ($subset as $gid) {
$loca[] = $length;
$length += $data[$gid]->encode();

$bytes = $data[$gid]->encode();

$pad = 0;
$mod = $bytes % 4;
if ($mod != 0) {
$pad = 4 - $mod;
$font->write(str_pad("", $pad, "\0"), $pad);
}
$length += $bytes + $pad;
}

$loca[] = $length; // dummy loca
Expand Down

0 comments on commit c5f7810

Please sign in to comment.