From 5a3d85bf53341078186d7fda8688efab921e610f Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 14:20:15 +0300 Subject: [PATCH 01/10] Fix small lint issues. --- charsets.js | 4 ++++ extensions/firefox/components/pdfContentHandler.js | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/charsets.js b/charsets.js index 59fcdf5cf..7f54ab327 100644 --- a/charsets.js +++ b/charsets.js @@ -1,3 +1,7 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ + +'use strict'; var ISOAdobeCharset = [ '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', diff --git a/extensions/firefox/components/pdfContentHandler.js b/extensions/firefox/components/pdfContentHandler.js index 879924047..9186bfd8a 100644 --- a/extensions/firefox/components/pdfContentHandler.js +++ b/extensions/firefox/components/pdfContentHandler.js @@ -131,8 +131,7 @@ pdfContentHandler.prototype = { throw Cr.NS_ERROR_WONT_HANDLE_CONTENT; let window = null; - let callbacks = aRequest.notificationCallbacks ? - aRequest.notificationCallbacks : + let callbacks = aRequest.notificationCallbacks || aRequest.loadGroup.notificationCallbacks; if (!callbacks) return; From 8cb7c218fdb614bf6406b092b9e163622aacc3c8 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 14:27:14 +0300 Subject: [PATCH 02/10] Add use strict to metrics.js --- metrics.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metrics.js b/metrics.js index 9cb8eb0e6..d4d07ec0d 100644 --- a/metrics.js +++ b/metrics.js @@ -1,6 +1,8 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ +'use strict'; + var Metrics = { 'Courier': 600, 'Courier-Bold': 600, From fb174290c7ed5b2297a5fb53c404cc390478d903 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 22:03:57 +0300 Subject: [PATCH 03/10] Move function creation out of the loop. Also name the anonymous function. Jslint complains about this. --- pdf.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pdf.js b/pdf.js index 3ebddd119..ef8493001 100644 --- a/pdf.js +++ b/pdf.js @@ -4381,6 +4381,10 @@ var PartialEvaluator = (function partialEvaluator() { var patterns = xref.fetchIfRef(resources.get('Pattern')) || new Dict(); var parser = new Parser(new Lexer(stream), false); var args = [], argsArray = [], fnArray = [], obj; + var getObjBt = function getObjBt() { + parser = this.oldParser; + return { name: 'BT' }; + }; while (!isEOF(obj = parser.getObj())) { if (isCmd(obj)) { @@ -4392,10 +4396,7 @@ var PartialEvaluator = (function partialEvaluator() { fn = OP_MAP[cmd.substr(0, cmd.length - 2)]; // feeding 'BT' on next interation parser = { - getObj: function() { - parser = this.oldParser; - return { name: 'BT' }; - }, + getObj: getObjBt, oldParser: parser }; } From 3c53e34c7b9815b6ab5e82117e300045f6a8c2b1 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sat, 15 Oct 2011 23:32:56 +0300 Subject: [PATCH 04/10] Refactor duplicate code in getBlackCode. --- pdf.js | 64 +++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/pdf.js b/pdf.js index 3ebddd119..0aaf68539 100644 --- a/pdf.js +++ b/pdf.js @@ -2089,45 +2089,35 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - var n; - for (n = 2; n <= 6; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 6) - code <<= 6 - n; - p = blackTable3[code]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; - } - } - for (n = 7; n <= 12; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 12) - code <<= 12 - n; - if (code >= 64) { - p = blackTable2[code - 64]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; + var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, table, limit) { + for (var i = start; i <= end; ++i) { + var code = this.lookBits(i); + if (code == EOF) + return [true, 1]; + if (i < end) + code <<= end - i; + if (code >= limit) { + var p = table[code]; + if (p[0] == i) { + this.eatBits(i); + return [true, p[1]]; + } } } - } - for (n = 10; n <= 13; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 13) - code <<= 13 - n; - p = blackTable1[code]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; - } - } + return [false, 0]; + }; + + var result = findBlackCode(2, 6, blackTable3, -1); + if (result[0]) + return result[1]; + + result = findBlackCode(7, 12, blackTable2, 64); + if (result[0]) + return result[1]; + + result = findBlackCode(10, 13, blackTable1, -1); + if (result[0]) + return result[1]; } warn('bad black code'); this.eatBits(1); From d39ea4dc5486911a8ce154f00d0d06b54b590386 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Sun, 16 Oct 2011 12:34:34 +0300 Subject: [PATCH 05/10] Adhere to 80 char line limit. --- pdf.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 0aaf68539..60774808a 100644 --- a/pdf.js +++ b/pdf.js @@ -2089,7 +2089,8 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, table, limit) { + var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, + table, limit) { for (var i = start; i <= end; ++i) { var code = this.lookBits(i); if (code == EOF) From 674d6a7d18821fcea8570b70a2454d5a1ab2d4ec Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Mon, 17 Oct 2011 20:39:29 +0200 Subject: [PATCH 06/10] Fix warnings in strict mode --- fonts.js | 14 +++++++++++--- pdf.js | 12 ++++++++---- web/compatibility.js | 2 +- web/viewer.js | 7 +++++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/fonts.js b/fonts.js index bbff14e89..bcec5d2ac 100644 --- a/fonts.js +++ b/fonts.js @@ -710,7 +710,13 @@ var Font = (function Font() { }; function createOS2Table(properties, override) { - var override = override || {}; + override = override || { + unitsPerEm: 0, + yMax: 0, + yMin: 0, + ascent: 0, + descent: 0 + }; var ulUnicodeRange1 = 0; var ulUnicodeRange2 = 0; @@ -1322,7 +1328,8 @@ var Font = (function Font() { 'OS/2': stringToArray(createOS2Table(properties)), // Character to glyphs mapping - 'cmap': createCMapTable(charstrings.slice(), font.glyphIds), + 'cmap': createCMapTable(charstrings.slice(), + ('glyphIds' in font) ? font.glyphIds: null), // Font header 'head': (function fontFieldsHead() { @@ -2612,7 +2619,8 @@ var Type2CFF = (function type2CFF() { if (unicode <= 0x1f || (unicode >= 127 && unicode <= 255)) unicode += kCmapGlyphOffset; - var width = isNum(mapping.width) ? mapping.width : defaultWidth; + var width = ('width' in mapping) && isNum(mapping.width) ? mapping.width + : defaultWidth; properties.encoding[code] = { unicode: unicode, width: width diff --git a/pdf.js b/pdf.js index ef8493001..2ee61ada6 100644 --- a/pdf.js +++ b/pdf.js @@ -5163,7 +5163,8 @@ var CanvasGraphics = (function canvasGraphics() { stroke: function canvasGraphicsStroke() { var ctx = this.ctx; var strokeColor = this.current.strokeColor; - if (strokeColor && strokeColor.type === 'Pattern') { + if (strokeColor && strokeColor.hasOwnProperty('type') && + strokeColor.type === 'Pattern') { // for patterns, we transform to pattern space, calculate // the pattern, call stroke, and restore to user space ctx.save(); @@ -5184,7 +5185,8 @@ var CanvasGraphics = (function canvasGraphics() { var ctx = this.ctx; var fillColor = this.current.fillColor; - if (fillColor && fillColor.type === 'Pattern') { + if (fillColor && fillColor.hasOwnProperty('type') && + fillColor.type === 'Pattern') { ctx.save(); ctx.fillStyle = fillColor.getPattern(ctx); ctx.fill(); @@ -5204,7 +5206,8 @@ var CanvasGraphics = (function canvasGraphics() { var ctx = this.ctx; var fillColor = this.current.fillColor; - if (fillColor && fillColor.type === 'Pattern') { + if (fillColor && fillColor.hasOwnProperty('type') && + fillColor.type === 'Pattern') { ctx.save(); ctx.fillStyle = fillColor.getPattern(ctx); ctx.fill(); @@ -5214,7 +5217,8 @@ var CanvasGraphics = (function canvasGraphics() { } var strokeColor = this.current.strokeColor; - if (strokeColor && strokeColor.type === 'Pattern') { + if (strokeColor && strokeColor.hasOwnProperty('type') && + strokeColor.type === 'Pattern') { ctx.save(); ctx.strokeStyle = strokeColor.getPattern(ctx); ctx.stroke(); diff --git a/web/compatibility.js b/web/compatibility.js index 36df0e2a5..ad4c8f8a9 100644 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -163,7 +163,7 @@ // IE9 text/html data URI (function checkDocumentDocumentModeCompatibility() { - if (document.documentMode !== 9) + if (!('documentMode' in document) || document.documentMode !== 9) return; // overriding the src property var originalSrcDescriptor = Object.getOwnPropertyDescriptor( diff --git a/web/viewer.js b/web/viewer.js index 93f6acd31..91562baf4 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -178,7 +178,9 @@ var PDFView = { while (sidebar.hasChildNodes()) sidebar.removeChild(sidebar.lastChild); - clearInterval(sidebar._loadingInterval); + + if ('_loadingInterval' in sidebar) + clearInterval(sidebar._loadingInterval); var container = document.getElementById('viewer'); while (container.hasChildNodes()) @@ -544,7 +546,8 @@ window.addEventListener('load', function webViewerLoad(evt) { params[unescape(param[0])] = unescape(param[1]); } - PDFView.open(params.file || kDefaultURL, parseFloat(params.scale)); + var scale = ('scale' in params) ? params.scale : kDefaultScale; + PDFView.open(params.file || kDefaultURL, parseFloat(scale)); if (!window.File || !window.FileReader || !window.FileList || !window.Blob) document.getElementById('fileInput').style.display = 'none'; From e83c77148d4c64602ad3d88aba0c4b5c5e998186 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Mon, 17 Oct 2011 21:04:54 +0200 Subject: [PATCH 07/10] add oncontextmenu='return false;' to buttons --- web/viewer.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/viewer.html b/web/viewer.html index 160c5ce57..428171b9e 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -17,12 +17,12 @@
- - @@ -36,16 +36,16 @@
- -
- @@ -59,14 +59,14 @@
-
- +
From 6688c3a1f5c1ff8d0071bba8d76e60df9f99ec2f Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Mon, 17 Oct 2011 22:24:19 +0300 Subject: [PATCH 08/10] Handle blackTable2 array access correctly. --- pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 60774808a..f11d28c36 100644 --- a/pdf.js +++ b/pdf.js @@ -2098,7 +2098,7 @@ var CCITTFaxStream = (function ccittFaxStream() { if (i < end) code <<= end - i; if (code >= limit) { - var p = table[code]; + var p = table[code - ((limit == -1) ? 0 : limit)]; if (p[0] == i) { this.eatBits(i); return [true, p[1]]; From 3ba167645fb75374e86aae30648fb385d76af970 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Tue, 18 Oct 2011 00:29:43 +0300 Subject: [PATCH 09/10] Refactor duplicate code in getWhiteCode. Reuse functionality from getBlackCode for this. --- pdf.js | 74 ++++++++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/pdf.js b/pdf.js index 68c5dfad4..d4326b5ab 100644 --- a/pdf.js +++ b/pdf.js @@ -2021,6 +2021,25 @@ var CCITTFaxStream = (function ccittFaxStream() { return EOF; }; + var findTableCode = function ccittFaxStreamFindTableCode(start, end, table, + limit) { + for (var i = start; i <= end; ++i) { + var code = this.lookBits(i); + if (code == EOF) + return [true, 1]; + if (i < end) + code <<= end - i; + if (code >= limit) { + var p = table[code - ((limit == ccittEOL) ? 0 : limit)]; + if (p[0] == i) { + this.eatBits(i); + return [true, p[1]]; + } + } + } + return [false, 0]; + }; + constructor.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() { var code = 0; var p; @@ -2040,31 +2059,13 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - for (var n = 1; n <= 9; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; + var result = findTableCode(1, 9, whiteTable2, ccittEOL); + if (result[0]) + return result[1]; - if (n < 9) - code <<= 9 - n; - p = whiteTable2[code]; - if (p[0] == n) { - this.eatBits(n); - return p[0]; - } - } - for (var n = 11; n <= 12; ++n) { - code = this.lookBits(n); - if (code == EOF) - return 1; - if (n < 12) - code <<= 12 - n; - p = whiteTable1[code]; - if (p[0] == n) { - this.eatBits(n); - return p[1]; - } - } + result = findTableCode(11, 12, whiteTable1, ccittEOL); + if (result[0]) + return result[1]; } warn('bad white code'); this.eatBits(1); @@ -2089,34 +2090,15 @@ var CCITTFaxStream = (function ccittFaxStream() { return p[1]; } } else { - var findBlackCode = function ccittFaxStreamFindBlackCode(start, end, - table, limit) { - for (var i = start; i <= end; ++i) { - var code = this.lookBits(i); - if (code == EOF) - return [true, 1]; - if (i < end) - code <<= end - i; - if (code >= limit) { - var p = table[code - ((limit == -1) ? 0 : limit)]; - if (p[0] == i) { - this.eatBits(i); - return [true, p[1]]; - } - } - } - return [false, 0]; - }; - - var result = findBlackCode(2, 6, blackTable3, -1); + var result = findTableCode(2, 6, blackTable3, ccittEOL); if (result[0]) return result[1]; - result = findBlackCode(7, 12, blackTable2, 64); + result = findTableCode(7, 12, blackTable2, 64); if (result[0]) return result[1]; - result = findBlackCode(10, 13, blackTable1, -1); + result = findTableCode(10, 13, blackTable1, ccittEOL); if (result[0]) return result[1]; } From f1444d6175794dd942c8a7d0f74b02508cb96bac Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Tue, 18 Oct 2011 00:18:12 +0200 Subject: [PATCH 10/10] Fix wrongs ids --- web/viewer.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/viewer.html b/web/viewer.html index 428171b9e..5da063b91 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -36,10 +36,10 @@
- -