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

Implement fill opacity for shading patterns in the SVG back-end #11927

Merged

Conversation

timvandermeij
Copy link
Contributor

@timvandermeij timvandermeij commented May 24, 2020

In the PDF file from the issue below, the fill alpha (ca) is set before drawing the circles using the setGState operator. Doing so causes the global alpha to be set on the canvas' context for the canvas back-end, but this was not handled in the SVG back-end. This patch fixes that by taking the fill opacity into account when drawing shading patterns in the same way as done elsewhere so it is only included if the value is non-default.

Fixes #11812.

@timvandermeij
Copy link
Contributor Author

You can test this by opening the preview viewer below and running PDFViewerApplication.preferences.set('renderer', 'svg'); in the console. If you refresh the page and open the file from the issue, you'll see three circles with different opacities now.

@timvandermeij
Copy link
Contributor Author

/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/9cde8c7afef8b6a/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/9cde8c7afef8b6a/output.txt

Total script time: 3.27 mins

Published

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 to me, thanks!

Super tiny nit: Shouldn't it be ca, i.e. lower-case, in the commit message since the upper-case variant is stroke-related based on e.g.

pdf.js/src/display/canvas.js

Lines 1005 to 1011 in 3b615e4

case "CA":
this.current.strokeAlpha = state[1];
break;
case "ca":
this.current.fillAlpha = state[1];
this.ctx.globalAlpha = state[1];
break;

This confused me for a second when reading the commit message, before looking at the actual code.

In the PDF file from the issue below, the fill alpha (`ca`) is set
before drawing the circles using the `setGState` operator. Doing so
causes the global alpha to be set on the canvas' context for the canvas
back-end, but this was not handled in the SVG back-end. This patch fixes
that by taking the fill opacity into account when drawing shading
patterns in the same way as done elsewhere so it is only included if the
value is non-default.

Fixes mozilla#11812.
@timvandermeij
Copy link
Contributor Author

Good point; I have amended the commit and PR message. Thanks!

@timvandermeij timvandermeij merged commit 9d38dd4 into mozilla:master May 24, 2020
@timvandermeij timvandermeij deleted the svg-fill-opacity-shading branch May 24, 2020 12:29
@Snuffleupagus
Copy link
Collaborator

Good point; I have amended the commit and PR message.

Thank you; as an aside you do have to wonder why anyone thought it'd be a good idea to specify two separate operators with the same name and differing only in their casing...

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.

Rendering PDF which include shapes who have opacity (SVG renderer)
3 participants