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

Move svg:clipPath generation from clip to endPath #8542

Merged
merged 1 commit into from
Jun 22, 2017

Conversation

Rob--W
Copy link
Member

@Rob--W Rob--W commented Jun 19, 2017

See the commit message for a detailed explanation.

I think that we also need to check whether it is necessary to add more .endPath calls to src/display/svg.js, similar to the many consumePath calls in src/display/canvas.js. However I don't understand that part of the code well enough to tell whether it's needed.

Fixes #8527
Seems to improve #8496 (#8496 (comment))

@Rob--W Rob--W added the 4-svg label Jun 19, 2017
@Rob--W Rob--W requested a review from timvandermeij June 19, 2017 11:34
@Rob--W
Copy link
Member Author

Rob--W commented Jun 19, 2017

/botio test

@@ -264,6 +264,7 @@ var SVGExtraState = (function SVGExtraStateClosure() {
this.dependencies = [];

// Clipping
this.pendingClip = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not look like you store the pending clip in the SVGExtraState object (but instead as a property of SVGGraphics), so I think this should be moved to above https://github.com/mozilla/pdf.js/pull/8542/files?w=1#diff-84f753e2bb39669e059ce3447e5a0057R365, just like in canvas.js.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, fixed.

@@ -894,36 +896,41 @@ SVGGraphics = (function SVGGraphicsClosure() {
current.setCurrentPoint(x, y);
},

endPath: function SVGGraphics_endPath() {},
endPath: function SVGGraphics_endPath() {
if (this.pendingClip) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use this instead:

if (!this.pendingClip) {
  return;
}

That way we avoid a level of indenting, which improves readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done too.

In the PDF from issue 8527, the clip operator (W) shows up before a path
is defined. The current SVG backend however expects a path to exist
before generating a `<svg:clipPath>` element.
In the example, the path was defined after the clip, followed by a
endPath operator (n).
So this commit fixes the bug by moving the path generation logic from
clip to endPath.

Our canvas backend appears to use similar logic:
`CanvasGraphics_endPath` calls `consumePath`, which in turn draws the
clip and resets the `pendingClip` state. The canvas backend calls
`consumePath` from multiple other places, so we probably need to check
whether doing so is also necessary for the SVG backend.

I scanned our corpus of PDF files in test/pdfs, and found that in every
instance (except for one), the "W" PDF operator (clip) is immediately
followed by "n" (endPath). The new test from this commit (clippath.pdf)
starts with "W", followed by a path definition and then "n".

    # Commands used to find some of the clipping commands:
    grep -ra '^W$' -C7 | less -S
    grep -ra '^W ' -C7 | less -S
    grep -ra ' W$' -C7 | less -S

test/pdfs/issue6413.pdf is the only file where "W" (a tline 55) is not
followed by "n". In fact, the "W" is the last operation of a series of
XObject painting operations, and removing it does not have any effect
on the rendered PDF (confirmed by looking at the output of PDF.js's
canvas backend, and ImageMagick's convert command).
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

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

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

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

Total script time: 2.32 mins

Published

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/2f854761658bdca/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

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

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/2f854761658bdca/output.txt

Total script time: 16.50 mins

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

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

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

Total script time: 30.21 mins

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

@mozilla mozilla deleted a comment from pdfjsbot Jun 22, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jun 22, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jun 22, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jun 22, 2017
@timvandermeij
Copy link
Contributor

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

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

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

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

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

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

Total script time: 15.45 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/a7cd634efb6bae3/output.txt

Total script time: 28.77 mins

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

@timvandermeij timvandermeij merged commit c6ee05f into mozilla:master Jun 22, 2017
@timvandermeij
Copy link
Contributor

timvandermeij commented Jun 22, 2017

Thank you for fixing this! It's good that the canvas and SVG back-end are more similar now.

movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Move svg:clipPath generation from clip to endPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants