Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 652ea1f

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 e6336d1 commit 652ea1f

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

‎src/FontLib/Table/DirectoryEntry.php‎

Lines changed: 2 additions & 14 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /