offsets.virtualOffset++;
// checksum
- var checksum = 0;
- for (var i = 0; i < length; i += 4)
- checksum += int16([data[i], data[i + 1], data[i + 2], data[i + 3]]);
+ var checksum = 0, n = data.length;
+ for (var i = 0; i < n; i+=4)
+ checksum = (checksum + int32([data[i], data[i+1], data[i+2], data[i+3]])) | 0;
- var tableEntry = tag + string32(checksum) + string32(offset) + string32(length);
+ var tableEntry = (tag + string32(checksum) +
+ string32(offset) + string32(length));
tableEntry = stringToArray(tableEntry);
file.set(tableEntry, offsets.currentOffset);
var ulUnicodeRange3 = 0;
var ulUnicodeRange4 = 0;
- var charset = properties.charset;
+ var charset = properties.charset;
if (charset && charset.length) {
- var firstCharIndex = null;
- var lastCharIndex = 0;
+ var firstCharIndex = null;
+ var lastCharIndex = 0;
- for (var i = 1; i < charset.length; i++) {
+ for (var i = 0; i < charset.length; i++) {
- var code = GlyphsUnicode[charset[i]];
- if (firstCharIndex > code || !firstCharIndex)
- firstCharIndex = code;
- if (lastCharIndex < code)
- lastCharIndex = code;
+ var code = GlyphsUnicode[charset[i]];
+ if (firstCharIndex > code || !firstCharIndex)
+ firstCharIndex = code;
+ if (lastCharIndex < code)
+ lastCharIndex = code;
- var position = getUnicodeRangeFor(code);
+ var position = getUnicodeRangeFor(code);
if (position < 32) {
ulUnicodeRange1 |= 1 << position;
} else if (position < 64) {
relativeOffset += objects[i].length;
}
- for (var i =0; i < count; i++) {
+ for (var i = 0; i < count; i++) {
for (var j = 0; j < objects[i].length; j++)
- data += isByte ? String.fromCharCode(objects[i][j]) : objects[i][j];
+ data += isByte ? String.fromCharCode(objects[i][j] & 0xFF) : objects[i][j];
}
return data;
},
encodeNumber: function cff_encodeNumber(value) {
if (value >= -32768 && value <= 32767) {
- return "\x1c" +
+ return '\x1c' +
- String.fromCharCode(value >> 8) +
+ String.fromCharCode((value >> 8) & 0xFF) +
String.fromCharCode(value & 0xFF);
- } else if (value >= (-2147483647 - 1) && value <= 2147483647) {
+ } else if (value >= (-2147483647-1) && value <= 2147483647) {
- return "\xff" +
+ return '\xff' +
- String.fromCharCode(value >> 24) +
- String.fromCharCode(value >> 16) +
- String.fromCharCode(value >> 8) +
+ String.fromCharCode((value >>> 24) & 0xFF) +
+ String.fromCharCode((value >> 16) & 0xFF) +
+ String.fromCharCode((value >> 8) & 0xFF) +
String.fromCharCode(value & 0xFF);
}
- error("Value: " + value + " is not allowed");
+ error('Value: ' + value + ' is not allowed');
return null;
},