mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 19:40:21 +00:00
Export: clipping type's strokes paint over a knockout clip group's art
A clip group whose clipping type strokes becomes a group of a clip group and the strokes when it is evaluated or exported. That group took the clip group's Knockout Group setting, so the strokes knocked out the clipped art under them. The inner clip group now takes the setting and the group around it is set Off, so the clipped art knocks out as before and the strokes paint over it, as the canvas draws the live clip group. A neutral clip group stays neutral on both.
This commit is contained in:
@@ -28,7 +28,7 @@ use vectorcraft_geom::{Affine, FillRule, PathData, Rect, Vec2};
|
||||
use crate::distort::{transform_move, transform_offsets};
|
||||
use crate::group::{has_own_paint, paints};
|
||||
use crate::reshape::{
|
||||
as_art, clipping_text_outline, dressed, geometry_effects, glyph_outlines, outline_nested_text, painted_type_clip, reshape_leaves,
|
||||
as_art, clipping_text_outline, dressed, geometry_effects, glyph_outlines, knockout_inside, outline_nested_text, painted_type_clip, reshape_leaves,
|
||||
};
|
||||
use crate::{
|
||||
GeomContext, adjust_in_document, apply_geometry_carrying, crop_marks_art, evaluate_container, has_adjustment, has_crop_marks, has_geometry,
|
||||
@@ -502,7 +502,8 @@ fn clip_group_with_type_clip(d: &mut Document, n: &Node) -> Option<Node> {
|
||||
return Some(m);
|
||||
};
|
||||
// `n` keeps its id, name and transparency, and holds the clip group and the strokes over it.
|
||||
let inner = Node::new(d.alloc_id(), NodeKind::Group { children: members, clip: true });
|
||||
let mut inner = Node::new(d.alloc_id(), NodeKind::Group { children: members, clip: true });
|
||||
knockout_inside(&mut m, &mut inner);
|
||||
match &mut m.kind {
|
||||
NodeKind::Group { children, clip } | NodeKind::Layer { children, clip, .. } => {
|
||||
*children = vec![Arc::new(inner), stroke];
|
||||
|
||||
@@ -773,7 +773,8 @@ pub(crate) fn painted_type_clip(doc: Option<&Document>, n: &Node) -> Option<Node
|
||||
}
|
||||
let Some(stroke) = stroke else { return Some(m) };
|
||||
let guides = ch.split_off(Node::guide_run_start(ch));
|
||||
let inner = Node::new(n.id, NodeKind::Group { children: std::mem::take(ch), clip: true });
|
||||
let mut inner = Node::new(n.id, NodeKind::Group { children: std::mem::take(ch), clip: true });
|
||||
knockout_inside(&mut m, &mut inner);
|
||||
match &mut m.kind {
|
||||
NodeKind::Group { children, clip } | NodeKind::Layer { children, clip, .. } => {
|
||||
*children = [Arc::new(inner), Arc::new(stroke)].into_iter().chain(guides).collect();
|
||||
@@ -784,6 +785,17 @@ pub(crate) fn painted_type_clip(doc: Option<&Document>, n: &Node) -> Option<Node
|
||||
Some(m)
|
||||
}
|
||||
|
||||
/// Knockout Group for clip group `m` turned into a group around `inner`, a clip group of its
|
||||
/// members, and its clipping path's strokes: `inner` takes `m`'s setting, so the clipped art knocks
|
||||
/// out as before, and `m` is set Off so the strokes paint over it, as the renderer draws them. A
|
||||
/// neutral `m` stays neutral, so both take the setting of the groups around them.
|
||||
pub(crate) fn knockout_inside(m: &mut Node, inner: &mut Node) {
|
||||
inner.knockout = m.knockout;
|
||||
if m.knockout != vectorcraft_doc::Knockout::Neutral {
|
||||
m.knockout = vectorcraft_doc::Knockout::Off;
|
||||
}
|
||||
}
|
||||
|
||||
/// Replace type anywhere inside `n` by its outlines, as art that keeps the type's look
|
||||
/// ([`as_art`]). Type in a clip group's clipping path (all of `n` when `clipping` is set) becomes
|
||||
/// its outlines with its visibility and effects ([`clipping_text_outline`]); when it paints, the
|
||||
|
||||
@@ -546,6 +546,58 @@ fn painted_clipping_type_survives_enclosing_geometry_effect() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The group in `n` that holds a clip group and then the green stroke art of its clipping type,
|
||||
/// with that clip group.
|
||||
fn stroke_wrapper(n: &Node) -> Option<(&Node, &Node)> {
|
||||
let ch = n.children()?;
|
||||
if let [inner, stroke, ..] = ch.as_slice()
|
||||
&& matches!(inner.kind, NodeKind::Group { clip: true, .. })
|
||||
&& !n.clips()
|
||||
&& paints(stroke, false)
|
||||
{
|
||||
return Some((n, inner));
|
||||
}
|
||||
ch.iter().find_map(|c| stroke_wrapper(c))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clipping_type_strokes_paint_over_a_knockout_clip_group() {
|
||||
// A clip group set to Knockout Group On, Off or neutral, clipped by type that strokes: its
|
||||
// clipped art knocks out as the clip group says, and the type's stroke paints over it without
|
||||
// knocking it out, as the canvas draws the live clip group. The type is reshaped by a group's
|
||||
// Transform around it, or by its own Offset Path.
|
||||
use vectorcraft_doc::Knockout;
|
||||
for (knockout, around) in [(Knockout::On, Knockout::Off), (Knockout::Off, Knockout::Off), (Knockout::Neutral, Knockout::Neutral)] {
|
||||
for own in [false, true] {
|
||||
let mut ty = painted_type(3, true, true);
|
||||
if own {
|
||||
ty.appearance.effects.push(fx("path.offsetPath", json!({"offset": 1})));
|
||||
}
|
||||
let mut clipped = clip_group(2, ty);
|
||||
clipped.knockout = knockout;
|
||||
let mut outer = Node::group(NodeId(1), vec![Arc::new(clipped)]);
|
||||
if !own {
|
||||
outer.appearance.effects.push(fx("distort.transform", json!({"moveV": 10})));
|
||||
}
|
||||
let mut d = Document::new(400.0, 400.0);
|
||||
let layer = d.layers[0].id;
|
||||
d.insert(Some(layer), 0, outer.clone()).unwrap();
|
||||
let baked = bake_document(&d).unwrap();
|
||||
let canvas = if own { None } else { crate::evaluate_container(None, &outer) };
|
||||
let exported = baked.layers.iter().find_map(|l| stroke_wrapper(l));
|
||||
for (what, found) in [("canvas", canvas.as_ref().and_then(stroke_wrapper)), ("export", exported)] {
|
||||
if own && what == "canvas" {
|
||||
continue;
|
||||
}
|
||||
let case = format!("{what}, own effect {own}, knockout {knockout:?}");
|
||||
let (wrapper, inner) = found.unwrap_or_else(|| panic!("{case}: no group around the clip"));
|
||||
assert_eq!(inner.knockout, knockout, "{case}: the clipped art knocks out as before");
|
||||
assert_eq!(wrapper.knockout, around, "{case}: the stroke does not knock out the clipped art");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_clip_groups_own_fill_stays_in_the_clip_when_its_clipping_type_strokes() {
|
||||
// A clip group with a yellow fill of its own and an Offset Path effect, clipped by type that
|
||||
|
||||
Reference in New Issue
Block a user