Skip to content

Commit

Permalink
Re-calculate font header when generating TTF
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bsweeney committed Dec 30, 2023
1 parent 203a660 commit db0bb44
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FontLib/TrueType/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,13 @@ function encode($tags = array()) {
}

$num_tables = count($entries);
$exponent = floor(log($num_tables, 2));
$power_of_two = pow(2, $exponent);

$this->header->data["numTables"] = $num_tables;
$this->header->data["searchRange"] = $power_of_two * 16;
$this->header->data["entrySelector"] = log($power_of_two, 2);
$this->header->data["rangeShift"] = $num_tables * 16 - $this->header->data["searchRange"];
$this->header->encode();

$directory_offset = $this->pos();
Expand Down

0 comments on commit db0bb44

Please sign in to comment.