From fc9edfcf76d0efe0cd5630c93dcd4021c1cefa2e Mon Sep 17 00:00:00 2001 From: Christian Krebs Date: Sun, 16 Mar 2014 16:17:13 +0100 Subject: [PATCH 1/2] Introduce paintSolidColorImageMask command to handle 1x1 solid image masks See https://github.com/mozilla/pdf.js/issues/4436 for details --- src/core/evaluator.js | 20 ++++++++++++++++++++ src/display/canvas.js | 5 +++++ src/shared/util.js | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 226532187..23baf0b6f 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -1699,6 +1699,25 @@ var QueueOptimizer = (function QueueOptimizerClosure() { state[pattern[pattern.length - 1]] = fn; } + function handlePaintSolidColorImageMask(index, count, fnArray, argsArray) { + // Handles special case of mainly latex documents which + // use image masks to draw lines with the current fill style. + // 'count' groups of (save, transform, paintImageMaskXObject, restore)+ + // have been found at index. + for (var i = 0; i < count; i++) { + var arg = argsArray[index + 4 * i + 2]; + var imageMask = arg.length == 1 && arg[0]; + if (imageMask && imageMask.width == 1 && imageMask.height == 1 && + (!imageMask.data.length || (imageMask.data.length == 1 && + imageMask.data[0] === 0))) { + fnArray[index + 4 * i + 2] = OPS.paintSolidColorImageMask; + continue; + } + break; + } + return count - i; + } + var InitialState = []; addState(InitialState, @@ -1802,6 +1821,7 @@ var QueueOptimizer = (function QueueOptimizerClosure() { for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) { } var count = (i - j) >> 2; + count = handlePaintSolidColorImageMask(j, count, fnArray, argsArray); if (count < MIN_IMAGES_IN_MASKS_BLOCK) { context.currentOperation = i - 1; return; diff --git a/src/display/canvas.js b/src/display/canvas.js index ddcf3da18..6d60a7d7e 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -2128,6 +2128,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } }, + paintSolidColorImageMask: + function CanvasGraphics_paintSolidColorImageMask() { + this.ctx.fillRect(0, 0, 1, 1); + }, + // Marked content markPoint: function CanvasGraphics_markPoint(tag) { diff --git a/src/shared/util.js b/src/shared/util.js index 4803e6daf..c645d5838 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -151,7 +151,8 @@ var OPS = PDFJS.OPS = { paintInlineImageXObject: 86, paintInlineImageXObjectGroup: 87, paintImageXObjectRepeat: 88, - paintImageMaskXObjectRepeat: 89 + paintImageMaskXObjectRepeat: 89, + paintSolidColorImageMask: 90, }; // A notice for devs. These are good for things that are helpful to devs, such From 543117dd0e01a989084c5a477ac7326990756281 Mon Sep 17 00:00:00 2001 From: Christian Krebs Date: Wed, 19 Mar 2014 13:25:46 +0100 Subject: [PATCH 2/2] Added TC for issue 4436 --- test/pdfs/issue4436.pdf.link | 2 ++ test/test_manifest.json | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 test/pdfs/issue4436.pdf.link diff --git a/test/pdfs/issue4436.pdf.link b/test/pdfs/issue4436.pdf.link new file mode 100644 index 000000000..fc066e121 --- /dev/null +++ b/test/pdfs/issue4436.pdf.link @@ -0,0 +1,2 @@ +http://arxiv.org/pdf/1203.6597v3.pdf + diff --git a/test/test_manifest.json b/test/test_manifest.json index 70d93e241..27a6ac408 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1568,5 +1568,14 @@ "rounds": 1, "type": "eq", "about": "Image mask in higher resolution than the image itself" + }, + { "id": "issue4436", + "file": "pdfs/issue4436.pdf", + "md5": "34e6af7441961f5940e6440a62e37427", + "rounds": 1, + "link": true, + "firstPage": 9, + "lastPage": 9, + "type": "eq" } ]