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

shading-pattern: While drawing patterns, use transform to baseTransform first #6684

Merged
merged 1 commit into from
Dec 14, 2015
Merged

shading-pattern: While drawing patterns, use transform to baseTransform first #6684

merged 1 commit into from
Dec 14, 2015

Conversation

dsprenkels
Copy link
Contributor

I propose a fix for issue #6296.

I am, however, a bit uncertain about the implementation: maybe it would be better to alter the coordinates directly, instead of using ctx.save() and ctx.restore(). (Or maybe doing this in RadialAxialClosure).

@dsprenkels
Copy link
Contributor Author

This PR should be ready now. I'll squash the commits on request.

@dsprenkels dsprenkels changed the title shading-pattern: While drawing patterns, use owner.baseTransform shading-pattern: While drawing patterns, use transform to baseTransform first Nov 25, 2015
@@ -1839,7 +1839,7 @@
"link": false,
"type": "load",
"password": "\u00E6\u00F8\u00E5",
"about": "The password (���) is UTF8 encoded."
"about": "The password (���) is UTF8 encoded."

Choose a reason for hiding this comment

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

:-o

@dsprenkels
Copy link
Contributor Author

I have not yet looked into the following: I applied the change in CanvasGraphics.fill, but a similar change may be needed in CanvasGraphics.{stroke,shadingFill}, don't you think?

@timvandermeij
Copy link
Contributor

@dsprenkels Could you squash the commits? Looking at the diff in https://github.com/mozilla/pdf.js/pull/6684/files, I don't see how the owner argument is ever passed to getPattern. You have added it in the function header, but not in any calls. You might also need to handle owner being undefined.

@dsprenkels
Copy link
Contributor Author

I dabbled trying to revert the transformation, but as you say, I believe I have the "wrong" getPattern function. I think that, at the moment https://github.com/dsprenkels/pdf.js/commit/8a9480d893a5b0ba35f6102029c823ac57a81681 is the best fix.

I have seen, however, that this bug not only occurs in CanvasGraphics_fill, but also in CanvasGraphics_stroke. I would be preferable to fix this while we are at it, I believe. The point is, however, that if I use the method of using

ctx.save();
// (...)
var m = this.baseTransform;
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
// (...)

the stroke width is not correct anymore, (and I am not sure if other variables may be influenced as well).

The method I use in https://github.com/dsprenkels/pdf.js/commit/e5adbf62c37a964824b40fc52243acbd87eff05b is bad (but illustrates the idea of reverting the transformation done by the 0.1 0 0 0.1 0 0 cm instruction). If I could maybe get some guidance (perhaps via IRC) about where to implement a correction for the "current transformation", I'd be very happy. At the moment I feel like I'm just dabbling around. On the other hand, if you like, we could use the fix in https://github.com/dsprenkels/pdf.js/commit/8a9480d893a5b0ba35f6102029c823ac57a81681. The issue would be fixed, but the same problem would remain in CanvasGraphics_stroke.

@timvandermeij
Copy link
Contributor

This patch completely fixes #6296, #6486, #6293 (except for the last PDF which will become a separate issue) and #5436. It largely fixes #6298. Let's revert to the situation before the latest changes as that seems a reasonable way to fix this issue. Other methods can be updated in a follow-up patch, as it would be good to land this since it fixes a bunch of issues.

You can always contact us in IRC to discuss this patch.

@dsprenkels
Copy link
Contributor Author

@timvandermeij
I reverted to the state where I used the save()-restore() fix and squashed into one commit.

@@ -1089,6 +1089,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {

if (isPatternFill) {
ctx.save();
var m = this.baseTransform ||
this.ctx.mozCurrentTransform.slice();
ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
Copy link
Contributor

Choose a reason for hiding this comment

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

So this code just performs: if (this.baseTransform) { ctx.setTransform.apply(ctx, this.baseTransform); }? (Now I wonder if we ever will get this.baseTransform == null.)

I don't think you need to perform this.ctx.mozCurrentTransform and its slicing -- it will just create unneeded objects.

Shall stroke have the same statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this code just performs: if (this.baseTransform) { ctx.setTransform.apply(ctx, this.baseTransform); }? (Now I wonder if we ever will get this.baseTransform == null.)

I initially just used this.baseTransform, got null in some test cases from the test suite, and saw that in other places the expression this.baseTransform || this.ctx.mozCurrentTransform.slice(); was used. I did not know that the current tranformation was actually stored in this.ctx.mozCurrentTransform, (although now it makes a lot of sense).
You are right that this piece of code could better be if (this.baseTransform) { ctx.setTransform.apply(ctx, this.baseTransform); }.

Shall stroke have the same statements?

I some manner of speaking: "Yes". However, when transforming the stroke, the stroke width would be transformed as well. I do not know if other side effects occur when using ctx.setTransform(), that's why I initially thought that it may be a better idea to not use ctx.save() and ctx.restore(), but to alter the matrices of the patterns directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

the stroke width would be transformed as well

IMHO if it needs to be done, then we shall do it.

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/20102b3966f74cd/output.txt

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/57736848603eae8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/bb7ed3406c1e2d8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/bb7ed3406c1e2d8/output.txt

Total script time: 20.22 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/57736848603eae8/output.txt

Total script time: 20.27 mins

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

@timvandermeij
Copy link
Contributor

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/f119b893fd27fd1/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/f2b78b29f43227d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/f119b893fd27fd1/output.txt

Total script time: 19.33 mins

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/f2b78b29f43227d/output.txt

Total script time: 19.64 mins

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

timvandermeij added a commit that referenced this pull request Dec 14, 2015
shading-pattern: While drawing patterns, use transform to baseTransform first
@timvandermeij timvandermeij merged commit f93a220 into mozilla:master Dec 14, 2015
@timvandermeij
Copy link
Contributor

Thank you for the fix!

@dsprenkels dsprenkels deleted the issue-6296-radial-shading-size branch December 14, 2015 22:03
@Snuffleupagus
Copy link
Collaborator

@Snuffleupagus
Copy link
Collaborator

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.

6 participants