From d78fae01812193aa80237fc2422345391da7337d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 22 Mar 2016 13:16:08 +0100 Subject: [PATCH] Ensure that TrueType font tables have `uint32` checksums According to "The table directory" under https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#Directory, TrueType font tables should have `uint32` checksums. This is something that I noticed, and was initially confused about, while debugging a TrueType issue. As far as I can tell, the current (`int32`) checksums we use doesn't cause any issues in practice. However, I do think that this should be addressed to agree with the specification, and to reduce possible confusion when reading the font code. --- src/core/fonts.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/fonts.js b/src/core/fonts.js index eb122c7cd..4e2d88cd2 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -403,9 +403,8 @@ var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() { // checksum var checksum = 0; for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) { - var quad = (file[j] << 24) + (file[j + 1] << 16) + - (file[j + 2] << 8) + file[j + 3]; - checksum = (checksum + quad) | 0; + var quad = readUint32(file, j); + checksum = (checksum + quad) >>> 0; } writeInt32(file, offset + 4, checksum); @@ -1246,7 +1245,7 @@ var Font = (function FontClosure() { function readTableEntry(file) { var tag = bytesToString(file.getBytes(4)); - var checksum = file.getInt32(); + var checksum = file.getInt32() >>> 0; var offset = file.getInt32() >>> 0; var length = file.getInt32() >>> 0;