Skip to content

Commit 26fb88b

Browse files
committed
Use simpler, spec-compliat checksum logic
Per the spec: > Table checksums are the unsigned sum of the longs in a table.
1 parent e1a740d commit 26fb88b

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/FontLib/Table/DirectoryEntry.php

+2-14
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,8 @@ static function computeChecksum($data) {
4949
$data = str_pad($data, $len + (4 - $mod), "\0");
5050
}
5151

52-
$len = mb_strlen($data, '8bit');
53-
54-
$hi = 0x0000;
55-
$lo = 0x0000;
56-
57-
for ($i = 0; $i < $len; $i += 4) {
58-
$hi += (ord($data[$i]) << 8) + ord($data[$i + 1]);
59-
$lo += (ord($data[$i + 2]) << 8) + ord($data[$i + 3]);
60-
$hi += $lo >> 16;
61-
$lo = $lo & 0xFFFF;
62-
$hi = $hi & 0xFFFF;
63-
}
64-
65-
return ($hi << 8) + $lo;
52+
$table = unpack("N*", $data);
53+
return array_sum($table);
6654
}
6755

6856
function __construct(File $font) {

0 commit comments

Comments
 (0)