diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 15b4c96670..ca4a9d7022 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -129,7 +129,7 @@ pub fn specs() -> Vec { "Reorder", [], None, - "{id, parent?: id (null = top level), index} put a row at `index` (0 = bottom) of `parent` (layers only at the top level or in layers; the clipping path of a clip group or clipping layer stays at its bottom: it does not move until the mask is released, and a row put below it goes just above it; a path other than a clip group's or clipping layer's clipping path also goes into a shown, unlocked compound path whose layer and groups are shown and unlocked and that is not on a locked artboard, and gives up its own paint (the compound path becomes pixel-aligned when the path or the compound path it leaves was), and an empty compound path takes the paint the first path that goes in was drawn with; a path that leaves a compound path for a layer or a group takes its paint and pixel alignment; an Intertwine group takes and gives up members as layer.move does), deselecting every selected object left hidden or locked (the key object too); a Live Paint group or its paths take a row as layer.move does", + "{id, parent?: id (null = top level), index} put a row at `index` (0 = bottom) of `parent` (layers only at the top level or in layers; the clipping path of a clip group or clipping layer stays at its bottom: it does not move until the mask is released, and a row put below it goes just above it; a path other than a clip group's or clipping layer's clipping path also goes into a shown, unlocked compound path whose layer and groups are shown and unlocked and that is not on a locked artboard (unless it is new art there that is still selected), and gives up its own paint (the compound path becomes pixel-aligned when the path or the compound path it leaves was), and an empty compound path takes the paint the first path that goes in was drawn with; a path that leaves a compound path for a layer or a group takes its paint and pixel alignment; an Intertwine group takes and gives up members as layer.move does), deselecting every selected object left hidden or locked (the key object too); a Live Paint group or its paths take a row as layer.move does", has_doc, move_node ), diff --git a/crates/engine/src/script/dom/paths.rs b/crates/engine/src/script/dom/paths.rs index eaff2ab678..43b2982ce0 100644 --- a/crates/engine/src/script/dom/paths.rs +++ b/crates/engine/src/script/dom/paths.rs @@ -400,7 +400,7 @@ pub(super) fn flush(h: &super::Host) -> std::result::Result<(), HostError> { /// The object whose paint the path `n` with id `id` shows: its compound path or compound shape /// when it is a member of one, since the paint commands paint that owner in its place. -fn paint_owner<'a>(d: &'a crate::Document, id: NodeId, n: &'a crate::doc::Node) -> &'a crate::doc::Node { +pub(super) fn paint_owner<'a>(d: &'a crate::Document, id: NodeId, n: &'a crate::doc::Node) -> &'a crate::doc::Node { d.parent_of(id).and_then(|p| d.node(p)).filter(|p| matches!(p.kind, NodeKind::Compound { .. }) || p.is_compound_shape()).unwrap_or(n) } diff --git a/crates/engine/src/script/dom/transform.rs b/crates/engine/src/script/dom/transform.rs index 9bbc8c1cd2..f2f558fcd0 100644 --- a/crates/engine/src/script/dom/transform.rs +++ b/crates/engine/src/script/dom/transform.rs @@ -194,13 +194,15 @@ fn apply(h: &Host, item: Item, m: Matrix, about: Option<&Data>, opts: &Options, if matrix::singular(m) { return Err(HostError::Error("the transformation is singular and would flatten the object".into())); } - let (locked, hidden, on_locked, bounds, uses_pattern, clipped) = with_doc(h, item.doc, |_, st| { + let (locked, hidden, on_locked, bounds, uses_pattern, shows_pattern, clipped) = with_doc(h, item.doc, |_, st| { let d = &st.doc; let line = d.ancestry(item.id); let mut locked = line.as_ref().is_none_or(|a| a.iter().any(|i| d.node(*i).is_none_or(|n| n.locked))); let hidden = line.as_ref().is_none_or(|a| a.iter().chain(std::iter::once(&item.id)).any(|i| d.node(*i).is_none_or(|n| !n.visible))); - let (mut uses, mut clipped) = (false, false); + let (mut uses, mut shows, mut clipped) = (false, false, false); if let Some(n) = d.node(item.id) { + // A member of a compound path or compound shape shows its compound's paint. + shows = vectorcraft_doc::pattern::uses_pattern(paths::paint_owner(d, item.id, n), None); n.walk(&mut |c| { locked |= c.locked; uses |= vectorcraft_doc::pattern::uses_pattern(c, None); @@ -208,7 +210,7 @@ fn apply(h: &Host, item: Item, m: Matrix, about: Option<&Data>, opts: &Options, matches!(c.kind, vectorcraft_doc::NodeKind::Group { clip: true, .. } | vectorcraft_doc::NodeKind::Layer { clip: true, .. }); }); } - (locked, hidden, d.on_locked_artboard(item.id), d.bounds_of(&[item.id], false), uses, clipped) + (locked, hidden, d.on_locked_artboard(item.id), d.bounds_of(&[item.id], false), uses, shows || uses, clipped) }); if locked { return Err(HostError::Error(format!("{LOCKED}: {}", item.id.0))); @@ -235,11 +237,20 @@ fn apply(h: &Host, item: Item, m: Matrix, about: Option<&Data>, opts: &Options, // A path with no anchors has no bounds to turn or scale about, and turning or scaling it // changes nothing; only a stroke weight the call sets is applied. A pattern it uses has no // point to turn or scale about either, so a call that asks to transform it is refused. - (Some(_), None) if paths::is_path(h, item) && !(opts.patterns && uses_pattern) => { - if let Some(w) = weight { - paths::set_stroke_weight(h, item, w)?; - } - return Ok(Data::Undefined); + (Some(_), None) if paths::is_path(h, item) && !(opts.patterns && shows_pattern) => { + // A call that scales strokes and effects with the object still scales the path's own + // strokes and effects, as for a path with anchors. + return atomically(h, |h| { + if opts.strokes { + let c = on_page(m, Point::ORIGIN).as_coeffs(); + let p = json!({"ids": [item.id.0], "matrix": c, "objects": true, "patterns": false, "strokes": true}); + edit_item(h, item, "object.transform", &p)?; + } + if let Some(w) = weight { + paths::set_stroke_weight(h, item, w)?; + } + Ok(Data::Undefined) + }); } (Some(_), None) => return Err(HostError::Error("the object has no bounds".into())), (None, _) => Point::ORIGIN, diff --git a/crates/engine/src/tests/panelcmds.rs b/crates/engine/src/tests/panelcmds.rs index c99f58359f..d1ae98e29a 100644 --- a/crates/engine/src/tests/panelcmds.rs +++ b/crates/engine/src/tests/panelcmds.rs @@ -1136,6 +1136,30 @@ fn new_art_on_a_locked_artboard_stays_editable_until_the_selection_leaves_it() { batches_and_isolation_keep_new_art_protected(&mut s, pasted); } +/// A compound path pasted onto a locked artboard takes a path through node.move while it is still +/// selected, and is refused as a destination once the selection leaves it out. +#[test] +fn node_move_into_new_compound_path_on_a_locked_artboard() { + let mut s = session(); + let p = rect(&mut s); + let q = NodeId(s.execute("shape.rectangle", &json!({"x": 10, "y": 200, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap()); + let c = NodeId(s.execute("shape.rectangle", &json!({"x": 300, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap()); + let e = NodeId(s.execute("shape.rectangle", &json!({"x": 340, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap()); + s.execute("select.set", &json!({"ids": [c.0, e.0]})).unwrap(); + s.execute("edit.copy", &json!({})).unwrap(); + s.execute("artboard.new", &json!({"x": 1000, "y": 0, "width": 400, "height": 400})).unwrap(); + s.execute("artboard.setProps", &json!({"index": 1, "locked": true})).unwrap(); + let pasted = ids(&s.execute("edit.paste", &json!({"center": [1200, 200]})).unwrap()["ids"]); + assert_eq!(pasted.len(), 2); + let compound = s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap(); + assert_eq!(s.doc().unwrap().selection.objects.iter().map(|id| id.0).collect::>(), [compound], "the new compound path is selected"); + s.execute("node.move", &json!({"id": p.0, "parent": compound, "index": 0})).unwrap(); + assert_eq!(s.doc().unwrap().doc.parent_of(p), Some(NodeId(compound)), "new art takes the path"); + s.execute("select.none", &json!({})).unwrap(); + assert!(s.execute("node.move", &json!({"id": q.0, "parent": compound, "index": 0})).is_err(), "no longer new art"); + assert_ne!(s.doc().unwrap().doc.parent_of(q), Some(NodeId(compound))); +} + /// The batch, isolation and group cases of [`new_art_on_a_locked_artboard_stays_editable_until_the_selection_leaves_it`], /// with the pasted art `pasted` selected. fn batches_and_isolation_keep_new_art_protected(s: &mut Session, pasted: Vec) { diff --git a/crates/engine/src/tests/script_dom_paths.rs b/crates/engine/src/tests/script_dom_paths.rs index db02ff3742..155f99c1bc 100644 --- a/crates/engine/src/tests/script_dom_paths.rs +++ b/crates/engine/src/tests/script_dom_paths.rs @@ -1806,6 +1806,33 @@ fn transforming_the_pattern_of_an_empty_path_is_refused() { } } +/// A member with no anchors of a compound path that shows a pattern is refused as a path with a +/// pattern of its own is, since the pattern it shows is its compound's. +#[test] +fn transforming_the_compound_pattern_of_an_empty_member_is_refused() { + let (mut s, _) = doc_with_paints(); + s.execute("paint.setFill", &json!({"swatch": "Dots"})).unwrap(); + log(&mut s, "var d = app.activeDocument, n = d.pathItems.add(), c = d.compoundPathItems.add(); n.move(c, ElementPlacement.PLACEATBEGINNING);"); + assert_eq!(log(&mut s, "vc.log(app.activeDocument.compoundPathItems[0].pathItems.length);"), vec![json!(1)]); + let (before, steps) = (art(&s), undo_steps(&s)); + let e = failure(&mut s, "app.activeDocument.compoundPathItems[0].pathItems[0].rotate(90, true, true, true, true, Transformation.TOPLEFT);"); + assert!(e.contains("the object has no bounds"), "{e}"); + assert_eq!((art(&s), undo_steps(&s)), (before, steps)); +} + +/// Scaling a path with no anchors with its stroke weights scales its own stroke weight. +#[test] +fn scaling_an_empty_path_with_line_widths_scales_its_stroke() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + log(&mut s, "var n = app.activeDocument.pathItems.add(); n.stroked = true; n.strokeWidth = 10; n.strokeDashes = [3, 4];"); + let steps = undo_steps(&s); + log(&mut s, "app.activeDocument.pathItems[0].resize(200, 200, true, false, true, false, 200);"); + assert_eq!(log(&mut s, "vc.log(app.activeDocument.pathItems[0].strokeWidth);"), vec![json!(20)]); + assert_eq!(log(&mut s, "vc.log(app.activeDocument.pathItems[0].strokeDashes);"), vec![json!([6, 8])], "the dashes scale too"); + assert_eq!(undo_steps(&s), steps + 1, "one undo step"); +} + #[test] fn filled_true_throws_for_a_new_art_pattern_it_cannot_give() { let placed = vectorcraft_color::Paint::Pattern { pattern: "Dots".into(), xf: vectorcraft_geom::Affine::scale(2.0) }; diff --git a/docs/mcp.md b/docs/mcp.md index aa3d561e59..b493faaae9 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3369,7 +3369,7 @@ through `$`: An omitted key takes its default (`parent`: the current layer; `index`: on top; `compound`: false). Explicit `null` is refused for `parent`, `index` and `compound`. The selection stays as it is. `node.move` also puts a path into a shown, unlocked compound path (its layer and - groups shown and unlocked too, and not on a locked artboard), where the path + groups shown and unlocked too, and not on a locked artboard unless it is new art there that is still selected), where the path gives up its own paint (a clip group's or clipping layer's clipping path is refused until its mask is released), and an empty compound path takes the paint the first path that goes in was drawn with. A path that `node.move` takes out of a compound path into a layer or a group takes the compound path's paint and pixel alignment, and a pixel-aligned compound path snaps a path it takes to the pixel grid. `node.move` leaves the @@ -8332,7 +8332,7 @@ and `layerRows`, the rows highlighted in the panel. selected-art square is `layer.move` with the selected objects. `node.move {id, parent?, index}` is the low-level form with the same nesting rules; unlike `layer.move`, it also moves a row into a locked layer or group, and it puts a path into a shown, unlocked compound path whose layer and groups are also shown and unlocked and that is not on - a locked artboard (see `object.newGroup` for the paint the path keeps or takes). A row that + a locked artboard unless it is new art there that is still selected (see `object.newGroup` for the paint the path keeps or takes). A row that either command puts into a Live Paint group from elsewhere (inside it, or above or below one of its rows) joins the group's paths as `livePaint.merge` adds them, in one "Merge Live Paint" undo step, and the group is selected and listed in `layer.move`'s `ids` in its place; paths, compound paths, groups of them and Live Paint groups can join,