From 2d0389c8fdf0042820ba5d4483555e81dcb83e4c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 14:44:44 -0800 Subject: [PATCH 1/2] Gradient: moving out of a freeform object ends the Lines mode line In freeform Lines mode, moving the pointer out of the object and back now ends the line being drawn, so the next click on the object starts a new line. The help page describes this way of starting another line in the same object: https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=262 The line ends on the first pointer move, with no button held, that leaves the object. The object counts as its path's area inside any clipping masks above it, plus its own painted art (stroke, glyphs); other art lying over it does not end the line, and outline view, a layer with Preview off and the path-only selection preferences do not shrink the area. Escape and a click off the art still end the line. --- crates/tools/src/xform/freeform.rs | 160 +++++++++++++++++++++++++++-- docs/target-app-parity.md | 1 + 2 files changed, 154 insertions(+), 7 deletions(-) diff --git a/crates/tools/src/xform/freeform.rs b/crates/tools/src/xform/freeform.rs index 89c6faa933..8a5a461a2b 100644 --- a/crates/tools/src/xform/freeform.rs +++ b/crates/tools/src/xform/freeform.rs @@ -8,14 +8,15 @@ //! //! Points mode (the Gradient panel's Draw toggle): a click inside the selected art adds a point //! there, coloured as the gradient is there. Lines mode: successive clicks draw a smooth line -//! through the points they add, until Escape (or a click off the art) ends it; clicking an -//! existing point first starts the line from it. Delete or Backspace removes the selected point. +//! through the points they add, until Escape, a click off the art or moving the pointer out of +//! the object ends it; clicking an existing point first starts the line from it. Delete or +//! Backspace removes the selected point. use serde_json::{Value, json}; use vectorcraft_color::freeform::LineHit; use vectorcraft_color::{Color, Freeform, FreeformMode, FreeformPoint}; use vectorcraft_doc::NodeId; -use vectorcraft_doc::hit::hit_test; +use vectorcraft_doc::hit::{HitOptions, hit_test, hit_test_visible_skipping}; use vectorcraft_geom::{Point, Shape, Vec2}; use super::paint_owner; @@ -183,6 +184,43 @@ fn on_art(cx: &ToolContext, p: Point) -> bool { hit_test(cx.doc, p, cx.hit_options()).is_some_and(|h| cx.selection.objects.contains(&paint_owner(cx.doc, h.leaf))) } +/// Is `p` on object `id`: inside its path's area (where a dragged point stays) and every clipping +/// mask above it, or on its own art where a click hits it with the art lying over it left out (a +/// stroke, type's glyphs)? +fn on_object(cx: &ToolContext, id: NodeId, p: Point) -> bool { + let Some(n) = cx.doc.node(id) else { return false }; + let ancestry = cx.doc.ancestry(id).unwrap_or_default(); + let contains = |shapes: &[(vectorcraft_geom::BezPath, vectorcraft_geom::FillRule)]| { + shapes.iter().any(|(bp, rule)| vectorcraft_geom::hit::fill_contains(bp, *rule, p)) + }; + // A mask with a live effect clips by the effect's result, which the hit test below measures. + let plain = |clip: &vectorcraft_doc::Node| { + let mut effects = false; + clip.walk(&mut |c| { + effects |= c.appearance.effects.iter().any(|e| e.visible) || c.appearance.items.iter().any(|i| i.effects().iter().any(|e| e.visible)); + }); + !effects + }; + let unmasked = || { + ancestry.iter().filter_map(|a| cx.doc.node(*a)).filter(|a| a.clips()).all(|a| { + a.children() + .and_then(|c| c.first()) + .is_none_or(|clip| clip.id == id || plain(clip) && contains(&vectorcraft_doc::hit::clip_regions(clip))) + }) + }; + if contains(&n.clip_shapes(None)) && unmasked() { + return true; + } + let mut keep = std::collections::HashSet::new(); + n.walk(&mut |c| { + keep.insert(c.id); + }); + keep.extend(ancestry); + // The art as painted, whatever the view and the path-only selection preferences. + let opt = HitOptions { outline: false, path_only: false, type_path_only: false, ..cx.hit_options() }; + hit_test_visible_skipping(cx.doc, p, opt, &|n| !keep.contains(&n)).is_some_and(|h| h.leaf == id || h.ancestry.contains(&id)) +} + pub(super) fn press(cx: &ToolContext, a: &Annotator, p: Point) -> (Vec, Gesture) { let mut out = vec![]; let grab = if let Some(i) = a.point_at(cx, p) { @@ -293,8 +331,13 @@ pub(super) fn double_click(cx: &ToolContext, a: &Annotator, p: Point) -> Vec Date: Fri, 20 Nov 2026 17:07:31 -0800 Subject: [PATCH 2/2] Gradient: a freeform line stays open over its object's stroke on a layer with Preview off The check for whether the pointer is still on the object hit the object's painted art with outline off, but the hit test turned outline back on for a layer with Preview off, so a move onto the stroke past the fill ended the line. A new HitOptions field, ignore_layer_preview, keeps the point hit tests from switching to outline for such layers, and the freeform check sets it. the_stroke_counts_as_the_object now runs with the layer's Preview on and off. --- crates/doc/src/hit.rs | 12 ++++++-- crates/doc/src/hit/tests.rs | 1 + crates/tools/src/context.rs | 1 + crates/tools/src/xform/freeform.rs | 44 ++++++++++++++++++------------ 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/crates/doc/src/hit.rs b/crates/doc/src/hit.rs index fcbe2f9db1..7c0de44cab 100644 --- a/crates/doc/src/hit.rs +++ b/crates/doc/src/hit.rs @@ -78,6 +78,9 @@ pub struct HitOptions { /// Off, the empty part of the frame (away from its edge and its lines of type) takes no /// clicks, so they reach the art behind (#7274). pub area_type_interior: bool, + /// The point hit tests ([`hit_test`], [`hit_test_visible`] and [`hit_test_visible_skipping`]) + /// hit the art on a layer whose Preview is off as painted, not in outline. + pub ignore_layer_preview: bool, } impl Default for HitOptions { @@ -90,6 +93,7 @@ impl Default for HitOptions { skip_guides: false, clip_outlines: false, area_type_interior: false, + ignore_layer_preview: false, scope: None, } } @@ -847,7 +851,7 @@ fn hit_test_skipping(doc: &Document, p: Point, opt: HitOptions, skip: &dyn Fn(No continue; } chain.push(layer.id); - let opt = if matches!(layer.kind, NodeKind::Layer { preview: false, .. }) { HitOptions { outline: true, ..opt } } else { opt }; + let opt = if !opt.ignore_layer_preview && previews_off(layer) { HitOptions { outline: true, ..opt } } else { opt }; if let Some(h) = hit_children(layer, p, opt, &symbols, skip, &mut chain, editable_only) { return Some(finish(h)); } @@ -1211,7 +1215,9 @@ fn hit_children( chain.push(c.id); let hit = plain(i == 0 && clip.is_some(), || match &c.kind { // A sublayer whose Preview is off is clicked in outline, like an outline view. - NodeKind::Layer { preview: false, .. } => hit_children(c, p, HitOptions { outline: true, ..opt }, symbols, skip, chain, editable_only), + NodeKind::Layer { preview: false, .. } if !opt.ignore_layer_preview => { + hit_children(c, p, HitOptions { outline: true, ..opt }, symbols, skip, chain, editable_only) + } NodeKind::Layer { .. } | NodeKind::Group { .. } | NodeKind::Intertwine { .. } => { hit_children(c, p, opt, symbols, skip, chain, editable_only) } @@ -1325,7 +1331,7 @@ fn art_hit(n: &Node, p: Point, opt: HitOptions, symbols: &SymbolBoxes, accept: & match &n.kind { NodeKind::Group { children, .. } | NodeKind::Layer { children, .. } | NodeKind::Intertwine { children } => { // A layer with Preview off is clicked in outline, as [`hit_children`] clicks it. - let opt = HitOptions { outline: opt.outline || previews_off(n), ..opt }; + let opt = HitOptions { outline: opt.outline || !opt.ignore_layer_preview && previews_off(n), ..opt }; if n.clips() && let Some(clip) = children.first() { diff --git a/crates/doc/src/hit/tests.rs b/crates/doc/src/hit/tests.rs index e94b2b8ba8..ad037931a0 100644 --- a/crates/doc/src/hit/tests.rs +++ b/crates/doc/src/hit/tests.rs @@ -1463,6 +1463,7 @@ const SELECTING: HitOptions = HitOptions { skip_guides: false, clip_outlines: true, area_type_interior: false, + ignore_layer_preview: false, scope: None, }; diff --git a/crates/tools/src/context.rs b/crates/tools/src/context.rs index 50553a87bc..1a37860179 100644 --- a/crates/tools/src/context.rs +++ b/crates/tools/src/context.rs @@ -451,6 +451,7 @@ impl ToolContext<'_> { skip_guides: !self.guides, clip_outlines: false, area_type_interior: false, + ignore_layer_preview: false, } } diff --git a/crates/tools/src/xform/freeform.rs b/crates/tools/src/xform/freeform.rs index 8a5a461a2b..3e3eef28b2 100644 --- a/crates/tools/src/xform/freeform.rs +++ b/crates/tools/src/xform/freeform.rs @@ -216,8 +216,9 @@ fn on_object(cx: &ToolContext, id: NodeId, p: Point) -> bool { keep.insert(c.id); }); keep.extend(ancestry); - // The art as painted, whatever the view and the path-only selection preferences. - let opt = HitOptions { outline: false, path_only: false, type_path_only: false, ..cx.hit_options() }; + // The art as painted, whatever the view, the layers' Preview and the path-only selection + // preferences. + let opt = HitOptions { outline: false, path_only: false, type_path_only: false, ignore_layer_preview: true, ..cx.hit_options() }; hit_test_visible_skipping(cx.doc, p, opt, &|n| !keep.contains(&n)).is_some_and(|h| h.leaf == id || h.ancestry.contains(&id)) } @@ -530,23 +531,32 @@ mod tests { } /// The object's stroke is part of the object: moving onto it past the filled area keeps the - /// line open, and moving past the stroke ends it. + /// line open, and moving past the stroke ends it. The same holds on a layer with Preview off. #[test] fn the_stroke_counts_as_the_object() { - let (mut d, s) = doc(FreeformMode::Lines); - let id = s.objects[0]; - d.node_mut(id).unwrap().appearance.stroke_mut().unwrap().width = 20.0; - let p = paint(); - let mut cx = cx(&d, &s, &p); - let mut t = GradientTool::default(); - let add = |x: f64, y: f64, line: bool| Action::Exec("paint.freeform.addPoint".into(), json!({"at": [x, y], "line": line, "stroke": false})); - assert_eq!(click(&mut t, &cx, 140.0, 150.0), vec![add(140.0, 150.0, false)]); - cx.freeform_point = Some(2); - t.pointer(&cx, &ev(PointerKind::Move, 206.0, 150.0)); - assert!(t.claims_key(&cx, ToolKey::Escape), "on the stroke the line stays open"); - assert_eq!(click(&mut t, &cx, 160.0, 150.0), vec![add(160.0, 150.0, true)]); - t.pointer(&cx, &ev(PointerKind::Move, 230.0, 150.0)); - assert!(!t.claims_key(&cx, ToolKey::Escape), "past the stroke the line has ended"); + for preview in [true, false] { + let (mut d, s) = doc(FreeformMode::Lines); + let id = s.objects[0]; + d.node_mut(id).unwrap().appearance.stroke_mut().unwrap().width = 20.0; + let l = d.layers[0].id; + if let vectorcraft_doc::NodeKind::Layer { preview: p, .. } = &mut d.node_mut(l).unwrap().kind { + *p = preview; + } + let p = paint(); + let mut cx = cx(&d, &s, &p); + let mut t = GradientTool::default(); + cx.freeform_point = Some(2); + // The line starts from the existing point. + assert!(click(&mut t, &cx, 150.0, 180.0).is_empty()); + t.pointer(&cx, &ev(PointerKind::Move, 206.0, 150.0)); + assert!(t.claims_key(&cx, ToolKey::Escape), "on the stroke the line stays open (Preview {preview})"); + if preview { + let add = Action::Exec("paint.freeform.addPoint".into(), json!({"at": [160.0, 150.0], "line": true, "stroke": false})); + assert_eq!(click(&mut t, &cx, 160.0, 150.0), vec![add]); + } + t.pointer(&cx, &ev(PointerKind::Move, 230.0, 150.0)); + assert!(!t.claims_key(&cx, ToolKey::Escape), "past the stroke the line has ended (Preview {preview})"); + } } /// In a clipping mask, the part of the object the mask hides is outside it: moving there ends