Skip to content
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

Fix color of image masks inside uncolored patterns #8808

Merged
merged 1 commit into from
Sep 12, 2017

Conversation

janpe2
Copy link
Contributor

@janpe2 janpe2 commented Aug 22, 2017

Fixes #8741
Fixes #3226
Fixes #8860

This is a patch for uncolored (/PaintType 2) tiling patterns that contain image masks. When uncolored patterns are used as a fill or stroke, the operator scn or SCN specifies the color of the pattern. If the pattern contains an image mask, PDF.js incorrectly draws it using black instead of the color specified by scn or SCN.

In my patch, I assign the proper color to the fillColor property of the CanvasExtraState object. That property is used as the color of image masks in functions paintImageMaskXObject...() in canvas.js.

@@ -360,7 +360,7 @@ var TilingPattern = (function TilingPatternClosure() {
var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
graphics.groupLevel = owner.groupLevel;

this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color, graphics);
Copy link
Contributor

Choose a reason for hiding this comment

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

let's change signature to setFillAndStrokeStyleToGraphics(graphic, paintType, color) -- context is accessible via graphics.ctx.

@@ -412,6 +413,8 @@ var TilingPattern = (function TilingPatternClosure() {
var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
context.fillStyle = cssColor;
context.strokeStyle = cssColor;
// Set color needed by image masks (fixes issues 3226 and 8741).
graphics.current.fillColor = cssColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to do that for this.current.strokeColor =? do we need to do the same for PaintType.COLORED case?

@janpe2
Copy link
Contributor Author

janpe2 commented Aug 29, 2017

do we need to do that for this.current.strokeColor =?

I don't know if any PDF would need this but I added it, just to be sure.

do we need to do the same for PaintType.COLORED case?

I added lines similar to the other case. Colored tiling patterns are a bit different: now the color argument in setFillAndStrokeStyleToContext() is meaningless (or null) because the PDF operators scn and SCN have no color operands.

@timvandermeij
Copy link
Contributor

/botio-linux preview

@timvandermeij
Copy link
Contributor

/botio test

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Aug 30, 2017

Fixes #8741, #3226.

Would it be possible to include the PDF file from either of those issues as a linked eq test-case, to prevent future regressions?

@janpe2
Copy link
Contributor Author

janpe2 commented Sep 5, 2017

I added the test case.

By the way, my patch seems to fix also issue #8860.

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Sep 5, 2017

I added the test case.

Thank you; one question though, wouldn't it be enough to just test the first page of the document?
If so, please add "lastPage": 1, new test entry in test_manifest.json.

@Snuffleupagus
Copy link
Collaborator

/botio test

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Sep 5, 2017

@janpe2 Looking at the test logs above, it appears that the server prevented the PDF file from being downloaded:

Downloading http://arxiv.org/pdf/0705.4298.pdf to pdfs/issue3226.pdf...
Error during downloading of http://arxiv.org/pdf/0705.4298.pdf: HTTP 403
WARNING: File was not downloaded. See "pdfs/issue3226.pdf.error" file.
Unable to verify the checksum for the files that are used for testing.
Please re-download the files, or adjust the MD5 checksum in the manifest for the files listed above.

Would it be possible to link to the PDF file through e.g. https://archive.org/web/ instead, or do we need to use another PDF file for the test-case?

Edit: This prevents the new test-case from actually running, with messages such as:

TEST-SKIPPED | PDF was not downloaded issue3226 | in firefox | page1 round 1 | Loading PDF document: UnknownErrorException: PDFDocument: stream must have data
...
TEST-SKIPPED | PDF was not downloaded issue3226 | in chrome | page1 round 1 | Loading PDF document: UnknownErrorException: PDFDocument: stream must have data

@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 5, 2017
@timvandermeij
Copy link
Contributor

/botio test

@janpe2
Copy link
Contributor Author

janpe2 commented Sep 5, 2017

What are those failed regression tests? Should I be worried about them?

@timvandermeij
Copy link
Contributor

timvandermeij commented Sep 5, 2017

The problem is that the old file is not replaced. @yurydelendik Could you remove the old (cached) issue3226.pdf file from both bots so we can try again?

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Sep 6, 2017

The problem is that the old file is not replaced. @yurydelendik Could you remove the old (cached) issue3226.pdf file from both bots so we can try again?

I don't think that's going to help much, since the (Internet Archive) link does not actually point to a PDF file.
If you open https://web.archive.org/web/20170830175223/http://arxiv.org/pdf/0705.4298.pdf directly in a browser, you'll get the same thing that the test-suite gets when downloading the file: a HTML page which references a PDF file.

It seems to me that linking to this particular PDF file will probably not work, and that the easiest solution here would be to try and use a PDF file from one of the other referenced issues as a test-case instead.

@mozilla mozilla deleted a comment from pdfjsbot Sep 6, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 6, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 6, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 6, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 11, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 11, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 11, 2017
@mozilla mozilla deleted a comment from pdfjsbot Sep 11, 2017
@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/d3ecbe51f41b9e9/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.215.176.217:8877/6b875cc3ee3d9bb/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/d3ecbe51f41b9e9/output.txt

Total script time: 16.55 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.215.176.217:8877/6b875cc3ee3d9bb/output.txt

Total script time: 29.73 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.215.176.217:8877/6b875cc3ee3d9bb/reftest-analyzer.html#web=eq.log

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for the patch!

@Snuffleupagus Snuffleupagus removed the request for review from yurydelendik September 12, 2017 11:27
@Snuffleupagus
Copy link
Collaborator

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/c5a69837639ea9f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.215.176.217:8877/ebe8b13be2ac83a/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/c5a69837639ea9f/output.txt

Total script time: 15.65 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/ebe8b13be2ac83a/output.txt

Total script time: 28.13 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@Snuffleupagus Snuffleupagus merged commit f2618eb into mozilla:master Sep 12, 2017
@janpe2 janpe2 deleted the issue8741 branch December 19, 2017 19:36
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Fix color of image masks inside uncolored patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants