fix(engine): turn a shape's gradient stroke with the canvas (#9239) (#9240)

Image Rotation, rotated Crop, canvas flips and Image Size mapped a shape
layer's gradient fill through map_fill but never its stroke paint, so a
gradient stroke kept its old angle and offset while the fill turned.

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 authored and GitHub committed 2026-10-25 10:17:44 -04:00
1 parent 6f1705a32b
commit 100ff983f5
2 files changed
+35

No files matched your search

+3
View File
@@ -137,6 +137,9 @@ pub(crate) fn transform_layer_geometry(l: &mut Layer, a: &Affine, content: bool,
if let Some(f) = &mut sh.fill {
map_fill(a, f);
}
if let Some(st) = &mut sh.stroke {
map_fill(a, &mut st.paint);
}
if content {
crate::vector_cmds::transform_shape(sh, a);
}
+32
View File
@@ -221,6 +221,38 @@ fn gradient_fill_offset_stays_a_fraction_of_the_frame() {
assert!((offset.0 - 0.1).abs() < 1e-6 && (offset.1 - 0.25).abs() < 1e-6, "{offset:?}");
}
/// The shape's (fill, stroke) gradient angles after `cmd` on a shape whose fill and stroke both
/// start as a 0° (left to right) gradient.
fn shape_gradient_angles_after(cmd: &str, p: serde_json::Value) -> (f32, f32) {
let mut s = Session::new();
s.execute("file.new", json!({"width": W, "height": H})).unwrap();
let g = json!({"gradient": {"stops": [[0, "#ff0000"], [1, "#0000ff"]], "angle": 0}});
s.execute("shape.create", json!({"kind": "rect", "rect": [10, 8, 30, 20], "fill": g, "stroke": {"width": 6, "fill": g}})).unwrap();
s.execute(cmd, p).unwrap();
let angle = |f: &Fill| if let Fill::Gradient { angle, .. } = f { *angle } else { panic!("not a gradient: {f:?}") };
let sh = doc(&s).walk().into_iter().find_map(|(_, _, l)| if let LayerContent::Shape(sh) = &l.content { Some(sh.clone()) } else { None }).unwrap();
(angle(sh.fill.as_ref().unwrap()), angle(&sh.stroke.as_ref().unwrap().paint))
}
/// A gradient stroke turns and mirrors with the canvas like the fill does (#9239).
#[test]
fn shape_gradient_stroke_turns_with_the_canvas() {
let same = |a: f32, b: f32| {
let d = (a - b).rem_euclid(360.0);
d < 1e-3 || d > 360.0 - 1e-3
};
for (cmd, p, want) in [
("image.imageRotation.90cw", json!({}), -90.0),
("image.imageRotation.flipCanvasHorizontal", json!({}), 180.0),
("image.imageRotation.flipCanvasVertical", json!({}), 0.0),
("image.rotation.arbitrary", json!({"angle": 30, "direction": "cw"}), -30.0),
] {
let (fill, stroke) = shape_gradient_angles_after(cmd, p);
assert!(same(fill, want), "{cmd}: fill {fill}, want {want}");
assert!(same(stroke, want), "{cmd}: stroke {stroke}, want {want}");
}
}
fn type_and_shape_origin(d: &Document) -> ([f64; 6], [f64; 2]) {
let mut t = None;
let mut k = None;