Issue #2008 - Fix lint errors for src/fonts.js
This commit is contained in:
parent
c281805fde
commit
3793ca5283
78
src/fonts.js
78
src/fonts.js
@ -1,5 +1,6 @@
|
|||||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||||
|
/* globals assert, bytesToString, CIDToUnicodeMaps, error, ExpertCharset, ExpertSubsetCharset, FileReaderSync, globalScope, GlyphsUnicode, info, isArray, isNum, ISOAdobeCharset, isWorker, PDFJS, Stream, stringToBytes, TextDecoder, warn */
|
||||||
/* Copyright 2012 Mozilla Foundation
|
/* Copyright 2012 Mozilla Foundation
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -507,7 +508,7 @@ var FontLoader = {
|
|||||||
|
|
||||||
// Add the font to the DOM only once or skip if the font
|
// Add the font to the DOM only once or skip if the font
|
||||||
// is already loaded.
|
// is already loaded.
|
||||||
if (font.attached || font.loading == false) {
|
if (font.attached || font.loading === false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
font.attached = true;
|
font.attached = true;
|
||||||
@ -2425,7 +2426,7 @@ var Font = (function FontClosure() {
|
|||||||
this.encoding = properties.baseEncoding;
|
this.encoding = properties.baseEncoding;
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
};
|
}
|
||||||
|
|
||||||
var numFonts = 0;
|
var numFonts = 0;
|
||||||
function getUniqueName() {
|
function getUniqueName() {
|
||||||
@ -2438,7 +2439,7 @@ var Font = (function FontClosure() {
|
|||||||
array[i] = str.charCodeAt(i);
|
array[i] = str.charCodeAt(i);
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
};
|
}
|
||||||
|
|
||||||
function arrayToString(arr) {
|
function arrayToString(arr) {
|
||||||
var str = '';
|
var str = '';
|
||||||
@ -2446,16 +2447,16 @@ var Font = (function FontClosure() {
|
|||||||
str += String.fromCharCode(arr[i]);
|
str += String.fromCharCode(arr[i]);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
};
|
}
|
||||||
|
|
||||||
function int16(bytes) {
|
function int16(bytes) {
|
||||||
return (bytes[0] << 8) + (bytes[1] & 0xff);
|
return (bytes[0] << 8) + (bytes[1] & 0xff);
|
||||||
};
|
}
|
||||||
|
|
||||||
function int32(bytes) {
|
function int32(bytes) {
|
||||||
return (bytes[0] << 24) + (bytes[1] << 16) +
|
return (bytes[0] << 24) + (bytes[1] << 16) +
|
||||||
(bytes[2] << 8) + (bytes[3] & 0xff);
|
(bytes[2] << 8) + (bytes[3] & 0xff);
|
||||||
};
|
}
|
||||||
|
|
||||||
function getMaxPower2(number) {
|
function getMaxPower2(number) {
|
||||||
var maxPower = 0;
|
var maxPower = 0;
|
||||||
@ -2469,26 +2470,26 @@ var Font = (function FontClosure() {
|
|||||||
for (var i = 1; i < maxPower; i++)
|
for (var i = 1; i < maxPower; i++)
|
||||||
value *= 2;
|
value *= 2;
|
||||||
return value;
|
return value;
|
||||||
};
|
}
|
||||||
|
|
||||||
function string16(value) {
|
function string16(value) {
|
||||||
return String.fromCharCode((value >> 8) & 0xff) +
|
return String.fromCharCode((value >> 8) & 0xff) +
|
||||||
String.fromCharCode(value & 0xff);
|
String.fromCharCode(value & 0xff);
|
||||||
};
|
}
|
||||||
|
|
||||||
function safeString16(value) {
|
function safeString16(value) {
|
||||||
// clamp value to the 16-bit int range
|
// clamp value to the 16-bit int range
|
||||||
value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
|
value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
|
||||||
return String.fromCharCode((value >> 8) & 0xff) +
|
return String.fromCharCode((value >> 8) & 0xff) +
|
||||||
String.fromCharCode(value & 0xff);
|
String.fromCharCode(value & 0xff);
|
||||||
};
|
}
|
||||||
|
|
||||||
function string32(value) {
|
function string32(value) {
|
||||||
return String.fromCharCode((value >> 24) & 0xff) +
|
return String.fromCharCode((value >> 24) & 0xff) +
|
||||||
String.fromCharCode((value >> 16) & 0xff) +
|
String.fromCharCode((value >> 16) & 0xff) +
|
||||||
String.fromCharCode((value >> 8) & 0xff) +
|
String.fromCharCode((value >> 8) & 0xff) +
|
||||||
String.fromCharCode(value & 0xff);
|
String.fromCharCode(value & 0xff);
|
||||||
};
|
}
|
||||||
|
|
||||||
function createOpenTypeHeader(sfnt, file, numTables) {
|
function createOpenTypeHeader(sfnt, file, numTables) {
|
||||||
// Windows hates the Mac TrueType sfnt version number
|
// Windows hates the Mac TrueType sfnt version number
|
||||||
@ -2514,7 +2515,7 @@ var Font = (function FontClosure() {
|
|||||||
|
|
||||||
file.file += header;
|
file.file += header;
|
||||||
file.virtualOffset += header.length;
|
file.virtualOffset += header.length;
|
||||||
};
|
}
|
||||||
|
|
||||||
function createTableEntry(file, tag, data) {
|
function createTableEntry(file, tag, data) {
|
||||||
// offset
|
// offset
|
||||||
@ -2540,7 +2541,7 @@ var Font = (function FontClosure() {
|
|||||||
string32(offset) + string32(length));
|
string32(offset) + string32(length));
|
||||||
file.file += tableEntry;
|
file.file += tableEntry;
|
||||||
file.virtualOffset += data.length;
|
file.virtualOffset += data.length;
|
||||||
};
|
}
|
||||||
|
|
||||||
function getRanges(glyphs) {
|
function getRanges(glyphs) {
|
||||||
// Array.sort() sorts by characters, not numerically, so convert to an
|
// Array.sort() sorts by characters, not numerically, so convert to an
|
||||||
@ -2569,7 +2570,7 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ranges;
|
return ranges;
|
||||||
};
|
}
|
||||||
|
|
||||||
function createCmapTable(glyphs, deltas) {
|
function createCmapTable(glyphs, deltas) {
|
||||||
var ranges = getRanges(glyphs);
|
var ranges = getRanges(glyphs);
|
||||||
@ -2646,7 +2647,7 @@ var Font = (function FontClosure() {
|
|||||||
'\x00\x04' + // format
|
'\x00\x04' + // format
|
||||||
string16(format314.length + 4) + // length
|
string16(format314.length + 4) + // length
|
||||||
format314);
|
format314);
|
||||||
};
|
}
|
||||||
|
|
||||||
function validateOS2Table(os2) {
|
function validateOS2Table(os2) {
|
||||||
var stream = new Stream(os2.data);
|
var stream = new Stream(os2.data);
|
||||||
@ -2769,7 +2770,7 @@ var Font = (function FontClosure() {
|
|||||||
string16(0) + // usDefaultChar
|
string16(0) + // usDefaultChar
|
||||||
string16(firstCharIndex || properties.firstChar) + // usBreakChar
|
string16(firstCharIndex || properties.firstChar) + // usBreakChar
|
||||||
'\x00\x03'; // usMaxContext
|
'\x00\x03'; // usMaxContext
|
||||||
};
|
}
|
||||||
|
|
||||||
function createPostTable(properties) {
|
function createPostTable(properties) {
|
||||||
var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
|
var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
|
||||||
@ -2782,7 +2783,7 @@ var Font = (function FontClosure() {
|
|||||||
'\x00\x00\x00\x00' + // maxMemType42
|
'\x00\x00\x00\x00' + // maxMemType42
|
||||||
'\x00\x00\x00\x00' + // minMemType1
|
'\x00\x00\x00\x00' + // minMemType1
|
||||||
'\x00\x00\x00\x00'; // maxMemType1
|
'\x00\x00\x00\x00'; // maxMemType1
|
||||||
};
|
}
|
||||||
|
|
||||||
function createNameTable(name, proto) {
|
function createNameTable(name, proto) {
|
||||||
if (!proto) {
|
if (!proto) {
|
||||||
@ -2925,7 +2926,7 @@ var Font = (function FontClosure() {
|
|||||||
offset: offset,
|
offset: offset,
|
||||||
data: data
|
data: data
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
function readOpenTypeHeader(ttf) {
|
function readOpenTypeHeader(ttf) {
|
||||||
return {
|
return {
|
||||||
@ -2935,7 +2936,7 @@ var Font = (function FontClosure() {
|
|||||||
entrySelector: int16(ttf.getBytes(2)),
|
entrySelector: int16(ttf.getBytes(2)),
|
||||||
rangeShift: int16(ttf.getBytes(2))
|
rangeShift: int16(ttf.getBytes(2))
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
function createGlyphNameMap(glyphs, ids, properties) {
|
function createGlyphNameMap(glyphs, ids, properties) {
|
||||||
var glyphNames = properties.glyphNames;
|
var glyphNames = properties.glyphNames;
|
||||||
@ -3171,7 +3172,7 @@ var Font = (function FontClosure() {
|
|||||||
mappings: mappings,
|
mappings: mappings,
|
||||||
hasShortCmap: hasShortCmap
|
hasShortCmap: hasShortCmap
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
function sanitizeMetrics(font, header, metrics, numGlyphs) {
|
function sanitizeMetrics(font, header, metrics, numGlyphs) {
|
||||||
if (!header) {
|
if (!header) {
|
||||||
@ -3207,7 +3208,7 @@ var Font = (function FontClosure() {
|
|||||||
entries += '\x00\x00';
|
entries += '\x00\x00';
|
||||||
metrics.data = stringToArray(entries);
|
metrics.data = stringToArray(entries);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart) {
|
function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart) {
|
||||||
if (sourceEnd - sourceStart <= 12) {
|
if (sourceEnd - sourceStart <= 12) {
|
||||||
@ -3357,7 +3358,7 @@ var Font = (function FontClosure() {
|
|||||||
startOffset = endOffset;
|
startOffset = endOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeOffset == 0) {
|
if (writeOffset === 0) {
|
||||||
// glyf table cannot be empty -- redoing the glyf and loca tables
|
// glyf table cannot be empty -- redoing the glyf and loca tables
|
||||||
// to have single glyph with one point
|
// to have single glyph with one point
|
||||||
var simpleGlyph = new Uint8Array(
|
var simpleGlyph = new Uint8Array(
|
||||||
@ -3484,7 +3485,7 @@ var Font = (function FontClosure() {
|
|||||||
offset: int16(font.getBytes(2))
|
offset: int16(font.getBytes(2))
|
||||||
};
|
};
|
||||||
// using only Macintosh and Windows platform/encoding names
|
// using only Macintosh and Windows platform/encoding names
|
||||||
if ((r.platform == 1 && r.encoding == 0 && r.language == 0) ||
|
if ((r.platform == 1 && r.encoding === 0 && r.language === 0) ||
|
||||||
(r.platform == 3 && r.encoding == 1 && r.language == 0x409)) {
|
(r.platform == 3 && r.encoding == 1 && r.language == 0x409)) {
|
||||||
records.push(r);
|
records.push(r);
|
||||||
}
|
}
|
||||||
@ -3516,7 +3517,7 @@ var Font = (function FontClosure() {
|
|||||||
var data = os2Table.data;
|
var data = os2Table.data;
|
||||||
// usWinAscent == 0 makes font unreadable by windows
|
// usWinAscent == 0 makes font unreadable by windows
|
||||||
var usWinAscent = (data[74] << 8) | data[75];
|
var usWinAscent = (data[74] << 8) | data[75];
|
||||||
if (usWinAscent == 0)
|
if (usWinAscent === 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -3747,7 +3748,7 @@ var Font = (function FontClosure() {
|
|||||||
|
|
||||||
// Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
|
// Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
|
||||||
// Sometimes it's 0. That needs to be fixed
|
// Sometimes it's 0. That needs to be fixed
|
||||||
if (hhea.data[10] == 0 && hhea.data[11] == 0) {
|
if (hhea.data[10] === 0 && hhea.data[11] === 0) {
|
||||||
hhea.data[10] = 0xFF;
|
hhea.data[10] = 0xFF;
|
||||||
hhea.data[11] = 0xFF;
|
hhea.data[11] = 0xFF;
|
||||||
}
|
}
|
||||||
@ -4211,7 +4212,7 @@ var Font = (function FontClosure() {
|
|||||||
var firstChar = properties.firstChar, lastChar = properties.lastChar;
|
var firstChar = properties.firstChar, lastChar = properties.lastChar;
|
||||||
var map = [];
|
var map = [];
|
||||||
if (properties.composite) {
|
if (properties.composite) {
|
||||||
var isIdentityMap = this.cidToUnicode.length == 0;
|
var isIdentityMap = this.cidToUnicode.length === 0;
|
||||||
for (var i = firstChar, ii = lastChar; i <= ii; i++) {
|
for (var i = firstChar, ii = lastChar; i <= ii; i++) {
|
||||||
// TODO missing map the character according font's CMap
|
// TODO missing map the character according font's CMap
|
||||||
var cid = i;
|
var cid = i;
|
||||||
@ -4352,7 +4353,7 @@ var Font = (function FontClosure() {
|
|||||||
if (!charcode && 'toUnicode' in this)
|
if (!charcode && 'toUnicode' in this)
|
||||||
charcode = this.toUnicode.indexOf(glyphUnicode);
|
charcode = this.toUnicode.indexOf(glyphUnicode);
|
||||||
// setting it to unicode if negative or undefined
|
// setting it to unicode if negative or undefined
|
||||||
if (!(charcode > 0))
|
if (charcode <= 0)
|
||||||
charcode = glyphUnicode;
|
charcode = glyphUnicode;
|
||||||
// trying to get width via charcode
|
// trying to get width via charcode
|
||||||
width = this.widths[charcode];
|
width = this.widths[charcode];
|
||||||
@ -4660,7 +4661,6 @@ var Type1CharString = (function Type1CharStringClosure() {
|
|||||||
break;
|
break;
|
||||||
case 11: // return
|
case 11: // return
|
||||||
return error;
|
return error;
|
||||||
break;
|
|
||||||
case 13: // hsbw
|
case 13: // hsbw
|
||||||
if (this.stack.length < 2) {
|
if (this.stack.length < 2) {
|
||||||
error = true;
|
error = true;
|
||||||
@ -5033,7 +5033,7 @@ var Type1Parser = function type1Parser() {
|
|||||||
var blueArray = readNumberArray(eexecStr, i + 1);
|
var blueArray = readNumberArray(eexecStr, i + 1);
|
||||||
// *Blue* values may contain invalid data: disables reading of
|
// *Blue* values may contain invalid data: disables reading of
|
||||||
// those values when hinting is disabled.
|
// those values when hinting is disabled.
|
||||||
if (blueArray.length > 0 && (blueArray.length % 2) == 0 &&
|
if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
|
||||||
HINTING_ENABLED) {
|
HINTING_ENABLED) {
|
||||||
program.properties.privateData[token.substring(1)] = blueArray;
|
program.properties.privateData[token.substring(1)] = blueArray;
|
||||||
}
|
}
|
||||||
@ -5649,7 +5649,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
while (bytes[offset] != 1)
|
while (bytes[offset] != 1)
|
||||||
++offset;
|
++offset;
|
||||||
|
|
||||||
if (offset != 0) {
|
if (offset !== 0) {
|
||||||
info('cff data is shifted');
|
info('cff data is shifted');
|
||||||
bytes = bytes.subarray(offset);
|
bytes = bytes.subarray(offset);
|
||||||
this.bytes = bytes;
|
this.bytes = bytes;
|
||||||
@ -5739,7 +5739,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
var start = pos;
|
var start = pos;
|
||||||
var end = pos;
|
var end = pos;
|
||||||
|
|
||||||
if (count != 0) {
|
if (count !== 0) {
|
||||||
var offsetSize = bytes[pos++];
|
var offsetSize = bytes[pos++];
|
||||||
// add 1 for offset to determine size of last object
|
// add 1 for offset to determine size of last object
|
||||||
var startPos = pos + ((count + 1) * offsetSize) - 1;
|
var startPos = pos + ((count + 1) * offsetSize) - 1;
|
||||||
@ -5796,8 +5796,8 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
return strings;
|
return strings;
|
||||||
},
|
},
|
||||||
createDict: function CFFParser_createDict(type, dict, strings) {
|
createDict: function CFFParser_createDict(Type, dict, strings) {
|
||||||
var cffDict = new type(strings);
|
var cffDict = new Type(strings);
|
||||||
var types = cffDict.types;
|
var types = cffDict.types;
|
||||||
|
|
||||||
for (var i = 0, ii = dict.length; i < ii; ++i) {
|
for (var i = 0, ii = dict.length; i < ii; ++i) {
|
||||||
@ -5825,7 +5825,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
var validationCommand = null;
|
var validationCommand = null;
|
||||||
if (value == 12) {
|
if (value == 12) {
|
||||||
var q = data[j++];
|
var q = data[j++];
|
||||||
if (q == 0) {
|
if (q === 0) {
|
||||||
// The CFF specification state that the 'dotsection' command
|
// The CFF specification state that the 'dotsection' command
|
||||||
// (12, 0) is deprecated and treated as a no-op, but all Type2
|
// (12, 0) is deprecated and treated as a no-op, but all Type2
|
||||||
// charstrings processors should support them. Unfortunately
|
// charstrings processors should support them. Unfortunately
|
||||||
@ -5929,7 +5929,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
privateDict.subrsIndex = subrsIndex.obj;
|
privateDict.subrsIndex = subrsIndex.obj;
|
||||||
},
|
},
|
||||||
parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
|
parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
|
||||||
if (pos == 0) {
|
if (pos === 0) {
|
||||||
return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
|
return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
|
||||||
ISOAdobeCharset);
|
ISOAdobeCharset);
|
||||||
} else if (pos == 1) {
|
} else if (pos == 1) {
|
||||||
@ -6000,7 +6000,7 @@ var CFFParser = (function CFFParserClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos == 0 || pos == 1) {
|
if (pos === 0 || pos == 1) {
|
||||||
predefined = true;
|
predefined = true;
|
||||||
format = pos;
|
format = pos;
|
||||||
var baseEncoding = pos ? Encodings.ExpertEncoding :
|
var baseEncoding = pos ? Encodings.ExpertEncoding :
|
||||||
@ -6253,7 +6253,7 @@ var CFFTopDict = (function CFFTopDictClosure() {
|
|||||||
[[12, 5], 'PaintType', 'num', 0],
|
[[12, 5], 'PaintType', 'num', 0],
|
||||||
[[12, 6], 'CharstringType', 'num', 2],
|
[[12, 6], 'CharstringType', 'num', 2],
|
||||||
[[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
|
[[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
|
||||||
[.001, 0, 0, .001, 0, 0]],
|
[0.001, 0, 0, 0.001, 0, 0]],
|
||||||
[13, 'UniqueID', 'num', null],
|
[13, 'UniqueID', 'num', null],
|
||||||
[5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
|
[5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
|
||||||
[[12, 8], 'StrokeWidth', 'num', 0],
|
[[12, 8], 'StrokeWidth', 'num', 0],
|
||||||
@ -6423,7 +6423,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
array[i] = str.charCodeAt(i);
|
array[i] = str.charCodeAt(i);
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
};
|
}
|
||||||
function CFFCompiler(cff) {
|
function CFFCompiler(cff) {
|
||||||
this.cff = cff;
|
this.cff = cff;
|
||||||
}
|
}
|
||||||
@ -6506,7 +6506,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
return output.data;
|
return output.data;
|
||||||
},
|
},
|
||||||
encodeNumber: function CFFCompiler_encodeNumber(value) {
|
encodeNumber: function CFFCompiler_encodeNumber(value) {
|
||||||
if (parseFloat(value) == parseInt(value) && !isNaN(value)) // isInt
|
if (parseFloat(value) == parseInt(value, 10) && !isNaN(value)) // isInt
|
||||||
return this.encodeInteger(value);
|
return this.encodeInteger(value);
|
||||||
else
|
else
|
||||||
return this.encodeFloat(value);
|
return this.encodeFloat(value);
|
||||||
@ -6706,7 +6706,7 @@ var CFFCompiler = (function CFFCompilerClosure() {
|
|||||||
|
|
||||||
// If there is no object, just create an index. This technically
|
// If there is no object, just create an index. This technically
|
||||||
// should just be [0, 0] but OTS has an issue with that.
|
// should just be [0, 0] but OTS has an issue with that.
|
||||||
if (count == 0)
|
if (count === 0)
|
||||||
return [0, 0, 0];
|
return [0, 0, 0];
|
||||||
|
|
||||||
var data = [(count >> 8) & 0xFF, count & 0xff];
|
var data = [(count >> 8) & 0xFF, count & 0xff];
|
||||||
|
Loading…
Reference in New Issue
Block a user