From d9e01b1d7a146bda289a483584af37a63891f479 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Thu, 8 Sep 2011 22:37:35 +0300 Subject: [PATCH 1/4] Fix gjslint warnings. --- fonts.js | 41 +++++++++++++++++++++-------------------- pdf.js | 4 ++-- web/viewer.js | 2 +- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/fonts.js b/fonts.js index 659c5157e..f3178b37f 100755 --- a/fonts.js +++ b/fonts.js @@ -447,10 +447,10 @@ var Font = (function Font() { this.glyphs = properties.glyphs; this.sizes = []; - var names = name.split("+"); + var names = name.split('+'); names = names.length > 1 ? names[1] : names[0]; names = names.split(/[-,_]/g)[0]; - this.serif = serifFonts[names] || (name.indexOf("Serif") != -1); + this.serif = serifFonts[names] || (name.indexOf('Serif') != -1); // If the font is to be ignored, register it like an already loaded font // to avoid the cost of waiting for it be be loaded by the platform. @@ -470,8 +470,8 @@ var Font = (function Font() { // Use 'name' instead of 'fontName' here because the original // name ArialNarrow for example will be replaced by Helvetica. - this.narrow = (name.indexOf("Narrow") != -1) - this.black = (name.indexOf("Black") != -1) + this.narrow = (name.indexOf('Narrow') != -1); + this.black = (name.indexOf('Black') != -1); this.loadedName = fontName.split('-')[0]; this.loading = false; @@ -485,8 +485,8 @@ var Font = (function Font() { this.mimetype = 'font/opentype'; var subtype = properties.subtype; - var cff = (subtype === 'Type1C') ? new Type2CFF(file, properties) - : new CFF(name, file, properties); + var cff = (subtype === 'Type1C') ? + new Type2CFF(file, properties) : new CFF(name, file, properties); // Wrap the CFF data inside an OTF font file data = this.convert(name, cff, properties); @@ -912,7 +912,7 @@ var Font = (function Font() { // Check that table are sorted by platformID then encodingID, records.sort(function(a, b) { return ((a.platformID << 16) + a.encodingID) - - ((b.platformID << 16) + b.encodingID) + ((b.platformID << 16) + b.encodingID); }); var tables = [records[0]]; @@ -944,7 +944,7 @@ var Font = (function Font() { } for (var i = 0; i < data.length; i++) - cmap.data[i] = data.charCodeAt(i); + cmap.data[i] = data.charCodeAt(i); } var encoding = properties.encoding; @@ -972,7 +972,7 @@ var Font = (function Font() { var code = encoding[index]; for (var glyph in properties.glyphs) { - if (properties.glyphs[glyph] == code) + if (properties.glyphs[glyph] == code) break; } @@ -981,7 +981,7 @@ var Font = (function Font() { glyphs.push({ glyph: glyph, unicode: unicode }); } } - + return cmap.data = createCMapTable(glyphs, deltas); } else if (format == 6) { // Format 6 is a 2-bytes dense mapping, which means the font data @@ -1693,7 +1693,7 @@ var Type1Parser = function() { }; var c = eexecStr[i]; - if ((glyphsSection || subrsSection) && + if ((glyphsSection || subrsSection) && (token == 'RD' || token == '-|')) { i++; var data = eexec.slice(i, i + length); @@ -1729,7 +1729,7 @@ var Type1Parser = function() { getToken(); // read in 'array' for (var j = 0; j < num; ++j) { var t = getToken(); // read in 'dup' - if (t == 'ND' || t == '|-' || t == 'noaccess') + if (t == 'ND' || t == '|-' || t == 'noaccess') break; var index = parseInt(getToken(), 10); if (index > j) @@ -1828,7 +1828,7 @@ var Type1Parser = function() { if (token == 'dup') { var index = parseInt(getToken(), 10); var glyph = getToken(); - + if ('undefined' == typeof(properties.differences[index])) { properties.encoding[index] = glyph; properties.glyphs[glyph] = GlyphsUnicode[glyph] || index; @@ -1847,7 +1847,7 @@ var Type1Parser = function() { }; /** - * The CFF class takes a Type1 file and wrap it into a + * The CFF class takes a Type1 file and wrap it into a * 'Compact Font Format' which itself embed Type2 charstrings. */ var CFFStrings = [ @@ -2289,7 +2289,7 @@ var Type2CFF = (function() { var charStrings = this.parseIndex(topDict.CharStrings); var charset = this.parseCharsets(topDict.charset, charStrings.length, strings); - var hasSupplement = this.parseEncoding(topDict.Encoding, properties, + var hasSupplement = this.parseEncoding(topDict.Encoding, properties, strings, charset); // The font sanitizer does not support CFF encoding with a @@ -2360,7 +2360,8 @@ var Type2CFF = (function() { return charstrings; }, - parseEncoding: function cff_parseencoding(pos, properties, strings, charset) { + parseEncoding: function cff_parseencoding(pos, properties, strings, + charset) { var encoding = {}; var bytes = this.bytes; @@ -2375,8 +2376,8 @@ var Type2CFF = (function() { if (pos == 0 || pos == 1) { var gid = 1; - var baseEncoding = pos ? Encodings.ExpertEncoding - : Encodings.StandardEncoding; + var baseEncoding = + pos ? Encodings.ExpertEncoding : Encodings.StandardEncoding; for (var i = 0; i < charset.length; i++) { var index = baseEncoding.indexOf(charset[i]); if (index != -1) @@ -2387,7 +2388,7 @@ var Type2CFF = (function() { switch (format & 0x7f) { case 0: var glyphsCount = bytes[pos++]; - for (var i = 1; i <= glyphsCount; i++) + for (var i = 1; i <= glyphsCount; i++) encoding[bytes[pos++]] = i; if (format & 0x80) { @@ -2413,7 +2414,7 @@ var Type2CFF = (function() { break; default: - error('Unknow encoding format: ' + format + " in CFF"); + error('Unknow encoding format: ' + format + ' in CFF'); break; } } diff --git a/pdf.js b/pdf.js index fbceb8e7b..c36462714 100644 --- a/pdf.js +++ b/pdf.js @@ -4389,7 +4389,7 @@ var PartialEvaluator = (function() { var type = dict.get('Subtype'); assertWellFormed(IsName(type), 'invalid font Subtype'); - var composite = false + var composite = false; if (type.name == 'Type0') { // If font is a composite // - get the descendant font @@ -4449,7 +4449,7 @@ var PartialEvaluator = (function() { // According to the spec if 'FontDescriptor' is declared, 'FirstChar', // 'LastChar' and 'Widths' should exists too, but some PDF encoders seems // to ignore this rule when a variant of a standart font is used. - // TODO Fill the width array depending on which of the base font this is + // TODO Fill the width array depending on which of the base font this is // a variant. var firstChar = xref.fetchIfRef(dict.get('FirstChar')) || 0; var lastChar = xref.fetchIfRef(dict.get('LastChar')) || 256; diff --git a/web/viewer.js b/web/viewer.js index c5d79c541..5752cf84e 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -593,7 +593,7 @@ window.addEventListener('pagechange', function pagechange(evt) { }, true); window.addEventListener('keydown', function keydown(evt) { - switch(evt.keyCode) { + switch (evt.keyCode) { case 61: // FF/Mac '=' case 107: // FF '+' and '=' case 187: // Chrome '+' From b8263a5c1f932e4d0493b6b2239a597067be83f9 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Thu, 8 Sep 2011 23:10:49 +0300 Subject: [PATCH 2/4] Initialize inputBuf. Fix also another jslint error. --- pdf.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pdf.js b/pdf.js index c36462714..797416c39 100644 --- a/pdf.js +++ b/pdf.js @@ -1553,7 +1553,7 @@ var CCITTFaxStream = (function() { this.row = 0; this.nextLine2D = this.encoding < 0; this.inputBits = 0; - this.inputBuf; + this.inputBuf = EOF; this.outputBits = 0; this.buf = EOF; @@ -3676,8 +3676,7 @@ var PDFDoc = (function() { if (find(stream, 'startxref', 1024, true)) { stream.skip(9); var ch; - while (Lexer.isSpace(ch = stream.getChar())) -; + while (Lexer.isSpace(ch = stream.getChar())){} var str = ''; while ((ch - '0') <= 9) { str += ch; From 63d3f0626510fe56f11695c09972370a806eba61 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Fri, 9 Sep 2011 00:52:11 +0300 Subject: [PATCH 3/4] Fix lastRow bug. It was introduced by 99ffc9991e00210d9f4c2dc1a97fee5021553264. --- pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 797416c39..ff87078b2 100644 --- a/pdf.js +++ b/pdf.js @@ -825,7 +825,7 @@ var PredictorStream = (function() { currentRow[i] = rawBytes[i]; for (; i < rowBytes; ++i) { var up = prevRow[i]; - var upLeft = lastRow[i - pixBytes]; + var upLeft = prevRow[i - pixBytes]; var left = currentRow[i - pixBytes]; var p = left + up - upLeft; From 946c4e2a887eaadb920d90f29ec2e181dfe55bb8 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Fri, 9 Sep 2011 20:12:38 +0300 Subject: [PATCH 4/4] Initialize inputBuf to zero. --- pdf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdf.js b/pdf.js index ff87078b2..ebce3d1b0 100644 --- a/pdf.js +++ b/pdf.js @@ -1553,7 +1553,7 @@ var CCITTFaxStream = (function() { this.row = 0; this.nextLine2D = this.encoding < 0; this.inputBits = 0; - this.inputBuf = EOF; + this.inputBuf = 0; this.outputBits = 0; this.buf = EOF; @@ -3676,7 +3676,7 @@ var PDFDoc = (function() { if (find(stream, 'startxref', 1024, true)) { stream.skip(9); var ch; - while (Lexer.isSpace(ch = stream.getChar())){} + while (Lexer.isSpace(ch = stream.getChar())) {} var str = ''; while ((ch - '0') <= 9) { str += ch;