mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 13:33:51 +00:00
Clipping: a stroked clipping type does not widen the box a clip group's gradient follows
Free Distort and the Warp effects move a group's placed gradient from the group's bounds before the effect to its bounds after it. A clip group whose clipping type strokes is measured as that clip group, so the stroke outside the clip no longer changes how its gradient follows the effect.
This commit is contained in:
@@ -2941,6 +2941,9 @@ fn group_marks(
|
||||
NodeKind::Image(_) => (images.map_or_else(|| n.geometric_bounds(), |w| w.image_bounds(n)), false),
|
||||
NodeKind::Group { children, clip } | NodeKind::Layer { children, clip, .. } if !n.extras().type_outlines => {
|
||||
let layer = matches!(n.kind, NodeKind::Layer { .. });
|
||||
// A clip group whose clipping type's strokes paint around it is measured as that clip
|
||||
// group: the strokes outside the clip do not widen it ([`clip_bounds`]).
|
||||
let clip = *clip || painted_clip_inner(n).is_some();
|
||||
let skip = children.len().saturating_sub(n.editing_children().len());
|
||||
let (mut bounds, mut held) = (None, false);
|
||||
for (i, c) in children.iter().enumerate() {
|
||||
@@ -2951,7 +2954,7 @@ fn group_marks(
|
||||
}
|
||||
at.pop();
|
||||
// Only members measured in the bounds hold the group's gradients in place.
|
||||
let counts = if *clip { i == 0 } else { i >= skip && (c.visible || !layer) };
|
||||
let counts = if clip { i == 0 } else { i >= skip && (c.visible || !layer) };
|
||||
if counts {
|
||||
bounds = vectorcraft_geom::union_opt(bounds, b);
|
||||
held |= h;
|
||||
|
||||
@@ -827,3 +827,50 @@ fn a_groups_own_fill_paints_only_the_clip_of_clipping_type_whose_stroke_moves()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_clip_groups_placed_gradient_follows_free_distort_by_the_clip_when_its_clipping_type_strokes() {
|
||||
// A clip group with a placed linear gradient fill of its own, in a group with Free Distort,
|
||||
// clipped by type whose stroke has a Transform effect moving it 60 pt right, outside the clip:
|
||||
// the gradient moves and scales from the clip's bounds, as for the same clip group whose type
|
||||
// does not stroke. The moved stroke adds nothing to those bounds.
|
||||
use vectorcraft_color::{Gradient, GradientGeom, GradientKind, GradientPaint, GradientStop};
|
||||
let stops = vec![GradientStop::new(0.0, Color::BLACK), GradientStop::new(1.0, Color::WHITE)];
|
||||
let ramp = GradientPaint::new(Gradient::new(GradientKind::Linear, stops));
|
||||
let geom = GradientGeom { start: (10.0, 45.0).into(), end: (30.0, 45.0).into(), aspect: 1.0, focal: None };
|
||||
let placed = Paint::Gradient(Box::new(GradientPaint { geom: Some(geom), ..ramp }));
|
||||
fn placed_geom(n: &Node) -> Option<vectorcraft_color::GradientGeom> {
|
||||
if let Paint::Gradient(g) = n.appearance.fill_paint()
|
||||
&& g.geom.is_some()
|
||||
{
|
||||
return g.geom;
|
||||
}
|
||||
n.children().into_iter().flatten().find_map(|c| placed_geom(c))
|
||||
}
|
||||
let ends = |stroke: bool| {
|
||||
let mut ty = painted_type(3, false, false);
|
||||
if stroke {
|
||||
ty.appearance = Appearance::basic(Paint::None, green(), 2.0).into();
|
||||
for item in &mut ty.appearance.items {
|
||||
if let vectorcraft_doc::AppearanceItem::Stroke(s) = item {
|
||||
s.effects.push(fx("distort.transform", json!({"moveH": 60})));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut group = clip_group(2, ty);
|
||||
group.appearance = Appearance::basic(placed.clone(), Paint::None, 0.0).into();
|
||||
let mut outer = Node::group(NodeId(1), vec![Arc::new(group)]);
|
||||
let corners = json!({"corners": [[1.0 / 3.0, 0.0], [4.0 / 3.0, 0.0], [1.0, 1.0], [0.0, 1.0]]});
|
||||
outer.appearance.effects.push(fx("distort.freeDistort", corners));
|
||||
let canvas = crate::evaluate_container(None, &outer).unwrap();
|
||||
if stroke {
|
||||
assert!(stroke_wrapper(&canvas).is_some(), "the type's stroke paints around the clip: {canvas:?}");
|
||||
}
|
||||
placed_geom(&canvas).unwrap_or_else(|| panic!("no placed gradient: {canvas:?}"))
|
||||
};
|
||||
let (plain, stroked) = (ends(false), ends(true));
|
||||
assert!(
|
||||
plain.start.distance(stroked.start) < 0.5 && plain.end.distance(stroked.end) < 0.5,
|
||||
"the gradient {stroked:?} follows the clip as {plain:?} does"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user