Issue #2008 - Fix lint errors for src/fonts.js

This commit is contained in:
Jon Buckley 2013-01-31 18:31:41 -05:00
parent c281805fde
commit 3793ca5283

View File

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