mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 04:58:11 +00:00
Effects: placed gradients move with Transform and Free Distort effects
A gradient placed with the Gradient tool stayed where it was when the object's Transform or Free Distort effect moved, turned or scaled the outline, so the shape slid across its own gradient. The Transform effect now maps placed gradients by its own transform, and each of its copies takes them as many times as it takes the transform. Under Free Distort, each path's placed gradients move and scale from the path's bounds before the effect to its bounds after it. This change does not alter gradients fitted to the object. The canvas, Expand Appearance and export, Pathfinder and compound shapes, groups, a fill's or stroke's own effects, and Object › Expand of a gradient fill apply the same rule. In a group, the own fills and strokes of the group, of the groups inside it and of a symbol's art follow it too, and images and symbol instances that a group's Transform effect moves take the placed gradients of their own fills and strokes along. A group whose path keeps its shape because the effect would pass the geometry budget keeps its own gradients in place. This changes how existing documents draw: a gradient placed on a path, or on an image's or symbol instance's own fill, inside a group with a Transform effect now moves with it. Before, only the gradients of type moved (#2214). How gradients follow each effect is VectorCraft's own rule. The Distort & Transform help page describes what the effects do to the object: https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/distort-and-transform-effects-in-illustrator.html
This commit is contained in:
@@ -133,6 +133,37 @@ fn white_black() -> Value {
|
||||
json!({"kind": "linear", "stops": [{"offset": 0, "color": "#ffffff"}, {"offset": 1, "color": "#000000"}]})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_placed_gradient_moved_by_a_transform_or_free_distort_expands_as_the_canvas_draws_it() {
|
||||
// The object's own effect, and the fill's (the first appearance item).
|
||||
let slant = json!({"corners": [[0.25, 0.0], [1.25, 0.0], [1.0, 1.0], [0.0, 1.0]]});
|
||||
for (effect, params, item) in [
|
||||
("distort.transform", json!({"rotate": 90}), json!(null)),
|
||||
("distort.transform", json!({"rotate": 30, "scaleH": 60}), json!(null)),
|
||||
("distort.transform", json!({"rotate": 90}), json!(0)),
|
||||
("distort.freeDistort", slant.clone(), json!(null)),
|
||||
("distort.freeDistort", slant, json!(0)),
|
||||
] {
|
||||
let mut s = session();
|
||||
let id = gradient_rect(&mut s, Rect::new(40.0, 70.0, 160.0, 130.0), white_black(), false);
|
||||
// Placed from a quarter of the way across to the right edge.
|
||||
run(&mut s, "paint.setGradientGeom", json!({"start": [70, 100], "end": [160, 100], "stroke": false}));
|
||||
let placed = s.doc().unwrap().doc.node(id).and_then(|n| match n.appearance.fill_paint() {
|
||||
vectorcraft_color::Paint::Gradient(g) => g.geom,
|
||||
_ => None,
|
||||
});
|
||||
assert!(placed.is_some(), "the fill's gradient is placed");
|
||||
run(&mut s, "effect.apply", json!({"effect": effect, "params": params, "ids": [id.0], "item": item}));
|
||||
let before = render(&s);
|
||||
// Fill alone: the gradient becomes strips inside the outline the effect makes.
|
||||
run(&mut s, "object.expand", json!({"object": false, "stroke": false, "steps": 64}));
|
||||
let after = render(&s);
|
||||
// The gradient moves with the rectangle on the canvas, and the strips follow it.
|
||||
let diff = mean_diff(&before, &after);
|
||||
assert!(diff < 1.0, "{effect} {params} on item {item}: mean difference {diff}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eight_strips_match_the_gradient_samples() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user