linebender / piet

An abstraction for 2D graphics.
Apache License 2.0
1.25k stars 94 forks source link

Support individual corner radii for kurbo::RoundedRect #391

Closed SecondFlight closed 3 years ago

SecondFlight commented 3 years ago

image

This PR adds support for this Kurbo patch. This PR points directly at my Kurbo fork, so it probably shouldn't be merged until the Kurbo PR is merged and a new Kurbo version is published.

piet-coregraphics and piet-cairo both get this feature for free, because both platforms use paths for rounded rectangles. I have tested both platforms and verified this.

piet-web should get this feature for free as well, for the same reason. I have not explicitly tested this, but I feel confident about it since to_path is well-tested and is not platform-specific, and RoundedRect is not mentioned in the code.

In piet-svg, this has been implemented by simply using a bezier curve if the corner radii aren't all equal, and a rounded rectangle if they are. Rounded rectangles in SVG can only have a single radius, and while it's possible to use some clipping magic, I don't think it's worth the effort.

In piet-direct2d, this has been implemented by drawing four rounded rectangles, one for each corner. They are clipped using an axis-aligned clip, which is faster than masking with a shape. If all corner radii are equal, a single rounded rectangle is drawn.

piet-direct2d has a similar implementation to piet-svg.

cmyr commented 3 years ago

Will give this a look through shortly, and will do a release when we land this + #389 (and maybe #387?)

raphlinus commented 3 years ago

Will give this a look through shortly, and will do a release when we land this + #389 (and maybe #387?)

I'd love to see #389 go in, though I consider it pretty high risk. I don't think #387 is ready, as there are serious unresolved questions in the Direct2D port in particular (and those are not just implementation details, but point to deeper architectural concerns imho).

SecondFlight commented 3 years ago

The most recent commit addresses a major oversight when rendering in Direct2D. See the top-middle here: image

versus here: d2d-test-6

Sample image 6 has also been updated. I'll have a PR for piet-snapshots shortly.

SecondFlight commented 3 years ago

Okay, I'll update this soon. I was really hoping for a better way to do that, because my version feels really clunky.

SecondFlight commented 3 years ago

That was just sloppy, sorry. I forgot that building and testing piet doesn't build or test piet-direct2d or etc.

Now the snapshots are still failing. Not sure what's going on, since they're freshly updated. I'll poke at this more when I get time next, but that may be a couple days.