Skip to content

Commit c61a738

Browse files
committed
Fix table sizes to a multiple 4 bytes
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
1 parent 26fb88b commit c61a738

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/FontLib/Table/DirectoryEntry.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ function encode($entry_offset) {
8181
$this->offset = $table_offset;
8282
$table_length = $data->encode();
8383

84+
$font->seek($table_offset + $table_length);
85+
$pad = 0;
86+
$mod = $table_length % 4;
87+
if ($mod != 0) {
88+
$pad = 4 - $mod;
89+
$font->write(str_pad("", $pad, "\0"), $pad);
90+
}
91+
8492
$font->seek($table_offset);
8593
$table_data = $font->read($table_length);
8694

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

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

96-
$font->seek($table_offset + $table_length);
104+
$font->seek($table_offset + $table_length + $pad);
97105
}
98106

99107
/**

0 commit comments

Comments
 (0)