From a17b13019b17f71a55c47e829dbbc59b815eb158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20G=2E=20Stan?= Date: Thu, 27 Oct 2011 02:47:18 +0300 Subject: [PATCH 1/6] Fix strict mode syntax error in Safari This happens in Safari 5.1 and Mobile Safari on iOS 5. Apparently, Safari considers the function name as part of the ECMA's FormalParameterList and applies the strict mode rules from section 13.1 of the specification. > It is a SyntaxError if any Identifier value occurs more than once > within a FormalParameterList of a strict mode > FunctionDeclaration or FunctionExpression. --- pdf.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pdf.js b/pdf.js index f45993210..05a21538d 100644 --- a/pdf.js +++ b/pdf.js @@ -7522,19 +7522,19 @@ var Promise = (function() { Promise.prototype = { hasData: false, - set data(data) { - if (data === undefined) { + set data(value) { + if (value === undefined) { return; } if (this._data !== EMPTY_PROMISE) { throw 'Promise ' + this.name + ': Cannot set the data of a promise twice'; } - this._data = data; + this._data = value; this.hasData = true; if (this.onDataCallback) { - this.onDataCallback(data); + this.onDataCallback(value); } }, From 56b9a3543dfd365fb065a85ac056d29064c72797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20G=2E=20Stan?= Date: Thu, 27 Oct 2011 03:08:11 +0300 Subject: [PATCH 2/6] Close path in `closeFillStroke` and `closeEOFillStroke` See Chapter 4, page 230, Table 4.10 of the PDF specification. --- pdf.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pdf.js b/pdf.js index 05a21538d..43df4a168 100644 --- a/pdf.js +++ b/pdf.js @@ -5643,10 +5643,12 @@ var CanvasGraphics = (function canvasGraphics() { this.restoreFillRule(savedFillRule); }, closeFillStroke: function canvasGraphicsCloseFillStroke() { - return this.fillStroke(); + this.closePath(); + this.fillStroke(); }, closeEOFillStroke: function canvasGraphicsCloseEOFillStroke() { var savedFillRule = this.setEOFillRule(); + this.closePath(); this.fillStroke(); this.restoreFillRule(savedFillRule); }, From 0c321466dce4377f58a038515260c66a0f74603b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20G=2E=20Stan?= Date: Thu, 27 Oct 2011 05:45:10 +0300 Subject: [PATCH 3/6] Set DeviceGray as initial value for color space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See the PDF reference, section 4.3 Graphics State, table 4.2, third row. > The current color space in which color values are to be interpreted > (see Section 4.5, “Color Spaces”). There are two separate color space > parameters: one for stroking and one for all other painting opera- > tions. Initial value: DeviceGray. The problem before was that certain PDFs didn't explicitly set the color space, so a call to `setFillColor` or `setStrokeColor` were failing when the `getRgb` method was call, as the color space was null. See source code of CanvasGraphics.prototype.setFillColor/setStrokeColor. --- pdf.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pdf.js b/pdf.js index 43df4a168..cb3ca3dc5 100644 --- a/pdf.js +++ b/pdf.js @@ -5344,6 +5344,9 @@ var CanvasExtraState = (function canvasExtraState() { this.strokeColor = '#000000'; this.old = old; + + this.fillColorSpace = new DeviceGrayCS; + this.strokeColorSpace = new DeviceGrayCS; } constructor.prototype = { From 009d6a8863fae350c8b95f1a6f0936f7b3fbf12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20G=2E=20Stan?= Date: Fri, 28 Oct 2011 14:27:41 +0300 Subject: [PATCH 4/6] Log error stacktrace only when available Safari does not provide a `stack` property on Error instances. --- pdf.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pdf.js b/pdf.js index cb3ca3dc5..4a8b9a091 100644 --- a/pdf.js +++ b/pdf.js @@ -22,16 +22,15 @@ function warn(msg) { } function backtrace() { - var stackStr; try { throw new Error(); } catch (e) { - stackStr = e.stack; + return e.stack ? e.stack.split('\n').slice(2).join('\n') : ""; } - return stackStr.split('\n').slice(1).join('\n'); } function error(msg) { + log("Error: " + msg); log(backtrace()); throw new Error(msg); } From 8a6cf185fd71ea6132bc305ac8282141aab86914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20G=2E=20Stan?= Date: Fri, 28 Oct 2011 16:38:55 +0300 Subject: [PATCH 5/6] Add eq test for close path rendering bug See: 56b9a3543dfd365fb065a85ac056d29064c72797 --- test/pdfs/.gitignore | 2 +- test/pdfs/close-path-bug.pdf | 69 ++++++++++++++++++++++++++++++++++++ test/test_manifest.json | 5 +++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/pdfs/close-path-bug.pdf diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index e7eb0da43..49267e36f 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -12,4 +12,4 @@ !rotation.pdf !simpletype3font.pdf !sizes.pdf - +!close-path-bug.pdf diff --git a/test/pdfs/close-path-bug.pdf b/test/pdfs/close-path-bug.pdf new file mode 100644 index 000000000..994d4e572 --- /dev/null +++ b/test/pdfs/close-path-bug.pdf @@ -0,0 +1,69 @@ +%PDF-1.4 +1 0 obj + <> +endobj + +2 0 obj + <> +endobj + +3 0 obj + <> +endobj + +4 0 obj + <>>> +endobj + +5 0 obj + << /Length 885 >> +stream + % Draw a black line segment, using the default line width. + 150 250 m + 150 350 l + S + + % Draw a thicker, dashed line segment. + 4 w % Set line width to 4 points + [4 6] 0 d % Set dash pattern to 4 units on, 6 units off + 150 250 m + 400 250 l + S + + [] 0 d % Reset dash pattern to a solid line + 1 w % Reset line width to 1 unit + + % Draw a rectangle with a 1−unit red border, filled with light blue. + 1.0 0.0 0.0 RG % Red for stroke color + 0.5 0.75 1.0 rg % Light blue for fill color + 200 300 50 75 re + B + + % Draw a curve filled with gray and with a colored border. + 0.5 0.1 0.2 RG + 0.7 g + 300 300 m + 300 400 400 400 400 300 c + b +endstream +endobj + +6 0 obj + [/PDF] +endobj + +xref +0 7 +0000000000 65535 f +0000000009 00000 n +0000000074 00000 n +0000000120 00000 n +0000000179 00000 n +0000000300 00000 n +0000001532 00000 n + +trailer + <> +startxref +1556 +%%EOF diff --git a/test/test_manifest.json b/test/test_manifest.json index d7ac34cef..4837dd2b7 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -217,5 +217,10 @@ "link": false, "rounds": 1, "type": "eq" + }, + { "id": "close-path-bug", + "file": "pdfs/close-path-bug.pdf", + "rounds": 1, + "type": "eq" } ] From 56789aea47efa22912034d4f337f14b23be23699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20G=2E=20Stan?= Date: Sat, 29 Oct 2011 01:26:55 +0300 Subject: [PATCH 6/6] Fix lint errors Single quotes instead of double quotes --- src/util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util.js b/src/util.js index 953732057..9765914ca 100644 --- a/src/util.js +++ b/src/util.js @@ -19,12 +19,12 @@ function backtrace() { try { throw new Error(); } catch (e) { - return e.stack ? e.stack.split('\n').slice(2).join('\n') : ""; + return e.stack ? e.stack.split('\n').slice(2).join('\n') : ''; } } function error(msg) { - log("Error: " + msg); + log('Error: ' + msg); log(backtrace()); throw new Error(msg); }