Skip to content

Commit

Permalink
Fix table sizes to a multiple 4 bytes
Browse files Browse the repository at this point in the history
Per the spec:

> The length of any table is a multiple of four bytes, or that tables are padded with zero to four byte-aligned offsets. Actual table lengths recorded in the TableDirectory should not include padding.

fixes #119
  • Loading branch information
bsweeney committed Jan 6, 2024
1 parent 652ea1f commit 65d52a0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/FontLib/Table/DirectoryEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ function encode($entry_offset) {
$this->offset = $table_offset;
$table_length = $data->encode();

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

$font->seek($table_offset);
$table_data = $font->read($table_length);

Expand All @@ -93,7 +101,7 @@ function encode($entry_offset) {

Font::d("Bytes written = $table_length");

$font->seek($table_offset + $table_length);
$font->seek($table_offset + $table_length + $pad);
}

/**
Expand Down

0 comments on commit 65d52a0

Please sign in to comment.