Merge pull request #8861 from dotCooCoo/feat/freeform-lines-leave-ends-line

Gradient: moving out of a freeform object ends the Lines mode line
This commit is contained in:
BFlat
2026-11-21 10:33:27 +07:00
committed by GitHub
5 changed files with 175 additions and 10 deletions
+9 -3
View File
@@ -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()
{
+1
View File
@@ -1463,6 +1463,7 @@ const SELECTING: HitOptions = HitOptions {
skip_guides: false,
clip_outlines: true,
area_type_interior: false,
ignore_layer_preview: false,
scope: None,
};
+1
View File
@@ -451,6 +451,7 @@ impl ToolContext<'_> {
skip_guides: !self.guides,
clip_outlines: false,
area_type_interior: false,
ignore_layer_preview: false,
}
}
+163 -7
View File
@@ -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,44 @@ 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, 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))
}
pub(super) fn press(cx: &ToolContext, a: &Annotator, p: Point) -> (Vec<Action>, Gesture) {
let mut out = vec![];
let grab = if let Some(i) = a.point_at(cx, p) {
@@ -293,8 +332,13 @@ pub(super) fn double_click(cx: &ToolContext, a: &Annotator, p: Point) -> Vec<Act
}
/// Pointer moves: Lines mode's rubber band follows the pointer over the art (where a click
/// extends the line).
/// extends the line). Moving out of the object ends the line, so the next click on the object
/// starts another; the object's own art counts (its fill, stroke or glyphs), also where other art
/// lies over it.
pub(super) fn hover(cx: &ToolContext, lines: &mut Lines, p: Point) {
if lines.open && Annotator::of(cx).is_some_and(|a| !on_object(cx, a.id, p)) {
lines.open = false;
}
lines.hover = (lines.open && on_art(cx, p)).then_some(p);
}
@@ -433,9 +477,7 @@ mod tests {
t.pointer(&cx, &ev(PointerKind::Move, 170.0, 160.0));
let dashed = |t: &GradientTool, cx: &ToolContext| t.overlays(cx).iter().filter(|o| matches!(o, Overlay::Path { dashed: true, .. })).count();
assert_eq!(dashed(&t, &cx), 2, "the rubber band and the selected point's spread ring");
// Off the art (where a click ends the line) it goes.
t.pointer(&cx, &ev(PointerKind::Move, 400.0, 400.0));
assert_eq!(dashed(&t, &cx), 1);
// A click inside the object extends the line.
assert_eq!(click(&mut t, &cx, 170.0, 160.0), vec![add(170.0, 160.0, true)]);
// Escape ends the line: the next click starts another.
assert!(t.key(&cx, ToolKey::Escape, Default::default()).is_empty());
@@ -452,6 +494,120 @@ mod tests {
assert!(!t.claims_key(&cx, ToolKey::Escape));
}
/// Moving the pointer out of the object and back ends Lines mode's line: the next click on
/// the object starts another. Moves inside the object, also over other art on top of it, keep
/// the line open.
#[test]
fn leaving_the_object_ends_the_line() {
let (mut d, s) = doc(FreeformMode::Lines);
// Unselected art over the object's lower right corner and past it.
let (l, top) = (d.layers[0].id, d.alloc_id());
let rect = vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(160.0, 160.0, 230.0, 230.0));
d.insert(Some(l), 1, vectorcraft_doc::Node::path(top, rect, vectorcraft_doc::Appearance::default_art())).unwrap();
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}));
let dashed = |t: &GradientTool, cx: &ToolContext| t.overlays(cx).iter().filter(|o| matches!(o, Overlay::Path { dashed: true, .. })).count();
assert_eq!(click(&mut t, &cx, 140.0, 150.0), vec![add(140.0, 150.0, false)]);
cx.freeform_point = Some(2);
// Inside the object, over the other art as well, the line stays open.
t.pointer(&cx, &ev(PointerKind::Move, 130.0, 130.0));
t.pointer(&cx, &ev(PointerKind::Move, 180.0, 190.0));
assert!(t.claims_key(&cx, ToolKey::Escape));
assert_eq!(click(&mut t, &cx, 150.0, 140.0), vec![add(150.0, 140.0, true)]);
// Out of the object (here still over the other art) and back: the line has ended.
t.pointer(&cx, &ev(PointerKind::Move, 210.0, 210.0));
assert!(!t.claims_key(&cx, ToolKey::Escape), "no line is left for Escape to end");
t.pointer(&cx, &ev(PointerKind::Move, 170.0, 130.0));
assert_eq!(dashed(&t, &cx), 1, "only the spread ring: no rubber band");
assert_eq!(click(&mut t, &cx, 170.0, 130.0), vec![add(170.0, 130.0, false)]);
// The next click joins the new line.
assert_eq!(click(&mut t, &cx, 130.0, 170.0), vec![add(130.0, 170.0, true)]);
// Out past an edge with no other art there ends it too.
t.pointer(&cx, &ev(PointerKind::Move, 60.0, 150.0));
t.pointer(&cx, &ev(PointerKind::Move, 140.0, 160.0));
assert_eq!(click(&mut t, &cx, 140.0, 160.0), vec![add(140.0, 160.0, false)]);
}
/// 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. The same holds on a layer with Preview off.
#[test]
fn the_stroke_counts_as_the_object() {
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
/// the line.
#[test]
fn the_part_a_mask_hides_is_off_the_object() {
use std::sync::Arc;
use vectorcraft_doc::{Appearance, Node, NodeKind};
let (d0, s0) = doc(FreeformMode::Lines);
let mut obj = d0.node(s0.objects[0]).unwrap().clone();
let mut d = Document::new(500.0, 500.0);
let l = d.layers[0].id;
let (group, clip, id) = (d.alloc_id(), d.alloc_id(), d.alloc_id());
obj.id = id;
let mask =
Node::path(clip, vectorcraft_geom::shapes::rectangle(vectorcraft_geom::Rect::new(100.0, 100.0, 160.0, 200.0)), Appearance::default_art());
d.insert(Some(l), 0, Node::new(group, NodeKind::Group { children: vec![Arc::new(mask), Arc::new(obj)], clip: true })).unwrap();
let mut s = Selection::default();
s.add(id);
let p = paint();
let mut cx = cx(&d, &s, &p);
cx.freeform_point = Some(2);
let mut t = GradientTool::default();
assert!(click(&mut t, &cx, 150.0, 180.0).is_empty());
t.pointer(&cx, &ev(PointerKind::Move, 130.0, 150.0));
assert!(t.claims_key(&cx, ToolKey::Escape), "inside the mask the line stays open");
t.pointer(&cx, &ev(PointerKind::Move, 185.0, 150.0));
assert!(!t.claims_key(&cx, ToolKey::Escape), "where the mask hides the object the line has ended");
}
/// Outline view, a layer with Preview off and Object Selection by Path Only don't shrink the
/// object to its path: a line started from a point stays open over the object's fill.
#[test]
fn the_fill_counts_in_outline_view_and_with_path_only_selection() {
let (mut d, s) = doc(FreeformMode::Lines);
let l = d.layers[0].id;
if let vectorcraft_doc::NodeKind::Layer { preview, .. } = &mut d.node_mut(l).unwrap().kind {
*preview = false;
}
let p = paint();
let mut cx = cx(&d, &s, &p);
(cx.outline, cx.path_only, cx.type_path_only) = (true, true, true);
cx.freeform_point = Some(2);
let mut t = GradientTool::default();
assert!(click(&mut t, &cx, 150.0, 180.0).is_empty());
t.pointer(&cx, &ev(PointerKind::Move, 140.0, 150.0));
assert!(t.claims_key(&cx, ToolKey::Escape), "over the fill the line stays open");
t.pointer(&cx, &ev(PointerKind::Move, 240.0, 150.0));
assert!(!t.claims_key(&cx, ToolKey::Escape), "off the object the line has ended");
}
/// A dropped click adds no point and leaves the line being drawn open: the next click still
/// joins it. A dropped drag of a point is canceled as by Escape.
#[test]
+1
View File
@@ -2053,6 +2053,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
Escape ends that eyedropper's pick, and Brush Options' Key Color pick, without sampling and returns to the tool that started it; the stop keeps its color, and Brush Options stays open with its Key Color until a new Escape cancels it (#8024, [Modify gradients, archived user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=264)).
Cmd/Ctrl-click on the Gradient panel's Gradient Fill box or on the Tools panel's Gradient button resets the gradient of the active Fill or Stroke to the linear White, Black gradient, as one undo step ([Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html)).
With a gradient stop or a freeform gradient point selected, Alt-clicking a color swatch in the Swatches panel recolors it instead of the inactive Fill or Stroke.
In the Gradient tool's freeform Lines mode, moving the pointer out of the object and back ends the line being drawn, and the next click on the object starts a new line from the point it adds. The help page describes this way of starting another line segment in the same object ([Create freeform gradient in lines mode](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=262)). As VectorCraft's own rules, the line ends as soon as the pointer, with no button held, moves off the object's own art, its fill, stroke or glyphs (other art lying over the object still counts as inside), and Escape and a click off the art still end it as before (`xform::freeform::tests::leaving_the_object_ends_the_line`).
- **Freeform gradient colors in their own model:** Object ▸ Expand and Object ▸ Create Gradient Mesh (`object.mesh.create`) mix a freeform gradient's points in the color model they share: points of C50 M20 Y0 K10 give mesh points of C50 M20 Y0 K10, and RGB points keep their values in a working RGB space other than sRGB. The canvas, the gradient chips and the SVG, PDF, EPS and EMF writers mix the points in that model too. PDF and EPS write a gradient whose points are all CMYK, or all Gray in a CMYK file, as a CMYK image, which PDF's Output settings convert as they convert any CMYK image. Points in different models mix in display RGB (on the canvas in a CMYK document that shows transparency, as the inks of each point), and a CMYK document stores the result of Expand as CMYK through the color settings. Points colored along CMYK stops (`paint.editGradient {stops}`, or a CMYK gradient switched to freeform) are CMYK, and so are a point `paint.freeform.splitLine` adds between CMYK points and a point `paint.freeform.addPoint` adds without `color` to CMYK points. Public reference: [Gradients](https://web.archive.org/web/20250714042311/https://helpx.adobe.com/illustrator/using/gradients.html) and [Meshes](https://web.archive.org/web/20250812201019/https://helpx.adobe.com/illustrator/using/meshes.html), which do not state how colors in different models mix; the rule is VectorCraft's own.
- **Strokes:** one stroke-geometry module shared by the canvas, SVG, PDF and Outline Stroke; dotted lines (zero-length dashes draw dots or squares); arrowheads with hollow outlines, tip-on-end or extend-past-end alignment and one opacity for line and head. SVG and PDF export arrowheads, width profiles, brushes and aligned strokes exactly as the canvas draws them; Outline Stroke and the live Outline Stroke effect outline every stroke item as drawn (dashes, heads, profiles, alignment); dashes can be fitted to corners and path ends; width profiles carry through dashes, and their corners take the join. The Stroke panel edits type's character strokes, follows the stroke units (its weight presets are round values in that unit: `0.25 mm`, `0.0625 in`, `1 px`, #426; fields show four decimals in mm, cm and inches, three in points), shows mixed values blank and opens from the Control bar. A width profile library, thirty-one more arrowheads (among them Line Arrow: two arms of the head's weight (stroke weight × arrowhead scale, at least 0.25 pt: the line's weight at 100 % for lines of 0.25 pt or more) at right angles, cut square, #5421), and Width Point Edit with multi-select and discontinuous points. Visual bounds and clicks cover the whole painted stroke. Scale Strokes & Effects, Scale Corners and Use Preview Bounds work everywhere, and new art inherits stroke options, a graphic style or the whole last appearance. A width profile's sides run as a smooth C1 curve between the width points (a monotone cubic Hermite, Fritsch–Carlson, with the one-sided three-point PCHIP slope at the profile's ends and flat either side of a step), sampled adaptively along the path (two samples per profile segment, refined where the width bends, and leaning on dense path flattening) so straight runs draw it too; added samples offset along the source curve's exact tangent, not the flattened chord, so high zoom follows the true width; the sampled edges are fitted with G1 cubics within a tenth of the flattening tolerance (0.001 pt at the default 0.01 pt) rather than one cubic per flatten step, so exports stay close to a uniform stroke's path data; a point reshapes the curve as far as its neighbours' neighbours (their slopes depend on it), and coincident points still step.
- **Brushes (part of #852):** double-clicking a brush in the Brushes panel (or the panel menu's Brush Options…) opens Calligraphic Brush Options (Name; Angle, Roundness and Size, each Fixed, Random, Pressure, Tilt, Bearing or Rotation with its Variation; live previews of the nib and of a light–heavy–light stroke) or Bristle Brush Options (Shape and the bristle sliders); OK edits the brush and every stroke painted with it. The Paintbrush records the pen pressure along each stroke (kept with the path, saved, and joined when a stroke continues a path); a Calligraphic value on Pressure goes from value − variation at the lightest pressure to value + variation at the heaviest, on the canvas and in SVG, PDF and the other exports. Brushes saved before keep their look. Scatter Brush Options (Size, Spacing, Scatter and Rotation, each Fixed, Random between two values, Pressure from the first at the lightest pressure to the second at the heaviest, Tilt, Bearing or Rotation; Rotation relative to Page or Path), Art Brush Options (Width, Scale Proportionately, Stretch to Fit Stroke Length or Stretch Between Guides with the guides' start and end, the four Directions, Flip Along and Across, Overlap) and Pattern Brush Options (Scale, Spacing, the five tiles shown, Flip Along and Across, Stretch to fit, Add space to fit or Approximate path) each have Colorization (None, Tints, Tints and Shades, Hue Shift with its Key Color picked from the art's colours) and a live stroke preview; values from files and commands are clamped to their ranges. Art Brush Options › Overlap places art on each run between sharp corners so folds do not overlap (`ArtBrush.overlap`; `art_brush_overlap_splits_at_corners`). Still to come: Stylus Wheel for Pattern brushes and on Windows and the web, pen pressure on macOS where the windowing layer reports none, and tilt, bearing and rotation for Pattern and Bristle brushes and on native Wayland and the web.