Skip to content

Introduce paintSolidColorImageMask command to handle 1x1 solid image #4474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}
},

paintSolidColorImageMask:
function CanvasGraphics_paintSolidColorImageMask() {
this.ctx.fillRect(0, 0, 1, 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line causes rendering problems on Firefox (v. 32, Ubuntu 14.04):

screenshot from 2014-10-06 14 21 14

If I change it to:

this.ctx.fillStyle = 'transparent';
this.ctx.fillRect(0, 0, 1, 1);

the problem with the black boxes is solved, but that would defeat the purpose of this commit. Any suggestions here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's defect in Firefox 32 for Linux only. See https://bugzilla.mozilla.org/show_bug.cgi?id=1050788

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldnt we eliminate the rendering of transparent items at all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodingFabian, color is set to black so it's not transparent. See source code of the minimal test case https://bug1050788.bugzilla.mozilla.org/attachment.cgi?id=8470100 that demonstrates issue with Firefox 32 for Linux.

},

// Marked content

markPoint: function CanvasGraphics_markPoint(tag) {
Expand Down
3 changes: 2 additions & 1 deletion src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/pdfs/issue4436.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
http://arxiv.org/pdf/1203.6597v3.pdf

9 changes: 9 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]