Skip to content

Commit abe286c

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 abe286c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/FontLib/Table/DirectoryEntry.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ 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+
if (($mod = $table_length % 4) != 0) {
87+
$pad = 4 - $mod;
88+
$font->write(str_pad("", $pad, "\0"), $pad);
89+
}
90+
8491
$font->seek($table_offset);
8592
$table_data = $font->read($table_length);
8693

@@ -93,7 +100,7 @@ function encode($entry_offset) {
93100

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

96-
$font->seek($table_offset + $table_length);
103+
$font->seek($table_offset + $table_length + $pad);
97104
}
98105

99106
/**

0 commit comments

Comments
 (0)