Skip to content

Commit e6336d1

Browse files
committed
Re-calculate font header when generating TTF
The number of tables in the font may change when generating a font file. Because the font header is dependent on the number of tables the values need to be recalculated. ref #123
1 parent 4546f06 commit e6336d1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/FontLib/TrueType/File.php

+5
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,13 @@ function encode($tags = array()) {
239239
}
240240

241241
$num_tables = count($entries);
242+
$exponent = floor(log($num_tables, 2));
243+
$power_of_two = pow(2, $exponent);
242244

243245
$this->header->data["numTables"] = $num_tables;
246+
$this->header->data["searchRange"] = $power_of_two * 16;
247+
$this->header->data["entrySelector"] = log($power_of_two, 2);
248+
$this->header->data["rangeShift"] = $num_tables * 16 - $this->header->data["searchRange"];
244249
$this->header->encode();
245250

246251
$directory_offset = $this->pos();

0 commit comments

Comments
 (0)