Conversation
9a6cc10 to
8d1f4a6
Compare
8d1f4a6 to
e1c597c
Compare
e1c597c to
f1d41e3
Compare
f1d41e3 to
019e30a
Compare
saecki
left a comment
There was a problem hiding this comment.
Thanks again for your work on gradients! This looks like some great improvements.
I agree with closing #5647 as expected behavior.
I think you're not part of the discord server, but since you're quite involved with gradients I'd be interested in your opinion regarding conic gradients. I've opened an issue just now to discuss the design: #7890
cf45a21 to
977c510
Compare
|
@saecki ready for 2nd review |
saecki
left a comment
There was a problem hiding this comment.
Thanks! And sorry for the delay (we had quite a busy week).
| Geometry::Line(_) | Geometry::Curve(_) => s.geometry.bbox(s.stroke.as_ref()), | ||
| // Special handling for fill of rectangles (mirrors gradients for negative sizes) | ||
| Geometry::Rect(_) => { | ||
| Rect::from_pos_size(Point::zero(), s.geometry.bbox_size()) |
There was a problem hiding this comment.
The documentation on Rect says that min is always smaller than max, and the from_pos_size function doesn't check that. Maybe this could return a Point and Size tuple for now, so that we don't misuse the documented API of Rect.
The same also applies to the code in typst-svg.
| Geometry::Line(_) | Geometry::Curve(_) => s.geometry.bbox(s.stroke.as_ref()), | ||
| // Special handling for fill of rectangles (mirrors gradients for negative sizes) | ||
| Geometry::Rect(_) => { | ||
| Rect::from_pos_size(Point::zero(), s.geometry.bbox_size()) |
There was a problem hiding this comment.
I've just noticed that by not passing the stroke, the bbox will be wrong for rectangles created by the typst_layout::shapes::simple_rect function such as:
#rect(
width: 100pt,
height: 100pt,
stroke: gradient.linear(green, black, yellow, angle: 90deg).sharp(8) + 20pt,
)The gradient is not spreading to the edge of the stroke (the weird clipping in the converted PDF is an issue that should be fixed in a newer hayro version)
report.html
So essentially the special handling for rectangles also has to check if the paint is converted for the stroke or the fill of the rectangle shape.
EDIT: It's probably desirable to have the same transform as the rect fill here, so let's just leave this as is 🤔
| bbox | ||
| }; | ||
|
|
||
| let bbox = shape.geometry.bbox(shape.stroke.as_ref()); |
There was a problem hiding this comment.
(This comment should go on line 44, but I can't add comments to lines not modified in this PR)
I've found another issue only present in typst-render for rectangles that don't have a radius. This is the issue-5705-gradient-border-stroke test without the radius:
#rect(
width: 100pt,
height: 100pt,
stroke: (
top: gradient.linear(green, black, yellow, angle: 90deg) + 20pt,
right: gradient.linear(green, black, yellow, angle: 180deg) + 20pt,
bottom: gradient.linear(green, black, yellow, angle: 270deg) + 20pt,
left: gradient.linear(green, black, yellow, angle: 0deg) + 20pt,
)
)
Fixes issues with gradient strokes for lines and curves:
curveelements don't use the correct bounding box when last segment iscurve.line#6068Tests added
Left / right shows before / after this PR. PDF screenshots are from Adobe Acrobat (report.html does not render them correctly with my firefox)
issue-6068-curve-stroke-gradient




PNG
SVG
PDF
issue-5705-gradient-border-stroke paged




PNG
SVG
PDF
In the test images below, each "star" consists of lines/curves at different angles, all using the same stroke gradient.
gradient-line-stroke




PNG
SVG
PDF
gradient-curve-stroke




PNG
SVG
PDF
gradient-curve-stroke-quad




PNG
SVG
PDF