Calculate the checksumAdjustement for the file
This commit is contained in:
parent
1037fdf2ad
commit
9b1d6a5e25
20
fonts.js
20
fonts.js
@ -1024,14 +1024,14 @@ var Font = (function Font() {
|
|||||||
// to write the table entry information about a table and another offset
|
// to write the table entry information about a table and another offset
|
||||||
// representing the offset where to draw the actual data of a particular
|
// representing the offset where to draw the actual data of a particular
|
||||||
// table
|
// table
|
||||||
var kRequiredTablesCount = 9;
|
var tablesCount = 9;
|
||||||
var offsets = {
|
var offsets = {
|
||||||
currentOffset: 0,
|
currentOffset: 0,
|
||||||
virtualOffset: 9 * (4 * 4)
|
virtualOffset: tablesCount * (4 * 4)
|
||||||
};
|
};
|
||||||
|
|
||||||
var otf = new Uint8Array(kMaxFontFileSize);
|
var otf = new Uint8Array(kMaxFontFileSize);
|
||||||
createOpenTypeHeader("\x4F\x54\x54\x4F", otf, offsets, 9);
|
createOpenTypeHeader("\x4F\x54\x54\x4F", otf, offsets, tablesCount);
|
||||||
|
|
||||||
var charstrings = font.charstrings;
|
var charstrings = font.charstrings;
|
||||||
properties.fixedPitch = isFixedPitch(charstrings);
|
properties.fixedPitch = isFixedPitch(charstrings);
|
||||||
@ -1115,12 +1115,26 @@ var Font = (function Font() {
|
|||||||
for (var field in fields)
|
for (var field in fields)
|
||||||
createTableEntry(otf, offsets, field, fields[field]);
|
createTableEntry(otf, offsets, field, fields[field]);
|
||||||
|
|
||||||
|
var headPosition = 0;
|
||||||
for (var field in fields) {
|
for (var field in fields) {
|
||||||
var table = fields[field];
|
var table = fields[field];
|
||||||
|
if (field == "head")
|
||||||
|
headPosition = offsets.currentOffset;
|
||||||
|
|
||||||
otf.set(table, offsets.currentOffset);
|
otf.set(table, offsets.currentOffset);
|
||||||
offsets.currentOffset += table.length;
|
offsets.currentOffset += table.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now calculate the checksumAdjustement for all the file and put it into
|
||||||
|
// head. This will make the head checksum incorrect but per spec that's
|
||||||
|
// the way it works.
|
||||||
|
var checksumAdjustement = 0;
|
||||||
|
for (var i = 0; i < offsets.currentOffset; i+=4)
|
||||||
|
checksumAdjustement += int16([otf[i], otf[i+1], otf[i+2], otf[i+3]]);
|
||||||
|
checksumAdjustement = 0xB1B0AFBA - checksumAdjustement;
|
||||||
|
otf.set(stringToArray(string32(checksumAdjustement)), headPosition + (2 * 4));
|
||||||
|
|
||||||
|
|
||||||
var fontData = [];
|
var fontData = [];
|
||||||
for (var i = 0; i < offsets.currentOffset; i++)
|
for (var i = 0; i < offsets.currentOffset; i++)
|
||||||
fontData.push(otf[i]);
|
fontData.push(otf[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user