Skip to content

canvas: Scale stroke width based on shape transform#7042

Merged
Herschel merged 3 commits into
ruffle-rs:masterfrom
Herschel:canvas-strokes
Jul 19, 2022
Merged

canvas: Scale stroke width based on shape transform#7042
Herschel merged 3 commits into
ruffle-rs:masterfrom
Herschel:canvas-strokes

Conversation

@Herschel
Copy link
Copy Markdown
Member

@Herschel Herschel commented May 21, 2022

Render strokes with the proper width in the canvas backend:

  • Stroke width gets scaled based on the shape's transform and line style scaling settings
  • Minimum 1 pixel width (1 twip hairline strokes get scaled to 1 pixel)

TODO:

  • Move the line scale calculation to core::shape_utils because other renderers will want it as well
  • Handle complex fill styles in strokes (need to create a fresh CanvasGradient instance per draw)
  • Only calculate line scales if necessary (slight optimization)

Fixes the line widths in #751 in the canvas backend.

@Herschel Herschel marked this pull request as draft May 21, 2022 06:37
@Toad06
Copy link
Copy Markdown
Member

Toad06 commented May 23, 2022

This is also greatly improving the Steppenwolf games. 👍

Master:
s3_b

This PR (matches Flash):
s3_g

@Herschel Herschel force-pushed the canvas-strokes branch 2 times, most recently from c4c0082 to f53fc57 Compare July 19, 2022 00:56
@Herschel Herschel marked this pull request as ready for review July 19, 2022 02:56
@Herschel
Copy link
Copy Markdown
Member Author

Herschel commented Jul 19, 2022

@Toad06 Could you give this another test? Thank you!

Unfortunately with the canvas API, there's no good way to handle gradient strokes -- the trick that I use for gradient fills can't be applied to strokes, because transforms end up distorting the stroke geometry (joins/endcaps). So this PR takes the middle ground of creating a fresh gradient each frame for strokes, with a "simple" transform (rotation/scale, no skew), which should be good enough in the majority of cases.

@Herschel Herschel changed the title [wip] canvas: Scale stroke width based on shape transform canvas: Scale stroke width based on shape transform Jul 19, 2022
@Toad06
Copy link
Copy Markdown
Member

Toad06 commented Jul 19, 2022

This looks good to me, this is really a significant improvement. 😉

(By the way, while testing I did notice a couple of regressions affecting the canvas renderer. They are not related to this PR. I reported them in #7448 before realizing this was an issue you were aware of already 😛)

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.

2 participants