From d8db9eda83f7919b621fa70d08d3709b79571759 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 02:42:10 -0800 Subject: [PATCH 1/4] Symbols: Direct Selection picks a dynamic instance's part where its fill and stroke effects draw it A geometry effect on a dynamic symbol instance's fill or stroke moves or reshapes the art the canvas draws, and a click there already selects the instance. Direct Selection still picked a part of the art at its plain shape and outlined that shape, so a click on the drawn result picked nothing and a click where the part no longer paints picked it. symbol_part_at and symbol_part_outline_in_view now test and outline the instance's art with the effects of its active fill and stroke added, as the canvas adds them. Live objects in the art keep their place, so the child-index path still leads to the part. A nested instance is picked and outlined where its reshaped art is drawn, type with a fill or stroke of its own where its reshaped glyphs are drawn (Type Object Selection by Path Only still takes the type path), and an image's outline includes the shapes its own fills and strokes paint. A clipping path is still picked and outlined by its own geometry. Outline view and layers with Preview off keep the plain shapes; blends, envelopes and repeats in the art are picked without the instance's effects. --- crates/doc/src/hit.rs | 179 +++++++++++++++++++-- crates/effects/src/lib.rs | 6 +- crates/effects/src/reshape.rs | 28 +++- crates/engine/src/session/documents.rs | 3 + crates/engine/src/tests/dynamic_symbols.rs | 154 ++++++++++++++++++ docs/target-app-parity.md | 1 + 6 files changed, 347 insertions(+), 24 deletions(-) diff --git a/crates/doc/src/hit.rs b/crates/doc/src/hit.rs index 7c0de44cab..6286597882 100644 --- a/crates/doc/src/hit.rs +++ b/crates/doc/src/hit.rs @@ -115,6 +115,22 @@ pub fn set_image_paint(f: ImagePaint) { let _ = IMAGE_PAINT.set(f); } +/// Adds the geometry and raster effects of a symbol instance's active fill and stroke to the fills +/// and strokes that paint in the art it is given, the instance's art in the symbol's coordinates, +/// as the canvas adds them to the art it draws. Every object keeps its place in the art, so the +/// child indices of [`symbol_part_at`] still lead to it. Effects are evaluated above this crate, so +/// the engine registers one with [`set_instance_row_art`]. +pub type InstanceRowArt = fn(Option<&Document>, &Node, &mut Node); + +static INSTANCE_ROW_ART: OnceLock = OnceLock::new(); + +/// Register how a symbol instance's art takes the effects of the instance's fill and stroke, for +/// Direct Selection's parts (the first registration stays). +pub fn set_instance_row_art(f: InstanceRowArt) { + // Already set: the same engine, registered by another session. + let _ = INSTANCE_ROW_ART.set(f); +} + /// The shapes that [`ImagePaint`] gives for one object. type Painted = Vec<(BezPath, FillRule, AppearanceItem)>; @@ -1575,12 +1591,45 @@ fn hit_leaf(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Optio /// symbol instance) paint with their geometry effects ([`image_paint`]), the frontmost first: a /// stroke along its shape, a fill inside it except with Selection by Path Only. fn hit_painted(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Option { - image_paint(Some(symbols.document()), n).iter().rev().find_map(|(bp, rule, item)| match item { + painted_hit(&image_paint(Some(symbols.document()), n), p, opt) +} + +/// What a click at `p` hits among `painted`, the shapes [`image_paint`] gives, as [`hit_painted`] +/// tests them. +fn painted_hit(painted: &Painted, p: Point, opt: HitOptions) -> Option { + painted.iter().rev().find_map(|(bp, rule, item)| match item { AppearanceItem::Stroke(s) => s.hits(bp, *rule, p, opt.tol).then_some(HitKind::Stroke), AppearanceItem::Fill(_) => (!opt.path_only && fill_contains(bp, *rule, p)).then_some(HitKind::Fill), }) } +/// Is `n` a symbol instance whose active fill or stroke has geometry effects that reshape the art +/// it draws ([`image_paint`])? Callers ask [`own_effects_art`] first, which takes an instance whose +/// own effects change what it draws; an instance whose own effects add only pixels (a drop shadow) +/// is tested here. Never with `outline`, where the canvas draws no effects, nor while a +/// [`DrawnOff`] guard lives. +fn reshapes_instance_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> bool { + !outline && !DRAWN_OFF.get() && matches!(n.kind, NodeKind::SymbolInstance { .. }) && !image_paint(Some(symbols.document()), n).is_empty() +} + +/// The art that symbol instance `n` draws with a visible effect of its own, the effects of its +/// fills and strokes and those of its symbol's art all applied, or that type `n` draws with the +/// visible effects of its own and of its fills and strokes, as outlined paths ([`set_drawn_art`]). +/// `None` for other objects, with `outline`, where the canvas draws no effects, for an instance or +/// type without such an effect, while a [`DrawnOff`] guard lives, and when no geometry effect +/// changes what it draws. +fn own_effects_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> Option { + let has = match n.kind { + NodeKind::SymbolInstance { .. } => n.appearance.effects.iter().any(|e| e.visible), + NodeKind::Text(_) => has_own_effects(n), + _ => false, + }; + if outline || DRAWN_OFF.get() || !has { + return None; + } + DRAWN_ART.get()?(symbols, n) +} + /// Is `p` within `tol` of the type path of `t` (in `n`), what "Type Object Selection by Path /// Only" picks type by: its baselines ([`crate::TextObject::baselines`]), area type's frame and /// type on a path's path, drawn through `n`'s perspective projection if it has one. @@ -1690,6 +1739,17 @@ impl<'a> InstanceArt<'a> { Some(Self { art, map, xf: *xf, boxes }) } + /// [`Self::of`] with the effects of the instance's active fill and stroke added to the fills and + /// strokes in the art ([`set_instance_row_art`]), so that each object of it is tested and + /// outlined where the canvas draws it. Not with `outline`, where the canvas draws no effects. + fn drawn(doc: &'a Document, inst: &Node, outline: bool) -> Option { + let mut art = Self::of(doc, inst)?; + if !outline && let Some(f) = INSTANCE_ROW_ART.get() { + f(Some(doc), inst, &mut art.art); + } + Some(art) + } + /// The map that the objects inside group or layer `n` are moved by as one piece: `whole`, the /// map of an object around `n` that is moved as one piece, or else the map of the 9-slice cell /// `n` lies in ([`crate::NineSliceMap::one_cell`]). `None` when `n` is placed through the guides @@ -1751,15 +1811,18 @@ fn moved(n: &Node, xf: vectorcraft_geom::Affine) -> Node { /// [`HitOptions::skip_guides`]. Nothing is picked in art that placing through the symbol's 9-slice /// guides could make more than [`crate::MAX_SYMBOL_NODES`] objects of, which the canvas does not /// draw. Art in a layer of the symbol whose Preview is off, and the art of an instance below such a -/// layer, is tested in outline ([`HitOptions::outline`]), as the canvas draws it. `None` when `inst` is not a symbol instance or -/// no editable object of its art is under `p`. +/// layer, is tested in outline ([`HitOptions::outline`]), as the canvas draws it. Elsewhere each +/// object is tested where the geometry effects of the instance's active fill and stroke draw it +/// ([`InstanceArt::drawn`]), and not where its own shape no longer paints. Live objects in the art +/// (blends, envelopes, repeats) are tested without those effects. `None` when `inst` is not a +/// symbol instance or no editable object of its art is under `p`. pub fn symbol_part_at(doc: &Document, inst: &Node, p: Point, opt: HitOptions) -> Option> { let _walk = ArtWalk::open(); - let art = InstanceArt::of(doc, inst)?; + let outline = opt.outline || below_preview_off(doc, inst, opt.scope); + let art = InstanceArt::drawn(doc, inst, outline)?; let symbols = doc.kept_symbol_boxes(); let mut path = vec![]; - let outline = opt.outline || below_preview_off(doc, inst, opt.scope); - let find = FindPart { art: &art, p, opt, symbols: &symbols, whole_instance: false }; + let find = FindPart { art: &art, p, opt, symbols: &symbols, whole_instance: false, drawn: true }; find.find(&art.art, &mut path, None, outline).map(|_| path) } @@ -1772,14 +1835,35 @@ struct FindPart<'a> { /// For [`instance_art_hit`]: locked and template objects of the art count, as the canvas draws /// them, and clipping paths are not picked by their outline. whole_instance: bool, + /// For [`symbol_part_at`] and [`drawn_instance_hit`]: the art carries the effects of the + /// instance's active fill and stroke ([`InstanceArt::drawn`]). + drawn: bool, } impl FindPart<'_> { /// What a click at `p` hits on object `n` of the art, placed. [`hit_any`] takes `n` and each - /// object it visits inside `n` from the [`ArtWalk`] limit. + /// object it visits inside `n` from the [`ArtWalk`] limit. In drawn art, a symbol instance with + /// geometry effects of its own, and type whose own effects or fill and stroke effects (its own, + /// or those the outer instance adds) reshape it, are hit only where the art they draw is + /// ([`own_effects_art`]), and an instance whose fill or stroke has geometry effects that reshape + /// its art (its own, or those the outer instance passes on) only where its art is drawn with + /// them ([`drawn_instance_hit`]); not anywhere in their bounds. With Type Object Selection by + /// Path Only ([`HitOptions::type_path_only`]), type is still picked by its type path. fn hit(&self, n: &Node, whole: Option, opt: HitOptions) -> Option { let placed = self.art.place(n, whole)?; let _charged = ArtWalk::charge(); + // Type Object Selection by Path Only picks type by its type path, whatever its effects draw. + let type_path = opt.type_path_only && matches!(placed.kind, NodeKind::Text(_)); + if self.drawn && !type_path { + if let Some(art) = own_effects_art(&placed, self.symbols, opt.outline) { + let _off = DrawnOff::set(); + let _art_only = ArtOnly::set(); + return hit_any(&art, self.p, opt, self.symbols); + } + if reshapes_instance_art(&placed, self.symbols, opt.outline) { + return drawn_instance_hit(&placed, self.p, opt, self.symbols); + } + } hit_any(&placed, self.p, opt, self.symbols) } @@ -1858,7 +1942,26 @@ fn instance_art_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) ARTS_WALKED.with(|c| c.set(c.get() + 1)); let opt = HitOptions { clip_outlines: false, ..opt }; let _art_only = ArtOnly::set(); - FindPart { art: &art, p, opt, symbols, whole_instance: true }.find(&art.art, &mut vec![], None, false) + FindPart { art: &art, p, opt, symbols, whole_instance: true, drawn: false }.find(&art.art, &mut vec![], None, false) +} + +/// What a click at `p` hits of symbol instance `n`, an object of another instance's drawn art, +/// where the canvas draws `n`'s art with the geometry effects of `n`'s active fill and stroke +/// ([`InstanceArt::drawn`]): each object of that art where it is drawn, paths, images and type +/// alike, and not anywhere in `n`'s box. Locked and template objects of the art count, as in +/// [`instance_art_hit`]. `None` for an instance of a missing symbol, of a symbol that holds an +/// instance of itself or nests too deep ([`SymbolBoxes::art`]), of art past the 9-slice object +/// limit ([`InstanceArt::of`]), and once the click has visited as many objects of symbol art as +/// [`ArtWalk`] allows. +fn drawn_instance_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes) -> Option { + let NodeKind::SymbolInstance { symbol, .. } = &n.kind else { return None }; + if symbols.art(symbol).is_none() || ArtWalk::used_up() { + return None; + } + let art = InstanceArt::drawn(symbols.document(), n, false)?; + let opt = HitOptions { clip_outlines: false, ..opt }; + let _art_only = ArtOnly::set(); + FindPart { art: &art, p, opt, symbols, whole_instance: true, drawn: true }.find(&art.art, &mut vec![], None, false) } thread_local! { @@ -2008,15 +2111,18 @@ pub fn symbol_part_outline(doc: &Document, inst: &Node, path: &[u32]) -> Option< /// instance (the isolated container [`HitOptions::scope`] and the layers around it apart), the /// outlines are cut to the bounds of the plain clipping paths, without their live effects, as /// [`symbol_part_at`] counts them. The outline is empty when the effects of a clipping path around -/// the object leave no region. +/// the object leave no region. Elsewhere the outlines follow the geometry effects of the instance's +/// active fill and stroke, as [`symbol_part_at`] does. pub fn symbol_part_outline_in_view(doc: &Document, inst: &Node, path: &[u32], opt: HitOptions) -> Option { - let art = InstanceArt::of(doc, inst)?; - let part = crate::symbol_overrides::part(&art.art, path)?; let mut outline = opt.outline || below_preview_off(doc, inst, opt.scope); + let art = InstanceArt::drawn(doc, inst, outline)?; + let part = crate::symbol_overrides::part(&art.art, path)?; + let symbols = doc.kept_symbol_boxes(); let mut out = BezPath::new(); let mut limit = None; let mut whole = None; let mut n = &art.art; + let mut mask = false; for &i in path { let children = n.children()?; whole = art.whole(n, whole); @@ -2028,9 +2134,12 @@ pub fn symbol_part_outline_in_view(doc: &Document, inst: &Node, path: &[u32], op let Some(within) = limit_within(&art.place_unclipped(first, whole)?, limit, outline) else { return Some(out) }; limit = within; } + mask = i == 0 && n.clips(); n = children.get(usize::try_from(i).ok()?)?; } - outline_within(&art.place(part, whole)?, limit, outline, &mut out); + // A clipping path is picked by its own geometry ([`FindPart::find`]), and outlined so. + let placed = art.place(part, whole)?; + plain(mask, || outline_within(&placed, &symbols, limit, outline, &mut out)); Some(out) } @@ -2052,9 +2161,37 @@ fn limit_within(clip: &Node, limit: Option, outline: bool) -> Option, outline: bool, out: &mut BezPath) { +/// [`symbol_part_outline_in_view`] for placed object `n`, cut to `limit` when there is one. A path +/// or compound path whose geometry effects reshape it is outlined as the art they draw +/// ([`drawn_art`]), a symbol instance with geometry effects of its own and type whose effects +/// reshape it as the art they draw ([`own_effects_art`]), and a symbol instance whose fill or stroke effects reshape its art as that +/// art drawn with them ([`InstanceArt::drawn`]), as [`FindPart`] tests them, except with `outline` +/// and while a [`DrawnOff`] guard lives. +fn outline_within(n: &Node, symbols: &SymbolBoxes, limit: Option, outline: bool, out: &mut BezPath) { use vectorcraft_geom::kurbo::Shape; + if matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) + && let Some(art) = drawn_art(symbols, n, outline) + { + let _off = DrawnOff::set(); + art.iter().for_each(|a| outline_within(a, symbols, limit, outline, out)); + return; + } + if let Some(art) = own_effects_art(n, symbols, outline) { + let _off = DrawnOff::set(); + outline_within(&art, symbols, limit, outline, out); + return; + } + if let NodeKind::SymbolInstance { symbol, .. } = &n.kind + && reshapes_instance_art(n, symbols, outline) + { + if symbols.art(symbol).is_some() + && let Some(art) = InstanceArt::drawn(symbols.document(), n, false) + && let Some(placed) = art.place(&art.art, None) + { + outline_within(&placed, symbols, limit, outline, out); + } + return; + } if let Some(pd) = n.path_data() { match limit { Some(r) => push_cut(out, &pd.to_bezpath(), r), @@ -2066,16 +2203,26 @@ fn outline_within(n: &Node, limit: Option, outline: bool, out: &mut BezPat { out.extend(b.to_path(0.1)); } + // An image is also outlined where its own fills and strokes paint with their effects, as + // [`hit_leaf`] picks it there ([`image_paint`]). + if !outline && matches!(n.kind, NodeKind::Image(_)) { + for (bp, ..) in image_paint(Some(symbols.document()), n).iter() { + match limit { + Some(r) => push_cut(out, bp, r), + None => out.extend(bp.iter()), + } + } + } let Some(children) = n.children() else { return }; let outline = outline || previews_off(n); if n.clips() && let Some((first, rest)) = children.split_first() { let Some(inner) = limit_within(first, limit, outline) else { return }; - rest.iter().for_each(|c| outline_within(c, inner, outline, out)); + rest.iter().for_each(|c| outline_within(c, symbols, inner, outline, out)); return; } - children.iter().for_each(|c| outline_within(c, limit, outline, out)); + children.iter().for_each(|c| outline_within(c, symbols, limit, outline, out)); } /// The overlap of `a` and `b` (`a` alone without `b`), `None` when they do not overlap. diff --git a/crates/effects/src/lib.rs b/crates/effects/src/lib.rs index c46ab0c76e..46fd9344e2 100644 --- a/crates/effects/src/lib.rs +++ b/crates/effects/src/lib.rs @@ -89,9 +89,9 @@ pub use raster::{ without_geometry, }; pub use reshape::{ - SYMBOL_ART_MAX_NODES, expand_outlined, follows_image_pixels, gives_image_shape, has_copied_row_raster, has_gradient_copies, - has_instance_row_raster, has_item_geometry, has_painted_effects, has_transform_art, has_transform_copies, has_transform_options, image_paint, - instance_as_art, needs_outline, outer_effects, outline_art, outline_text, paint_type_piece, reshape, + SYMBOL_ART_MAX_NODES, add_instance_row_effects_to_parts, expand_outlined, follows_image_pixels, gives_image_shape, has_copied_row_raster, + has_gradient_copies, has_instance_row_raster, has_item_geometry, has_painted_effects, has_transform_art, has_transform_copies, + has_transform_options, image_paint, instance_as_art, needs_outline, outer_effects, outline_art, outline_text, paint_type_piece, reshape, }; pub use revolve::{ CLASSIC_REVOLVE, REVOLVE, has_revolve, is_revolve, revolve_art, revolve_art_in, revolve_options, validate_revolve, validate_revolve_in, diff --git a/crates/effects/src/reshape.rs b/crates/effects/src/reshape.rs index a57c2085f6..c7ab85e7a8 100644 --- a/crates/effects/src/reshape.rs +++ b/crates/effects/src/reshape.rs @@ -388,11 +388,23 @@ fn row_effects_of(fx: &[Effect]) -> Vec { /// appearance, so the effects never pass round a symbol that holds itself. Without `doc`, no /// instance in the art takes them. pub(crate) fn add_instance_row_effects(doc: Option<&Document>, n: &Node, art: &mut Node) { + add_instance_rows(doc, n, art, true); +} + +/// [`add_instance_row_effects`] for Direct Selection's parts of a symbol instance's art: live +/// objects (blends, envelopes, repeats) are left as they are, without the effects, so that every +/// object keeps its place in the art and the child indices that pick a part still lead to it. +pub fn add_instance_row_effects_to_parts(doc: Option<&Document>, n: &Node, art: &mut Node) { + add_instance_rows(doc, n, art, false); +} + +/// [`add_instance_row_effects`], evaluating live objects in the art only with `live`. +fn add_instance_rows(doc: Option<&Document>, n: &Node, art: &mut Node, live: bool) { let NodeKind::SymbolInstance { symbol, .. } = &n.kind else { return }; let fill = active_fill(n).map_or(vec![], |f| row_effects_of(&f.effects)); let stroke = active_stroke(n).map_or(vec![], |s| row_effects_of(&s.effects)); if !fill.is_empty() || !stroke.is_empty() { - add_row_effects(doc, symbol, art, &fill, &stroke); + add_row_effects(doc, symbol, art, &fill, &stroke, live); } } @@ -413,8 +425,9 @@ fn places_symbol(doc: &Document, from: &str, to: &str, seen: &mut HashSet, outer: &str, n: &mut Node, fill: &[Effect], stroke: &[Effect]) { +/// instance of the symbol named `outer`. Without `live`, live objects are left as they are +/// ([`add_instance_row_effects_to_parts`]). +fn add_row_effects(doc: Option<&Document>, outer: &str, n: &mut Node, fill: &[Effect], stroke: &[Effect], live: bool) { match &n.kind { NodeKind::Path { clipping: true, .. } | NodeKind::Path { guide: true, .. } | NodeKind::RulerGuide { .. } => return, NodeKind::SymbolInstance { symbol, .. } => { @@ -425,7 +438,12 @@ fn add_row_effects(doc: Option<&Document>, outer: &str, n: &mut Node, fill: &[Ef } return; } - _ if vectorcraft_doc::live::is_live(n) => *n = evaluated(doc, n), + _ if vectorcraft_doc::live::is_live(n) => { + if !live { + return; + } + *n = evaluated(doc, n); + } _ => {} } let takes = |i: &AppearanceItem| { @@ -445,7 +463,7 @@ fn add_row_effects(doc: Option<&Document>, outer: &str, n: &mut Node, fill: &[Ef let clips = n.clips(); for (i, c) in n.children_mut().into_iter().flatten().enumerate() { if !(clips && i == 0) { - add_row_effects(doc, outer, Arc::make_mut(c), fill, stroke); + add_row_effects(doc, outer, Arc::make_mut(c), fill, stroke, live); } } } diff --git a/crates/engine/src/session/documents.rs b/crates/engine/src/session/documents.rs index 61dbdb4491..0272e8fb76 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine/src/session/documents.rs @@ -24,6 +24,9 @@ impl Session { }); // Clicks find an image's own fills and strokes where their effects draw them. vectorcraft_doc::hit::set_image_paint(vectorcraft_render::effects::image_paint); + // Direct Selection picks and outlines the parts of a dynamic symbol's instance where the + // effects of the instance's fill and stroke draw them. + vectorcraft_doc::hit::set_instance_row_art(vectorcraft_render::effects::add_instance_row_effects_to_parts); // Clicks inside a clip group fall in the region its clipping path's effects give it. vectorcraft_doc::hit::set_clip_region(vectorcraft_render::effects::reshaped_clip_outline); // Clicks and marquees find paths, compound paths, groups and layers where their geometry diff --git a/crates/engine/src/tests/dynamic_symbols.rs b/crates/engine/src/tests/dynamic_symbols.rs index e136d9f45b..6f4973cd15 100644 --- a/crates/engine/src/tests/dynamic_symbols.rs +++ b/crates/engine/src/tests/dynamic_symbols.rs @@ -587,6 +587,160 @@ fn direct_selection_paints_one_object_of_one_dynamic_instance() { assert_eq!(pixel(&s, 80, 30), BLUE); } +/// Instance `inst` with a new fill (`fill`) or stroke row without paint whose effect is `effect` +/// with `params`. +fn row_effect(s: &mut Session, inst: NodeId, fill: bool, effect: &str, params: Value) { + s.execute(if fill { "appearance.addFill" } else { "appearance.addStroke" }, &json!({"ids": [inst.0]})).unwrap(); + let row = node(s, inst).appearance.items.len() - 1; + s.execute("appearance.setItem", &json!({"ids": [inst.0], "index": row, "none": true})).unwrap(); + s.execute("effect.apply", &json!({"ids": [inst.0], "item": row, "effect": effect, "params": params})).unwrap(); +} + +/// The object of `inst`'s art that Direct Selection picks at (`x`, `y`) with `opt`. +fn part_at(s: &Session, inst: NodeId, (x, y): (f64, f64), opt: vectorcraft_doc::hit::HitOptions) -> Option> { + let doc = &s.doc().unwrap().doc; + vectorcraft_doc::hit::symbol_part_at(doc, doc.node(inst).unwrap(), vectorcraft_geom::Point::new(x, y), opt) +} + +/// The box of the outline of the object at `path` in `inst`'s art, as Direct Selection draws it. +fn part_outline_box(s: &Session, inst: NodeId, path: &[u32]) -> Rect { + use vectorcraft_geom::kurbo::Shape; + let doc = &s.doc().unwrap().doc; + let outline = vectorcraft_doc::hit::symbol_part_outline_in_view(doc, doc.node(inst).unwrap(), path, Default::default()).unwrap(); + outline.bounding_box() +} + +/// A geometry effect on a dynamic instance's fill or stroke moves where the objects of its art +/// are drawn: Direct Selection picks an object where it is drawn, not where its own shape no longer +/// paints, and outlines it there; Outline view still takes the plain shapes. +#[test] +fn direct_selection_picks_a_part_where_the_instance_fill_and_stroke_effects_draw_it() { + use vectorcraft_doc::hit::HitOptions; + let opt = HitOptions { tol: 1.0, ..Default::default() }; + let mut s = session(); + let inst = pair(&mut s, "dynamic"); + row_effect(&mut s, inst, true, "distort.transform", json!({"moveH": 100})); + // The squares are drawn at x 110..150 and 160..200. + assert_eq!(part_at(&s, inst, (130.0, 30.0), opt), Some(vec![0]), "the first square where it is drawn"); + assert_eq!(part_at(&s, inst, (180.0, 30.0), opt), Some(vec![1]), "the second square where it is drawn"); + assert_eq!(part_at(&s, inst, (80.0, 30.0), opt), None, "where the second square's own shape no longer paints"); + assert_eq!(part_at(&s, inst, (60.5, 30.0), opt), None, "the plain edge of the second square"); + assert_eq!(part_at(&s, inst, (60.5, 30.0), HitOptions { outline: true, ..opt }), Some(vec![1]), "Outline view draws the plain shapes"); + let b = part_outline_box(&s, inst, &[0]); + assert!((b.x0 - 110.0).abs() < 0.5 && (b.x1 - 150.0).abs() < 0.5, "the outline follows the moved square: {b:?}"); + direct(&mut s, (130.0, 30.0), (130.0, 30.0), Mods::default()); + let sel = s.doc().unwrap().selection.clone(); + assert_eq!(sel.objects, [inst]); + assert_eq!(sel.symbol_part, Some(vectorcraft_doc::SymbolPart { instance: inst, path: vec![0] }), "a press on the drawn square picks it"); + + // A stroke effect: Offset Path moves the first square's stroke out to x = 0. + let mut s = session(); + let (a, b) = (square(&mut s, 10.0), square(&mut s, 60.0)); + s.execute("paint.setStroke", &json!({"ids": [a.0, b.0], "color": "#00ff00"})).unwrap(); + let inst = id(&s.execute("symbol.new", &json!({"name": "Pair", "ids": [a.0, b.0], "type": "dynamic"})).unwrap()); + row_effect(&mut s, inst, false, "path.offsetPath", json!({"offset": 10})); + assert_eq!(part_at(&s, inst, (0.5, 30.0), opt), Some(vec![0]), "the moved stroke"); + assert_eq!(part_at(&s, inst, (30.0, 30.0), opt), Some(vec![0]), "the fill keeps its shape"); + let b = part_outline_box(&s, inst, &[0]); + assert!(b.x0 < 1.0 && b.x1 > 59.0, "the outline takes in the moved stroke: {b:?}"); + + // A symbol instance in the art takes the effect too: it is picked and outlined where its art is + // drawn, not in its box. The fill effect moves its square; its image has no fill and stays. + let mut s = session(); + let a = square(&mut s, 10.0); + place_image(&mut s); + let img = top(&s); + let inner = id(&s.execute("symbol.new", &json!({"name": "Inner", "ids": [a.0, img.0]})).unwrap()); + let b = square(&mut s, 60.0); + let inst = id(&s.execute("symbol.new", &json!({"name": "Outer", "ids": [inner.0, b.0], "type": "dynamic"})).unwrap()); + row_effect(&mut s, inst, true, "distort.transform", json!({"moveH": 100})); + assert_eq!(part_at(&s, inst, (130.0, 30.0), opt), Some(vec![0]), "the nested instance's square where it is drawn"); + assert_eq!(part_at(&s, inst, (65.0, 35.0), opt), Some(vec![0]), "the nested instance's image"); + assert_eq!(part_at(&s, inst, (30.0, 30.0), opt), None, "the nested instance's own box"); + let b = part_outline_box(&s, inst, &[0]); + assert!((b.x0 - 50.0).abs() < 0.5 && (b.x1 - 150.0).abs() < 0.5, "the outline takes in the moved square and the image: {b:?}"); + + // A nested instance with a geometry effect of its own is picked where both effects draw it. + let mut s = session(); + let a = square(&mut s, 10.0); + let inner = id(&s.execute("symbol.new", &json!({"name": "Inner", "ids": [a.0]})).unwrap()); + s.execute("effect.apply", &json!({"ids": [inner.0], "effect": "distort.transform", "params": {"moveV": 30}})).unwrap(); + let b = square(&mut s, 60.0); + let inst = id(&s.execute("symbol.new", &json!({"name": "Outer", "ids": [inner.0, b.0], "type": "dynamic"})).unwrap()); + row_effect(&mut s, inst, true, "distort.transform", json!({"moveH": 100})); + assert_eq!(part_at(&s, inst, (130.0, 60.0), opt), Some(vec![0]), "the nested square moved by both effects"); + assert_eq!(part_at(&s, inst, (30.0, 30.0), opt), None, "the nested instance's own box"); + let b = part_outline_box(&s, inst, &[0]); + assert!((b.x0 - 110.0).abs() < 0.5 && (b.y0 - 40.0).abs() < 0.5 && (b.y1 - 80.0).abs() < 0.5, "the outline follows both effects: {b:?}"); + + // Type with a fill of its own in the art is picked and outlined where the fill effect draws its + // glyphs, not in its own bounds. + let mut s = session(); + let t = id(&s.execute("text.create", &json!({"x": 10, "y": 45, "size": 40, "text": "I"})).unwrap()); + s.execute("appearance.addFill", &json!({"ids": [t.0]})).unwrap(); + let plain = { + let doc = &s.doc().unwrap().doc; + doc.node(t).unwrap().geometric_bounds().unwrap() + }; + let b = square(&mut s, 60.0); + let inst = id(&s.execute("symbol.new", &json!({"name": "Outer", "ids": [t.0, b.0], "type": "dynamic"})).unwrap()); + row_effect(&mut s, inst, true, "distort.transform", json!({"moveH": 100})); + // The type's own color still paints the glyph in place; the new fill paints it 100 pt right. + let drawn = part_outline_box(&s, inst, &[0]); + assert!(drawn.x1 > plain.x1 + 90.0 && drawn.x1 < plain.x1 + 101.0, "the outline takes in the moved glyph: {drawn:?}, plain {plain:?}"); + let glyph = drawn.x1 - 100.0 - drawn.x0; + let (x, y) = (drawn.x1 - glyph / 2.0, (drawn.y0 + drawn.y1) / 2.0); + assert_eq!(part_at(&s, inst, (x, y), opt), Some(vec![0]), "the type where the fill effect draws its glyph"); + assert_eq!(part_at(&s, inst, (plain.x0 + 1.0, plain.y0 + 1.0), opt), None, "the type's own bounds, off its glyph"); + let by_path = HitOptions { type_path_only: true, ..opt }; + assert_eq!(part_at(&s, inst, (plain.x1 - 1.5, 45.0), by_path), Some(vec![0]), "Type Object Selection by Path Only takes the baseline"); + + // A nested instance whose own effect adds only pixels (a drop shadow) is still picked where the + // outer fill effect draws its art. + let mut s = session(); + let a = square(&mut s, 10.0); + let inner = id(&s.execute("symbol.new", &json!({"name": "Inner", "ids": [a.0]})).unwrap()); + s.execute("effect.apply", &json!({"ids": [inner.0], "effect": "stylize.dropShadow"})).unwrap(); + let b = square(&mut s, 60.0); + let inst = id(&s.execute("symbol.new", &json!({"name": "Outer", "ids": [inner.0, b.0], "type": "dynamic"})).unwrap()); + row_effect(&mut s, inst, true, "distort.transform", json!({"moveH": 100})); + assert_eq!(part_at(&s, inst, (130.0, 30.0), opt), Some(vec![0]), "the shadowed nested square where it is drawn"); + assert_eq!(part_at(&s, inst, (30.0, 30.0), opt), None, "the shadowed nested instance's own box"); + + // An image whose fill has Convert to Shape is picked and outlined where the instance's fill + // effect moves that shape. + let mut s = session(); + place_image(&mut s); + let img = top(&s); + let frame = node(&s, img).geometric_bounds().unwrap(); + s.execute("appearance.addFill", &json!({"ids": [img.0]})).unwrap(); + s.execute("paint.setFill", &json!({"ids": [img.0], "color": "#00ff00", "item": 0})).unwrap(); + s.execute("effect.apply", &json!({"ids": [img.0], "effect": "convertToShape.rectangle", "item": 0})).unwrap(); + let b = square(&mut s, 200.0); + let inst = id(&s.execute("symbol.new", &json!({"name": "Outer", "ids": [img.0, b.0], "type": "dynamic"})).unwrap()); + row_effect(&mut s, inst, true, "distort.transform", json!({"moveH": 100})); + let c = frame.center(); + assert_eq!(part_at(&s, inst, (c.x + 100.0, c.y), opt), Some(vec![0]), "the image where its fill is drawn"); + let o = part_outline_box(&s, inst, &[0]); + assert!(o.x1 > frame.x1 + 99.0, "the outline takes in the moved fill: {o:?}, frame {frame:?}"); +} + +/// A clipping path in a dynamic symbol's art with a geometry effect of its own is picked by its +/// own geometry, and Direct Selection outlines that geometry, not the shape the effect draws. +#[test] +fn a_picked_clipping_path_is_outlined_by_its_own_geometry() { + let mut s = session(); + let content = square(&mut s, 20.0); + let clip = square(&mut s, 10.0); + s.execute("object.clippingMask.make", &json!({"ids": [content.0, clip.0]})).unwrap(); + s.execute("effect.apply", &json!({"ids": [clip.0], "effect": "path.offsetPath", "params": {"offset": 10}})).unwrap(); + let group = top(&s); + assert!(node(&s, group).clips()); + let inst = id(&s.execute("symbol.new", &json!({"name": "Clip", "ids": [group.0], "type": "dynamic"})).unwrap()); + let b = part_outline_box(&s, inst, &[0]); + assert!((b.x0 - 10.0).abs() < 0.5 && (b.x1 - 50.0).abs() < 0.5, "the clipping path's own edge: {b:?}"); +} + #[test] fn a_drag_of_a_picked_object_moves_nothing_and_says_why() { let mut s = session(); diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index f8a3dc84a0..17eb1a0ee0 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2102,6 +2102,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur A geometry effect on one of type's own fills or strokes reshapes the whole outline that the fill or stroke paints, on the canvas and in exports; PDF, SVG, EPS and the other vector exports write such type as paths. On type that holds inline graphics, those effects are drawn and exported only when the type has a geometry effect or perspective of its own. A geometry effect on a symbol instance's fill reshapes the filled shapes of the symbol's art and leaves their strokes as they are; one on the instance's stroke reshapes the stroked shapes and leaves their fills as they are. The shapes keep their colors. Only the instance's topmost fill and topmost stroke count, and only while they are visible with an opacity above 0. The canvas and Object › Expand Appearance use the same art, SVG and PDF export bake the same shapes, and Expand Appearance turns the instance into an editable group in one undo step. A group's own fills and strokes in the art take the effects too. An instance inside the art passes the effects on to its own art, and a dynamic symbol's instance reshapes the fills and strokes it paints on the art. How the effects map onto the symbol's art is VectorCraft's own rule. The help page describes effects on one fill or stroke, and the help page describes Expand Appearance (engine `expand::a_symbol_instance_fill_effect_reshapes_its_filled_art_and_expands`, `a_symbol_instance_stroke_effect_reshapes_its_stroked_art_and_expands`, `a_stroke_effect_reshapes_a_stroke_a_dynamic_instance_adds`, `a_fill_effect_reshapes_the_fill_of_a_group_in_the_art`, `only_the_topmost_visible_instance_fill_reshapes_the_art`, `a_nested_symbol_instance_takes_the_outer_fill_effect`, `export_bakes_a_symbol_instance_fill_effect`, `a_fill_effect_on_an_instance_of_a_symbol_that_holds_itself_ends`). Existing documents with a geometry effect on a symbol instance's fill or stroke draw differently: before, the effect drew nothing. Effect › Pathfinder takes a symbol instance as the art it draws with the geometry effects of its fill and stroke, as they take a path with such effects: the result painted by the instance's art carries those effects, also when the instance has geometry effects of its own and when the instance sits inside another symbol's art. A click where those effects paint the art outside the instance's bounds selects the instance, a fill only when Selection by Path Only is off, and outline mode still takes the instance's bounds alone. A marquee across those shapes selects the instance too, and a marquee across the shape an image's own fill or stroke paints outside its frame selects the image, except in outline mode. A compound shape's area leaves out its members' fill and stroke effects for symbol instances as for paths, since the compound shape paints the area with its own appearance. These are VectorCraft's own rules (engine `expand::pathfinder_takes_a_symbol_instance_fill_and_stroke_effects`, `a_click_where_a_symbol_instance_fill_or_stroke_effect_paints_selects_it`, `a_stroke_effect_reshapes_a_stroke_a_dynamic_instance_adds`, `a_fill_effect_reshapes_the_fill_of_a_group_in_the_art`, `a_click_on_the_grown_fill_of_an_image_in_the_art_selects_the_instance`, `a_marquee_where_a_symbol_instance_fill_or_stroke_effect_paints_selects_it`, `a_marquee_on_the_shape_of_an_image_fill_selects_it`). Before, Pathfinder dropped those effects, and clicks and marquees took only the instance's bounds. + Direct Selection on a dynamic symbol's instance picks an object of the art where the geometry effects of the instance's fill and stroke draw it, not where the object's own shape no longer paints, and outlines it there. An instance nested in the art is picked and outlined where its reshaped art is drawn, and type with a fill or stroke of its own where its reshaped glyphs are drawn, not anywhere in their bounds; Type Object Selection by Path Only still picks type by its type path. An image is outlined where its own fills and strokes paint as well as by its frame. A clipping path is still picked and outlined by its own geometry. Outline view and layers with Preview off still take the plain shapes, and blends, envelopes and repeats in the art are picked without those effects. These are VectorCraft's own rules (engine `dynamic_symbols::direct_selection_picks_a_part_where_the_instance_fill_and_stroke_effects_draw_it`, `a_picked_clipping_path_is_outlined_by_its_own_geometry`). Before, a part was picked and outlined at its plain shape only. Live effects inside a symbol's art (geometry effects, color adjustments and the rest that export bakes) are written where each instance places the art in PDF, print, EPS and DXF, as the canvas draws them: the art is placed first and its effects are applied after, so an instance that scales its art does not scale the distance a Transform effect moves it. Symbols nested in the art, a dynamic symbol instance's own paint changes and the stain an instance's fill gives its art are kept, and the art is stained before its effects apply. A linked instance's PDF link covers its art where the effects draw it. A symbol whose art holds itself stops at the nesting limit, and the symbols' own art keeps its effects. An instance stays an instance in these exports when the objects its art makes once baked (the copies a Transform effect makes included) would take the export's placed symbol art past 16,000,000 objects, or when its baked art would draw deeper than the 128 levels a document may draw; these are VectorCraft's own limits. Art baked for an instance that then stays an instance still counts toward that limit, and while an instance's art bakes, the art's own objects are held in the limit for the instances nested in it. Instances the export leaves out (hidden ones, those in hidden groups, on template layers, and on hidden layers or layers that do not print when the export leaves those out) are not placed and do not count toward that limit. Before, these exports wrote the art without its effects (effects `bake::placing_symbols_bakes_their_art_where_each_instance_places_it`, `placing_symbols_reaches_the_art_of_nested_instances`, `placing_a_symbol_that_holds_itself_stops`, `placing_symbols_keeps_dynamic_instances_changes`, `placing_symbols_keeps_the_instances_stain`, `placing_symbols_counts_the_baked_art`, `placing_symbols_counts_nested_art_once`, `placing_symbols_holds_the_outer_art_while_it_bakes`, `placing_symbols_counts_the_art_it_drops`, `placing_symbols_counts_art_dropped_for_depth_against_later_baked_art`, `placing_symbols_keeps_the_baked_art_within_the_drawn_depth`, `placing_symbols_skips_instances_the_export_leaves_out`; doc `depth::tests::drawn_heights_measure_objects_outside_the_layers`; PDF, print, EPS and DXF `symbol_art_effects_are_written_where_they_draw`, `symbol_art_effects_print_where_they_draw`; PDF `a_stained_instance_keeps_its_stain_when_its_art_has_effects`, `a_linked_instance_keeps_its_link_when_its_art_has_effects`). EMF, WMF and SVG export write the same symbol art the same way: an instance of a symbol whose art, or the art of a symbol nested in it, has such effects is written as that art placed by the instance and then baked, so a square that a Transform effect moves 100 pt right draws 100 pt right of where the instance places it at any scale or rotation, and art the effect moves onto the artboard is written. EMF and SVG clip 9-slice cells and WMF does not, as each places other instances. In SVG those instances use no ``, and instances of symbols without such effects still share one; named objects in a symbol's art take no ids there, as in an instance with its own copy of the art, so two instances do not write the same id; with Hidden Layers on, hidden instances are placed too and written hidden. An SVG instance nested in another instance's art is shared through `` only when the transform it is drawn with, the outer instances' included, keeps the shared art as the canvas draws it, so a nested stroke keeps its weight in a scaled instance. Preserve Editing still embeds the document with its live effects. Before, these exports wrote the art without its effects (metafile `tests::import::symbol_art_effects_are_written_where_they_draw`; SVG `symbols_layers::symbol_art_effects_are_written_where_the_canvas_draws_them`, `a_kept_hidden_instance_is_written_with_its_symbols_effects`, `instances_written_as_their_art_give_its_names_no_id`, `a_nested_instance_is_shared_only_under_the_transform_it_is_drawn_with`; effects `bake::placing_symbols_skips_instances_the_export_leaves_out`). EMF and WMF export with Use Artboards applies the document's live effects once for all the chosen artboards instead of once for each, and writes the same files byte for byte (metafile `tests::export_regions_writes_what_each_region_writes_alone`; `export_regions_perf` times it). From b06bccfaebab42ace4c09bd1f3a889df455c14fb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 03:30:44 -0800 Subject: [PATCH 2/4] Symbols: picking and outlining a dynamic instance's part stays within one object limit Outlining a part of a dynamic symbol's instance expanded every nested instance whose fill or stroke effects reshape its art, at every level, with no limit, so art that nests many such instances a few levels deep took work that grew with each level. A part pick charged each object it tested but copied each nested instance's art before charging anything for it. The part outline now shares the object limit a click has, and each object it outlines takes one object of it. The art of a nested instance takes its size from the limit before it is copied, and the art an object's own effects draw takes its size once evaluated; nothing more is copied or evaluated once the limit is used up. The art of the instance itself is charged by its walk, as before. --- crates/doc/src/hit.rs | 73 ++++++++++++++++++++++++++----- crates/doc/src/hit/tests.rs | 85 +++++++++++++++++++++++++++++++++++-- 2 files changed, 145 insertions(+), 13 deletions(-) diff --git a/crates/doc/src/hit.rs b/crates/doc/src/hit.rs index 6286597882..6320be059d 100644 --- a/crates/doc/src/hit.rs +++ b/crates/doc/src/hit.rs @@ -1609,7 +1609,17 @@ fn painted_hit(painted: &Painted, p: Point, opt: HitOptions) -> Option /// is tested here. Never with `outline`, where the canvas draws no effects, nor while a /// [`DrawnOff`] guard lives. fn reshapes_instance_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> bool { - !outline && !DRAWN_OFF.get() && matches!(n.kind, NodeKind::SymbolInstance { .. }) && !image_paint(Some(symbols.document()), n).is_empty() + !outline + && !DRAWN_OFF.get() + && matches!(n.kind, NodeKind::SymbolInstance { .. }) + && n.appearance.items.iter().any(|i| !i.effects().is_empty()) + && !image_paint(Some(symbols.document()), n).is_empty() +} + +/// How many objects `n` holds with its opacity masks' art ([`Node::count_with_masks`]), what +/// testing or outlining it takes from the [`ArtWalk`] limit. +fn walk_size(n: &Node) -> u64 { + u64::try_from(n.count_with_masks()).unwrap_or(u64::MAX) } /// The art that symbol instance `n` draws with a visible effect of its own, the effects of its @@ -1617,17 +1627,28 @@ fn reshapes_instance_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> bool /// visible effects of its own and of its fills and strokes, as outlined paths ([`set_drawn_art`]). /// `None` for other objects, with `outline`, where the canvas draws no effects, for an instance or /// type without such an effect, while a [`DrawnOff`] guard lives, and when no geometry effect -/// changes what it draws. +/// changes what it draws. Evaluating the art is work that walking it does not count, so the art +/// takes its objects from the [`ArtWalk`] limit of the click or outline under way, and the walk of +/// it takes them again. Once the limit is used up, the result is `Some` of an empty group, which +/// hits and outlines nothing, and no more art is evaluated. fn own_effects_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> Option { let has = match n.kind { NodeKind::SymbolInstance { .. } => n.appearance.effects.iter().any(|e| e.visible), NodeKind::Text(_) => has_own_effects(n), _ => false, }; - if outline || DRAWN_OFF.get() || !has { + if outline || DRAWN_OFF.get() || !has || DRAWN_ART.get().is_none() { return None; } - DRAWN_ART.get()?(symbols, n) + let nothing = || Some(Node::group(n.id, vec![])); + if ArtWalk::used_up() { + return nothing(); + } + let art = DRAWN_ART.get()?(symbols, n)?; + if !ArtWalk::take(walk_size(&art)) { + return nothing(); + } + Some(art) } /// Is `p` within `tol` of the type path of `t` (in `n`), what "Type Object Selection by Path @@ -1744,12 +1765,36 @@ impl<'a> InstanceArt<'a> { /// outlined where the canvas draws it. Not with `outline`, where the canvas draws no effects. fn drawn(doc: &'a Document, inst: &Node, outline: bool) -> Option { let mut art = Self::of(doc, inst)?; + #[cfg(test)] + ARTS_WALKED.with(|c| c.set(c.get() + 1)); if !outline && let Some(f) = INSTANCE_ROW_ART.get() { f(Some(doc), inst, &mut art.art); } Some(art) } + /// [`Self::drawn`] for symbol instance `inst` in the art of another instance, outside Outline. + /// Copying the art and adding the effects to it is work that walking it does not count, so the + /// art takes as many objects as placing it makes ([`Self::size`]) from the [`ArtWalk`] limit of + /// the click or outline under way before it is copied, as the marquee takes the art it places, + /// and the walk of it takes its objects again. `None` once fewer are left. + fn nested(doc: &'a Document, inst: &Node) -> Option { + if ArtWalk::used_up() { + return None; + } + let NodeKind::SymbolInstance { symbol, xf } = &inst.kind else { return None }; + let boxes = doc.symbol_boxes().quick(); + let source = boxes.symbol_art(symbol)?; + let size = match boxes.slice_map(symbol, *xf) { + Some(m) => m.most_placed_with(source, &boxes), + None => walk_size(source), + }; + if !ArtWalk::take(size) { + return None; + } + Self::drawn(doc, inst, false) + } + /// The map that the objects inside group or layer `n` are moved by as one piece: `whole`, the /// map of an object around `n` that is moved as one piece, or else the map of the 9-slice cell /// `n` lies in ([`crate::NineSliceMap::one_cell`]). `None` when `n` is placed through the guides @@ -1958,7 +2003,7 @@ fn drawn_instance_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes if symbols.art(symbol).is_none() || ArtWalk::used_up() { return None; } - let art = InstanceArt::drawn(symbols.document(), n, false)?; + let art = InstanceArt::nested(symbols.document(), n)?; let opt = HitOptions { clip_outlines: false, ..opt }; let _art_only = ArtOnly::set(); FindPart { art: &art, p, opt, symbols, whole_instance: true, drawn: true }.find(&art.art, &mut vec![], None, false) @@ -2112,8 +2157,11 @@ pub fn symbol_part_outline(doc: &Document, inst: &Node, path: &[u32]) -> Option< /// outlines are cut to the bounds of the plain clipping paths, without their live effects, as /// [`symbol_part_at`] counts them. The outline is empty when the effects of a clipping path around /// the object leave no region. Elsewhere the outlines follow the geometry effects of the instance's -/// active fill and stroke, as [`symbol_part_at`] does. +/// active fill and stroke, as [`symbol_part_at`] does. Outlining visits at most as many objects of +/// symbol art as one click does ([`ArtWalk`]), the art of the instances nested in the part included, +/// and leaves out what is past that limit. pub fn symbol_part_outline_in_view(doc: &Document, inst: &Node, path: &[u32], opt: HitOptions) -> Option { + let _walk = ArtWalk::open(); let mut outline = opt.outline || below_preview_off(doc, inst, opt.scope); let art = InstanceArt::drawn(doc, inst, outline)?; let part = crate::symbol_overrides::part(&art.art, path)?; @@ -2164,11 +2212,16 @@ fn limit_within(clip: &Node, limit: Option, outline: bool) -> Option, outline: bool, out: &mut BezPath) { use vectorcraft_geom::kurbo::Shape; + if !ArtWalk::take(1) { + return; + } if matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) && let Some(art) = drawn_art(symbols, n, outline) { @@ -2185,7 +2238,7 @@ fn outline_within(n: &Node, symbols: &SymbolBoxes, limit: Option, outline: && reshapes_instance_art(n, symbols, outline) { if symbols.art(symbol).is_some() - && let Some(art) = InstanceArt::drawn(symbols.document(), n, false) + && let Some(art) = InstanceArt::nested(symbols.document(), n) && let Some(placed) = art.place(&art.art, None) { outline_within(&placed, symbols, limit, outline, out); diff --git a/crates/doc/src/hit/tests.rs b/crates/doc/src/hit/tests.rs index ad037931a0..7c704511c3 100644 --- a/crates/doc/src/hit/tests.rs +++ b/crates/doc/src/hit/tests.rs @@ -1324,11 +1324,11 @@ fn evaluated_art_is_not_kept_while_a_placed_document_may_show_in_it() { assert_eq!(evaluated(), before + 2); } -/// For instances of the symbol "Painted", a fill that paints the square from (300, 0) to -/// (320, 20); nothing for anything else. +/// For instances of the symbols whose names start with "Painted", a fill that paints the square +/// from (300, 0) to (320, 20); nothing for anything else. fn painted_far_away(_: Option<&Document>, n: &Node) -> Vec<(BezPath, FillRule, AppearanceItem)> { match &n.kind { - NodeKind::SymbolInstance { symbol, .. } if symbol == "Painted" => { + NodeKind::SymbolInstance { symbol, .. } if symbol.starts_with("Painted") => { let square = shapes::rectangle(Rect::new(300.0, 0.0, 320.0, 20.0)).to_bezpath(); vec![(square, FillRule::NonZero, AppearanceItem::Fill(crate::FillLayer::new(Paint::solid(Color::rgb(1.0, 0.0, 0.0)))))] } @@ -3041,6 +3041,85 @@ fn a_click_counts_the_members_of_an_intertwine_group_in_symbol_art_toward_one_li assert_eq!(with_art_limit(100, || at(140.0)).0, Some(id), "on the squares' paths"); } +/// An instance of the symbol named `symbol`, not moved, whose fill has a geometry effect: +/// [`painted_far_away`] gives it shapes when the name starts with "Painted", so a part pick and a +/// part outline walk its art as drawn with its fill's effects ([`InstanceArt::drawn`]). +fn painted_instance_of(d: &mut Document, symbol: &str) -> Arc { + let mut n = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: symbol.into(), xf: vectorcraft_geom::Affine::IDENTITY }); + n.appearance = Appearance::default_art().into(); + let offset = crate::Effect { id: "path.offsetPath".into(), params: serde_json::json!({"offset": 10}), visible: true }; + n.appearance.items[0].effects_mut().push(offset); + Arc::new(n) +} + +/// Five levels of symbols: "Painted 0" is a 1 pt square, and each level above holds 8 instances +/// of the level below whose fills have a geometry effect. Returns the id of an instance of +/// "Painted 4" on the layer. +fn painted_chain(d: &mut Document) -> NodeId { + let l = d.layers[0].id; + let dot = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 1.0, 1.0)), Appearance::default_art()); + d.symbols.push(crate::Symbol { dynamic: false, name: "Painted 0".into(), art: Arc::new(dot) }); + for level in 1..5 { + let members = (0..8).map(|_| painted_instance_of(d, &format!("Painted {}", level - 1))).collect(); + group_symbol(d, &format!("Painted {level}"), members); + } + let inst = instance_of(d, "Painted 4"); + let id = inst.id; + d.insert(Some(l), 0, Arc::unwrap_or_clone(inst)).unwrap(); + id +} + +/// The outline of a part of a dynamic symbol's instance visits at most the art walk's limit of +/// objects, though the part is an instance whose art, drawn with its fill's effects, nests +/// instances 3 levels deep, 8 at each level. Within the limit every square is outlined. +#[test] +fn a_parts_outline_walks_nested_reshaped_symbol_instances_within_one_limit() { + set_image_paint(painted_far_away); + let mut d = Document::new(600.0, 400.0); + let id = painted_chain(&mut d); + let n = d.node(id).unwrap(); + let squares = |o: &BezPath| o.elements().iter().filter(|e| matches!(e, vectorcraft_geom::kurbo::PathEl::MoveTo(_))).count(); + // Part [0] is an instance of "Painted 3": 8 × 8 × 8 squares. + assert_eq!(squares(&symbol_part_outline(&d, n, &[0]).unwrap()), 512, "within the limit"); + let (outline, _, arts) = with_art_limit(100, || symbol_part_outline(&d, n, &[0]).unwrap()); + assert!(squares(&outline) < 100, "{} squares outlined", squares(&outline)); + assert!(arts < 100, "{arts} instances' art walked"); +} + +/// A part pick in a dynamic symbol's instance visits at most the art walk's limit of objects of +/// nested instances whose art, drawn with their fills' effects, is walked: in a chain of nested +/// instances, and in instances whose clip groups the click misses, where only the clip group +/// itself is tested. A click on the clipped art of a nested instance is still found. +#[test] +fn a_part_pick_walks_nested_reshaped_symbol_instances_within_one_limit() { + set_image_paint(painted_far_away); + let mut d = Document::new(600.0, 400.0); + let id = painted_chain(&mut d); + let opt = HitOptions::default(); + let (hit, _, arts) = with_art_limit(100, || symbol_part_at(&d, d.node(id).unwrap(), Point::new(150.0, 50.0), opt)); + assert_eq!(hit, None); + assert!(arts <= 40, "chain: {arts} instances' art walked"); + // 30 instances of a clip group whose 10 pt clipping path holds 40 squares: 42 objects each. + let mut d = Document::new(600.0, 400.0); + let l = d.layers[0].id; + let mask = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 10.0, 10.0)), Appearance::default()); + let mut members = vec![Arc::new(mask)]; + members.extend((0..40).map(|_| Arc::new(Node::path(d.alloc_id(), shapes::rectangle(Rect::new(0.0, 0.0, 5.0, 5.0)), Appearance::default_art())))); + let mut clip = Node::group(d.alloc_id(), members); + clip.set_clips(true); + d.symbols.push(crate::Symbol { dynamic: false, name: "Painted clip".into(), art: Arc::new(clip) }); + let members = (0..30).map(|_| painted_instance_of(&mut d, "Painted clip")).collect(); + group_symbol(&mut d, "Clips", members); + let inst = instance_of(&mut d, "Clips"); + let id = inst.id; + d.insert(Some(l), 0, Arc::unwrap_or_clone(inst)).unwrap(); + let n = d.node(id).unwrap(); + let (hit, _, arts) = with_art_limit(300, || symbol_part_at(&d, n, Point::new(150.0, 50.0), opt)); + assert_eq!(hit, None); + assert!(arts <= 8, "clip groups: {arts} instances' art walked"); + assert_eq!(with_art_limit(300, || symbol_part_at(&d, n, Point::new(2.0, 2.0), opt)).0, Some(vec![29]), "the clipped art"); +} + /// In a dynamic symbol's art that placing through its 9-slice guides could make more than /// [`crate::MAX_SYMBOL_NODES`] objects of, Direct Selection picks and outlines nothing, as the /// canvas draws nothing of it. At the art's natural size the same art is picked. From 05d5befece364ebcc9bf19df82fdf59f745db832 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 04:09:01 -0800 Subject: [PATCH 3/4] Symbols: Direct Selection follows a nested instance of a clip group moved by the instance's fill effects A symbol instance nested in a dynamic symbol's art was picked and outlined where its art is drawn only when the shapes its fill and stroke paint were non-empty. Those shapes leave out clip groups and type, so a nested instance whose art is a clip group was picked at its plain place although the canvas draws its members moved by the outer instance's fill or stroke effects. The test is now whether the nested instance's active fill or stroke has a visible geometry effect, which the engine registers with set_instance_reshapes. Picks and outlines no longer evaluate those shapes for each nested instance they visit. --- crates/doc/src/hit.rs | 29 ++++++++++++++++------ crates/doc/src/hit/tests.rs | 10 +++++++- crates/engine/src/session/documents.rs | 1 + crates/engine/src/tests/dynamic_symbols.rs | 26 +++++++++++++++++++ 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/crates/doc/src/hit.rs b/crates/doc/src/hit.rs index 6320be059d..6507112c24 100644 --- a/crates/doc/src/hit.rs +++ b/crates/doc/src/hit.rs @@ -131,6 +131,20 @@ pub fn set_instance_row_art(f: InstanceRowArt) { let _ = INSTANCE_ROW_ART.set(f); } +/// Does a symbol instance's active fill or stroke carry a visible geometry effect, which the art it +/// places takes on each of its fills and strokes ([`set_instance_row_art`])? Effects are classified +/// above this crate, so the engine registers one with [`set_instance_reshapes`]. +pub type InstanceReshapes = fn(&Node) -> bool; + +static INSTANCE_RESHAPES: OnceLock = OnceLock::new(); + +/// Register how Direct Selection tells whether a symbol instance's fill or stroke effects reshape +/// its art (the first registration stays). +pub fn set_instance_reshapes(f: InstanceReshapes) { + // Already set: the same engine, registered by another session. + let _ = INSTANCE_RESHAPES.set(f); +} + /// The shapes that [`ImagePaint`] gives for one object. type Painted = Vec<(BezPath, FillRule, AppearanceItem)>; @@ -1603,17 +1617,18 @@ fn painted_hit(painted: &Painted, p: Point, opt: HitOptions) -> Option }) } -/// Is `n` a symbol instance whose active fill or stroke has geometry effects that reshape the art -/// it draws ([`image_paint`])? Callers ask [`own_effects_art`] first, which takes an instance whose +/// Is `n` a symbol instance whose active fill or stroke has a visible geometry effect, which +/// reshapes the art it draws ([`set_instance_reshapes`])? This holds whatever that art is, clip +/// groups and type included. Callers ask [`own_effects_art`] first, which takes an instance whose /// own effects change what it draws; an instance whose own effects add only pixels (a drop shadow) /// is tested here. Never with `outline`, where the canvas draws no effects, nor while a -/// [`DrawnOff`] guard lives. -fn reshapes_instance_art(n: &Node, symbols: &SymbolBoxes, outline: bool) -> bool { +/// [`DrawnOff`] guard lives, nor while nothing is registered. +fn reshapes_instance_art(n: &Node, outline: bool) -> bool { !outline && !DRAWN_OFF.get() && matches!(n.kind, NodeKind::SymbolInstance { .. }) && n.appearance.items.iter().any(|i| !i.effects().is_empty()) - && !image_paint(Some(symbols.document()), n).is_empty() + && INSTANCE_RESHAPES.get().is_some_and(|f| f(n)) } /// How many objects `n` holds with its opacity masks' art ([`Node::count_with_masks`]), what @@ -1905,7 +1920,7 @@ impl FindPart<'_> { let _art_only = ArtOnly::set(); return hit_any(&art, self.p, opt, self.symbols); } - if reshapes_instance_art(&placed, self.symbols, opt.outline) { + if reshapes_instance_art(&placed, opt.outline) { return drawn_instance_hit(&placed, self.p, opt, self.symbols); } } @@ -2235,7 +2250,7 @@ fn outline_within(n: &Node, symbols: &SymbolBoxes, limit: Option, outline: return; } if let NodeKind::SymbolInstance { symbol, .. } = &n.kind - && reshapes_instance_art(n, symbols, outline) + && reshapes_instance_art(n, outline) { if symbols.art(symbol).is_some() && let Some(art) = InstanceArt::nested(symbols.document(), n) diff --git a/crates/doc/src/hit/tests.rs b/crates/doc/src/hit/tests.rs index 7c704511c3..ea38de43b8 100644 --- a/crates/doc/src/hit/tests.rs +++ b/crates/doc/src/hit/tests.rs @@ -3041,8 +3041,14 @@ fn a_click_counts_the_members_of_an_intertwine_group_in_symbol_art_toward_one_li assert_eq!(with_art_limit(100, || at(140.0)).0, Some(id), "on the squares' paths"); } +/// Whether a symbol instance's fill or stroke effects reshape its art, for these tests: when +/// [`painted_far_away`] gives it shapes. +fn reshapes_when_painted(n: &Node) -> bool { + !painted_far_away(None, n).is_empty() +} + /// An instance of the symbol named `symbol`, not moved, whose fill has a geometry effect: -/// [`painted_far_away`] gives it shapes when the name starts with "Painted", so a part pick and a +/// [`reshapes_when_painted`] holds for it when the name starts with "Painted", so a part pick and a /// part outline walk its art as drawn with its fill's effects ([`InstanceArt::drawn`]). fn painted_instance_of(d: &mut Document, symbol: &str) -> Arc { let mut n = Node::new(d.alloc_id(), NodeKind::SymbolInstance { symbol: symbol.into(), xf: vectorcraft_geom::Affine::IDENTITY }); @@ -3075,6 +3081,7 @@ fn painted_chain(d: &mut Document) -> NodeId { #[test] fn a_parts_outline_walks_nested_reshaped_symbol_instances_within_one_limit() { set_image_paint(painted_far_away); + set_instance_reshapes(reshapes_when_painted); let mut d = Document::new(600.0, 400.0); let id = painted_chain(&mut d); let n = d.node(id).unwrap(); @@ -3093,6 +3100,7 @@ fn a_parts_outline_walks_nested_reshaped_symbol_instances_within_one_limit() { #[test] fn a_part_pick_walks_nested_reshaped_symbol_instances_within_one_limit() { set_image_paint(painted_far_away); + set_instance_reshapes(reshapes_when_painted); let mut d = Document::new(600.0, 400.0); let id = painted_chain(&mut d); let opt = HitOptions::default(); diff --git a/crates/engine/src/session/documents.rs b/crates/engine/src/session/documents.rs index 0272e8fb76..1685adc40f 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine/src/session/documents.rs @@ -27,6 +27,7 @@ impl Session { // Direct Selection picks and outlines the parts of a dynamic symbol's instance where the // effects of the instance's fill and stroke draw them. vectorcraft_doc::hit::set_instance_row_art(vectorcraft_render::effects::add_instance_row_effects_to_parts); + vectorcraft_doc::hit::set_instance_reshapes(vectorcraft_render::effects::has_item_geometry); // Clicks inside a clip group fall in the region its clipping path's effects give it. vectorcraft_doc::hit::set_clip_region(vectorcraft_render::effects::reshaped_clip_outline); // Clicks and marquees find paths, compound paths, groups and layers where their geometry diff --git a/crates/engine/src/tests/dynamic_symbols.rs b/crates/engine/src/tests/dynamic_symbols.rs index 6f4973cd15..fc1305a0a7 100644 --- a/crates/engine/src/tests/dynamic_symbols.rs +++ b/crates/engine/src/tests/dynamic_symbols.rs @@ -741,6 +741,32 @@ fn a_picked_clipping_path_is_outlined_by_its_own_geometry() { assert!((b.x0 - 10.0).abs() < 0.5 && (b.x1 - 50.0).abs() < 0.5, "the clipping path's own edge: {b:?}"); } +/// A symbol instance in a dynamic symbol's art whose own art is a clip group takes the instance's +/// fill effect on the clip group's members, which the canvas draws moved: Direct Selection picks it +/// where its member is drawn, not where the member's own shape is, and outlines it there. +#[test] +fn a_nested_instance_of_a_clip_group_is_picked_where_the_fill_effect_draws_its_art() { + use vectorcraft_doc::hit::HitOptions; + let opt = HitOptions { tol: 1.0, ..Default::default() }; + let mut s = session(); + let content = square(&mut s, 10.0); + let clip = id(&s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 200, "height": 60})).unwrap()); + s.execute("object.clippingMask.make", &json!({"ids": [content.0, clip.0]})).unwrap(); + let group = top(&s); + assert!(node(&s, group).clips()); + let inner = id(&s.execute("symbol.new", &json!({"name": "Inner", "ids": [group.0]})).unwrap()); + let b = square(&mut s, 160.0); + let inst = id(&s.execute("symbol.new", &json!({"name": "Outer", "ids": [inner.0, b.0], "type": "dynamic"})).unwrap()); + row_effect(&mut s, inst, true, "distort.transform", json!({"moveH": 100})); + // The member is drawn at x 110..150, inside the clipping path. + assert_eq!(pixel(&s, 130, 30), BLUE, "the canvas draws the member moved"); + assert_ne!(pixel(&s, 30, 30), BLUE, "and not in its own place"); + assert_eq!(part_at(&s, inst, (130.0, 30.0), opt), Some(vec![0]), "the nested instance where its member is drawn"); + assert_eq!(part_at(&s, inst, (30.0, 30.0), opt), None, "the member's own place"); + let o = part_outline_box(&s, inst, &[0]); + assert!((o.x0 - 110.0).abs() < 0.5 && (o.x1 - 150.0).abs() < 0.5, "the outline follows the moved member: {o:?}"); +} + #[test] fn a_drag_of_a_picked_object_moves_nothing_and_says_why() { let mut s = session(); From d54cbce77875bcc4ccfeccf3941f771514b3e744 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 04:52:00 -0800 Subject: [PATCH 4/4] Symbols: a part's outline leaves out hidden art of instances nested in it The outline of a dynamic instance's part walked the art of an instance nested in the part, drawn with that instance's fill and stroke effects, and outlined its hidden objects as well. It now skips a hidden object and what it holds, as the part pick does. --- crates/doc/src/hit.rs | 4 ++-- crates/doc/src/hit/tests.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/doc/src/hit.rs b/crates/doc/src/hit.rs index 6507112c24..93a13296de 100644 --- a/crates/doc/src/hit.rs +++ b/crates/doc/src/hit.rs @@ -2231,10 +2231,10 @@ fn limit_within(clip: &Node, limit: Option, outline: bool) -> Option