From edd92c9db29f69ef092399dce877ff66e89ac4f4 Mon Sep 17 00:00:00 2001 From: Kalervo Kujala Date: Fri, 26 Aug 2011 23:55:14 +0300 Subject: [PATCH 01/10] Fix gjslint errors. --- fonts.js | 3 ++- pdf.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fonts.js b/fonts.js index 2d7ff94f5..3101a2c68 100755 --- a/fonts.js +++ b/fonts.js @@ -1891,7 +1891,8 @@ CFF.prototype = { return null; }, - getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs, properties) { + getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs, + properties) { var charstrings = []; var missings = []; diff --git a/pdf.js b/pdf.js index e7095b692..12aa9ca4c 100644 --- a/pdf.js +++ b/pdf.js @@ -4399,7 +4399,7 @@ var PartialEvaluator = (function() { var fontName = fontDict.get('Name'); if (!fontName) - fontName = xref.fetchIfRef(descriptor.get('FontName'));; + fontName = xref.fetchIfRef(descriptor.get('FontName')); assertWellFormed(IsName(fontName), 'invalid font name'); fontName = fontName.name.replace(/[\+,\-]/g, '_'); From f630b8c519cf6e98f1fdd283da0b693ada88374e Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 26 Aug 2011 22:58:03 -0500 Subject: [PATCH 02/10] Properly handle non-existent link destinations --- web/viewer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/viewer.js b/web/viewer.js index 8af6e01d1..ec7ff3001 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -87,6 +87,8 @@ var PDFView = { navigateTo: function(dest) { if (typeof dest === 'string') dest = this.destinations[dest]; + if (!(dest instanceof Array)) + return; // invalid destination // dest array looks like that: var destRef = dest[0]; var pageNumber = this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R']; From ff1f3ed882d93eb8262de30284c82c8a29e514e5 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 27 Aug 2011 10:10:36 -0500 Subject: [PATCH 03/10] Adds PDF index for "make server" --- test/test.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/test.py b/test/test.py index 4801c4b38..a6b01ec3d 100644 --- a/test/test.py +++ b/test/test.py @@ -103,6 +103,33 @@ class PDFTestHandler(BaseHTTPRequestHandler): with open(path, "rb") as f: self.wfile.write(f.read()) + def sendIndex(self, path, query): + if not path.endswith("/"): + # we need trailing slash + self.send_response(301) + redirectLocation = path + "/" + if query: + redirectLocation += "?" + query + self.send_header("Location", redirectLocation) + self.end_headers() + return + + self.send_response(200) + self.send_header("Content-Type", "text/html") + self.end_headers() + if query == "frame": + self.wfile.write("" + + "") + return + + location = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path)) + self.wfile.write("

PDFs of " + path + "

\n") + for filename in os.listdir(location): + if filename.lower().endswith('.pdf'): + self.wfile.write("" + + filename + "
\n") + self.wfile.write("") + def do_GET(self): url = urlparse(self.path) # Ignore query string @@ -115,6 +142,10 @@ class PDFTestHandler(BaseHTTPRequestHandler): self.sendFile(os.path.join(DOC_ROOT, "test", "resources", "favicon.ico"), ext) return + if os.path.isdir(path): + self.sendIndex(url.path, url.query) + return + if not (prefix == DOC_ROOT and os.path.isfile(path) and ext in MIMEs): From 39894f98b2d2fd7d35860825307efa79742a0472 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 27 Aug 2011 13:14:51 -0500 Subject: [PATCH 04/10] Fixing iframe's parent for postMessage in the font loading hack --- fonts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 3101a2c68..ce93d11e0 100755 --- a/fonts.js +++ b/fonts.js @@ -220,7 +220,7 @@ var FontLoader = { } src += ' var fontNames=[' + fontNamesArray + '];\n'; src += ' window.onload = function () {\n'; - src += ' top.postMessage(JSON.stringify(fontNames), "*");\n'; + src += ' parent.postMessage(JSON.stringify(fontNames), "*");\n'; src += ' }'; src += ''; for (var i = 0; i < names.length; ++i) { From 930e88941ccbeb9902792a05934a1f417eea47dc Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sat, 27 Aug 2011 17:10:15 -0500 Subject: [PATCH 05/10] Not-printing sidebar, toolbar, shadows and pages that were not loaded (#384) --- web/viewer.css | 31 +++++++++++++++++++++++++++++++ web/viewer.js | 2 ++ 2 files changed, 33 insertions(+) diff --git a/web/viewer.css b/web/viewer.css index 18da0b3d1..bb7da000e 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -210,3 +210,34 @@ canvas { -webkit-box-shadow: 0px 2px 10px #ff0; } +/* === Printed media overrides === */ +@media print { + #sidebar { + display: none; + } + + #controls { + display: none; + } + + #viewer { + margin: 0; + padding: 0; + } + + .page { + display: none; + margin: 0; + } + + .page canvas { + box-shadow: none; + -moz-box-shadow: none; + -webkit-box-shadow: none; + } + + .page[data-loaded] { + display: block; + page-break-after: always; + } +} diff --git a/web/viewer.js b/web/viewer.js index ec7ff3001..243afb7e5 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -211,6 +211,7 @@ var PageView = function(container, content, id, width, height, while (div.hasChildNodes()) div.removeChild(div.lastChild); + div.removeAttribute('data-loaded'); }; function setupLinks(canvas, content, scale) { @@ -259,6 +260,7 @@ var PageView = function(container, content, id, width, height, this.content.startRendering(ctx, this.updateStats); setupLinks(canvas, this.content, this.scale); + div.setAttribute('data-loaded', true); return true; }; From 5773511d16f82e555813b4a987db91feefd6909e Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 28 Aug 2011 15:10:14 -0500 Subject: [PATCH 06/10] Fixing font loading hack for IE9.. and some styles --- web/compatibility.js | 33 +++++++++++++++++++++++++++++++-- web/viewer.css | 10 ++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) mode change 100644 => 100755 web/compatibility.js mode change 100644 => 100755 web/viewer.css diff --git a/web/compatibility.js b/web/compatibility.js old mode 100644 new mode 100755 index d286692b1..878bf53ee --- a/web/compatibility.js +++ b/web/compatibility.js @@ -148,10 +148,39 @@ Function.prototype.bind = function(obj) { var fn = this, headArgs = Array.prototype.slice.call(arguments, 1); - var binded = function(tailArgs) { - var args = headArgs.concat(tailArgs); + var binded = function() { + var args = Array.prototype.concat.apply(headArgs, arguments); return fn.apply(obj, args); }; return binded; }; })(); + +// IE9 text/html data URI +(function() { + if (document.documentMode !== 9) + return; + // overriding the src property + var originalSrcDescriptor = Object.getOwnPropertyDescriptor( + HTMLIFrameElement.prototype, 'src'); + Object.defineProperty(HTMLIFrameElement.prototype, 'src', { + get: function() { return this.$src; }, + set: function(src) { + this.$src = src; + if (src.substr(0, 14) != 'data:text/html') { + originalSrcDescriptor['set'].call(this, src); + return; + } + // for text/html, using blank document and then + // document's open, write, and close operations + originalSrcDescriptor['set'].call(this, 'about:blank'); + setTimeout((function() { + var doc = this.contentDocument; + doc.open('text/html'); + doc.write(src.substr(src.indexOf(',') + 1)); + doc.close(); + }).bind(this), 0); + }, + enumerable: true + }); +})(); diff --git a/web/viewer.css b/web/viewer.css old mode 100644 new mode 100755 index bb7da000e..a8578eb7e --- a/web/viewer.css +++ b/web/viewer.css @@ -36,6 +36,11 @@ body { line-height: 32px; } +#controls > button > img { + width: 32px; + height: 32px; +} + #controls > button[disabled] > img { opacity: 0.5; } @@ -159,6 +164,11 @@ span#info { -webkit-box-shadow: 0px 4px 10px #000; } +#sidebarControls > button > img { + width: 32px; + height: 32px; +} + #sidebarControls > button[disabled] > img { opacity: 0.5; } From e4205ca66b304391cbaba61a20206ecdd50d7cf5 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 28 Aug 2011 15:15:16 -0500 Subject: [PATCH 07/10] rename to bound --- web/compatibility.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/compatibility.js b/web/compatibility.js index 878bf53ee..93d9d121b 100755 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -148,11 +148,11 @@ Function.prototype.bind = function(obj) { var fn = this, headArgs = Array.prototype.slice.call(arguments, 1); - var binded = function() { + var bound = function() { var args = Array.prototype.concat.apply(headArgs, arguments); return fn.apply(obj, args); }; - return binded; + return bound; }; })(); From 64b08e3d8224bea374d6af636f703d129220b800 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 28 Aug 2011 15:26:42 -0500 Subject: [PATCH 08/10] using .src --- web/compatibility.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/compatibility.js b/web/compatibility.js index 93d9d121b..e9a769163 100755 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -168,12 +168,12 @@ set: function(src) { this.$src = src; if (src.substr(0, 14) != 'data:text/html') { - originalSrcDescriptor['set'].call(this, src); + originalSrcDescriptor.set.call(this, src); return; } // for text/html, using blank document and then // document's open, write, and close operations - originalSrcDescriptor['set'].call(this, 'about:blank'); + originalSrcDescriptor.set.call(this, 'about:blank'); setTimeout((function() { var doc = this.contentDocument; doc.open('text/html'); From db09e34f71ab4e01b21888a3c7687318bc3d6d99 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 28 Aug 2011 16:14:37 -0500 Subject: [PATCH 09/10] Fix inverted B/W images in PIPEHEATCABLE.PDF --- pdf.js | 22 +++++++++++++--------- test/test.py | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pdf.js b/pdf.js index 12aa9ca4c..201744efe 100644 --- a/pdf.js +++ b/pdf.js @@ -5133,7 +5133,7 @@ var CanvasGraphics = (function() { var inverseDecode = !!imageObj.decode && imageObj.decode[0] > 0; imageObj.applyStencilMask(pixels, inverseDecode); } else - imageObj.fillRgbaBuffer(pixels); + imageObj.fillRgbaBuffer(pixels, imageObj.decode); tmpCtx.putImageData(imgData, 0, 0); ctx.drawImage(tmpCanvas, 0, -h); @@ -5928,7 +5928,7 @@ var PDFImage = (function() { }; constructor.prototype = { - getComponents: function getComponents(buffer) { + getComponents: function getComponents(buffer, decodeMap) { var bpc = this.bpc; if (bpc == 8) return buffer; @@ -5942,6 +5942,11 @@ var PDFImage = (function() { var output = new Uint8Array(length); if (bpc == 1) { + var valueZero = 0, valueOne = 255; + if (decodeMap) { + valueZero = decodeMap[0] ? 255 : 0; + valueOne = decodeMap[1] ? 255 : 0; + } var rowComps = width * numComps; var mask = 0; var buf = 0; @@ -5959,13 +5964,11 @@ var PDFImage = (function() { mask = 128; } - var t = buf & mask; - if (t == 0) - output[i] = 0; - else - output[i] = 255; + output[i] = !(buf & mask) ? valueZero : valueOne; } } else { + if (decodeMap != null) + TODO('interpolate component values'); var rowComps = width * numComps; var bits = 0; var buf = 0; @@ -6034,7 +6037,7 @@ var PDFImage = (function() { } } }, - fillRgbaBuffer: function fillRgbaBuffer(buffer) { + fillRgbaBuffer: function fillRgbaBuffer(buffer, decodeMap) { var numComps = this.numComps; var width = this.width; var height = this.height; @@ -6044,7 +6047,8 @@ var PDFImage = (function() { var rowBytes = (width * numComps * bpc + 7) >> 3; var imgArray = this.image.getBytes(height * rowBytes); - var comps = this.colorSpace.getRgbBuffer(this.getComponents(imgArray)); + var comps = this.colorSpace.getRgbBuffer( + this.getComponents(imgArray, decodeMap)); var compsPos = 0; var opacity = this.getOpacity(); var opacityPos = 0; diff --git a/test/test.py b/test/test.py index a6b01ec3d..d1e798d86 100644 --- a/test/test.py +++ b/test/test.py @@ -136,7 +136,7 @@ class PDFTestHandler(BaseHTTPRequestHandler): path, _ = url.path, url.query path = os.path.abspath(os.path.realpath(DOC_ROOT + os.sep + path)) prefix = os.path.commonprefix(( path, DOC_ROOT )) - _, ext = os.path.splitext(path) + _, ext = os.path.splitext(path.lower()) if url.path == "/favicon.ico": self.sendFile(os.path.join(DOC_ROOT, "test", "resources", "favicon.ico"), ext) From 8e407fe06dd7d57d5e379d14044ae21065528b69 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Sun, 28 Aug 2011 16:36:58 -0500 Subject: [PATCH 10/10] Adds cable.pdf link to tests --- test/pdfs/cable.pdf.link | 1 + test/test_manifest.json | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 test/pdfs/cable.pdf.link diff --git a/test/pdfs/cable.pdf.link b/test/pdfs/cable.pdf.link new file mode 100644 index 000000000..9cf92a5b8 --- /dev/null +++ b/test/pdfs/cable.pdf.link @@ -0,0 +1 @@ +http://www.wrapon.com/docs/PIPEHEATCABLE.PDF diff --git a/test/test_manifest.json b/test/test_manifest.json index 90a9f8a77..a83ca2fb1 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -97,5 +97,11 @@ "link": true, "rounds": 1, "type": "load" + }, + { "id": "cable", + "file": "pdfs/cable.pdf", + "link": true, + "rounds": 1, + "type": "eq" } ]