From d50b48bcd2d20b808fde9af59ae4a93dc575f1c0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 12:06:45 -0800 Subject: [PATCH 01/14] Graphs: Expand Appearance skips a design's art instead of restoring it Expand Appearance of a graph or series group no longer expands the art of a graph design in a series and then puts the earlier copy back. It leaves that art out while expanding the rest. - The art's own raster effects are no longer rendered into images that stay in the document after the art is put back. - A geometry effect, color adjustment or raster effect of the graph or series group around the art now applies to the art with the rest of the group. Before, the earlier copy put back did not have it. - In Safe Mode, a plug-in effect in the art is checked when an effect of a group around it, inside the selection, draws the art with that group. docs/mcp.md states that an effect of the group reaches its design art. --- crates/engine/src/cmd/effectcmd.rs | 65 ++++++++++++++----------- crates/engine/src/cmd/graph/tests.rs | 49 +++++++++++++++++++ crates/engine/tests/plugin_safe_mode.rs | 46 +++++++++++++++++ docs/mcp.md | 6 +-- 4 files changed, 135 insertions(+), 31 deletions(-) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index 9d86449bb9..8229ed55c3 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -927,15 +927,16 @@ fn raster_image(d: &mut Document, n: &Node) -> Option<(Node, bool)> { /// Expand the pieces of `m`, art evaluated from the object of the same id (its pieces share that /// id): those made from its own fills and strokes, or with `all` every member. The other members /// that repeat an id ([`repeats_an_id`]) and hold a random Transform effect ([`has_seeded`]) are -/// expanded as well ([`expand_in_place`]). Then the members get ids of their own. Random in a -/// Transform effect takes its seed from the id, and the canvas draws the pieces with the ids they -/// have before that. Returns what each of those other members' expansions lists, by the member's -/// new id. +/// expanded as well ([`expand_in_place`]), except the objects `skip` lists. Then the members get ids +/// of their own. Random in a Transform effect takes its seed from the id, and the canvas draws the +/// pieces with the ids they have before that. Returns what each of those other members' expansions +/// lists, by the member's new id. fn expand_pieces( d: &mut Document, m: &mut Node, all: bool, brushes: &[vectorcraft_brush::Brush], + skip: &[NodeId], stroke_art: effects::StrokeArt, ) -> std::collections::HashMap> { let id = m.id; @@ -951,7 +952,7 @@ fn expand_pieces( if all || c.id == id { effects::expand_art(d, c, stroke_art); } else if has_seeded(c) && repeats_an_id(c, &seen) { - listed = Some(expand_in_place(d, c, brushes)); + listed = Some(expand_in_place(d, c, brushes, skip)); } fresh_ids_listed(d, c, &mut seen, listed.as_deref_mut().unwrap_or_default()); if let Some(listed) = listed { @@ -1007,9 +1008,9 @@ fn repeats_an_id(n: &Node, seen: &std::collections::HashSet) -> bool { type Listed = (NodeId, usize); /// [`expanded_node`] of `c` in place. Returns what the expansion lists, by places in the walk of `c`. -fn expand_in_place(d: &mut Document, c: &mut Node, brushes: &[vectorcraft_brush::Brush]) -> Vec { +fn expand_in_place(d: &mut Document, c: &mut Node, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId]) -> Vec { let mut listed = vec![]; - if let Some(e) = expanded_node(d, c.clone(), brushes, &mut listed) { + if let Some(e) = expanded_node(d, c.clone(), brushes, skip, &mut listed) { *c = e; } listed @@ -1033,9 +1034,15 @@ fn fresh_ids_listed(d: &mut Document, c: &mut Node, seen: &mut std::collections: /// geometry effects are baked, raster effects become an embedded image, and the object keeps its /// transparency. pub(crate) fn expand_node(d: &mut Document, id: NodeId, brushes: &[vectorcraft_brush::Brush], out: &mut Vec) { + expand_node_except(d, id, brushes, &[], out); +} + +/// [`expand_node`], leaving the objects `skip` lists, and what they hold, as they are. A geometry +/// effect of a group or layer around one still reshapes it with the rest of its members. +fn expand_node_except(d: &mut Document, id: NodeId, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], out: &mut Vec) { let Some(n) = d.node(id).cloned() else { return }; let mut listed = vec![]; - let m = expanded_node(d, n, brushes, &mut listed); + let m = expanded_node(d, n, brushes, skip, &mut listed); out.extend(listed.into_iter().map(|(id, _)| id)); if let Some(mut m) = m { // Art made from type takes its emoji's pixels into the document. @@ -1048,10 +1055,10 @@ pub(crate) fn expand_node(d: &mut Document, id: NodeId, brushes: &[vectorcraft_b /// [`expand_node`] of `n`, which need not be in `d`: `n` with its appearance expanded, `None` when /// it has nothing to expand. `out` gets the objects whose appearance expands, by places in the walk -/// of the expanded `n`, `n`'s first when its own does. -fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Brush], out: &mut Vec) -> Option { +/// of the expanded `n`, `n`'s first when its own does. The objects `skip` lists are not expanded. +fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], out: &mut Vec) -> Option { let id = n.id; - if !expandable(&n) { + if skip.contains(&id) || !expandable(&n) { return None; } // Colour adjustments: the colours inside become the adjusted ones (an embedded image a @@ -1088,7 +1095,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br for (i, c) in m.children_mut().into_iter().flatten().enumerate() { let c = Arc::make_mut(c); if i == 0 { - expanded = expand_in_place(d, c, brushes); + expanded = expand_in_place(d, c, brushes, skip); fresh_ids_listed(d, c, &mut seen, &mut expanded); } else { effects::fresh_ids(d, c, &mut seen); @@ -1129,7 +1136,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br } else if container { // A group's or layer's own fills and strokes become art among its members. effects::evaluate_container(Some(&*d), &v).map(|mut m| { - members = expand_pieces(d, &mut m, false, brushes, &mut stroke_art); + members = expand_pieces(d, &mut m, false, brushes, skip, &mut stroke_art); m }) } else if matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) @@ -1150,7 +1157,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br effects::expand_outlined(Some(&*d), &v, symbol.as_ref()).map(|mut m| { let mut budget = vectorcraft_doc::MAX_SYMBOL_NODES; expand_nested_instances(d, &mut m, 1, &mut budget); - expand_pieces(d, &mut m, true, brushes, &mut stroke_art); + expand_pieces(d, &mut m, true, brushes, skip, &mut stroke_art); m }) }; @@ -1184,7 +1191,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br match members.remove(&c.id) { Some(listed) => out.extend(listed), None => { - if let Some(e) = expanded_node(d, (**c).clone(), brushes, out) { + if let Some(e) = expanded_node(d, (**c).clone(), brushes, skip, out) { *c = Arc::new(e); changed = true; } @@ -1229,9 +1236,19 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { // geometry it hasn't changed. if vectorcraft_plugins::safe_mode::active() { // A dimension selected with the art it measures is left as it is, and so is the art of a graph design in a - // series. + // series, unless an effect of a group around it, the selected graph or series group or one inside it, draws it + // with that group. let mut d = super::dimension::without_kept(&s.doc()?.doc, &roots); - let designs = super::appearance::design_art_in(&d, &roots); + let designs: Vec = super::appearance::design_art_in(&d, &roots) + .into_iter() + .filter(|art| { + !d.ancestry(*art).is_some_and(|up| { + let from = up.iter().position(|a| roots.contains(a)).unwrap_or(up.len()); + up.get(from..up.len().saturating_sub(1)) + .is_some_and(|around| around.iter().filter_map(|a| d.node(*a)).any(|g| g.appearance.effects.iter().any(|e| e.visible))) + }) + }) + .collect(); if !designs.is_empty() { let view = d.to_mut(); for id in designs { @@ -1249,7 +1266,8 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { let colorized_ok = super::paint::check_colorized(&s.doc()?.doc).is_ok(); let ids = s.edit("Expand Appearance", |d, _| { let before = d.clone(); - // The art of graph designs in the graphs and series among the roots stays as the graph draws it. + // The art of graph designs in the graphs and series among the roots is not expanded: the graph draws it again + // from the design. let designs = super::appearance::design_art_in(d, &roots); // A dimension selected with the art it measures keeps its own lines and label: it is out // of the document while the art expands. @@ -1260,16 +1278,7 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { let mut out = vec![]; let threaded = super::threads::frames(d); for id in &roots { - expand_node(d, *id, &brushes, &mut out); - } - for id in &designs { - if let (Some(was), Some(slot)) = (before.node(*id), d.node_mut(*id)) { - *slot = was.clone(); - } - } - if !designs.is_empty() { - // A mark that expands into a group stays listed: only what lies in the restored art is left out. - out.retain(|id| d.node(*id).is_some() && !d.ancestry(*id).is_some_and(|up| up.iter().any(|a| designs.contains(a)))); + expand_node_except(d, *id, &brushes, &designs, &mut out); } super::dimension::put_back(d, lifted); // A dimension whose source was replaced stays where it was, no longer linked. diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 7b7f9974af..c5801b85be 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -586,6 +586,55 @@ fn expand_appearance_leaves_a_graph_designs_art() { assert!(s.doc().unwrap().doc.node(NodeId(other)).is_none_or(|m| m.appearance.effects.is_empty())); } +/// `effect` with `params`, as `effect.apply` gives it to an object. +fn an_effect(s: &mut Session, effect: &str, params: serde_json::Value) -> vectorcraft_doc::Effect { + let r = s.execute("shape.rectangle", &json!({"x": 700, "y": 20, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap(); + s.execute("effect.apply", &json!({"effect": effect, "ids": [r], "params": params})).unwrap(); + s.doc().unwrap().doc.node(NodeId(r)).unwrap().appearance.effects[0].clone() +} + +/// Expand Appearance of a graph neither lists the art of a design in a series whose own effect it leaves, nor adds an +/// image of that effect to the document. +#[test] +fn expand_appearance_lists_no_design_art_and_rasterizes_none() { + let (mut s, id, copy, _, mark) = design_art(); + let shadow = an_effect(&mut s, "stylize.dropShadow", json!({})); + std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(copy).unwrap().appearance.effects.push(shadow); + s.execute("effect.apply", &json!({"effect": "stylize.dropShadow", "ids": [mark.0]})).unwrap(); + let copy_was = look(&s, copy); + let images = |s: &Session| s.doc().unwrap().doc.images.len(); + let before = images(&s); + s.execute("select.set", &json!({"ids": [mark.0]})).unwrap(); + s.execute("effect.expandAppearance", &json!({})).unwrap(); + let per_mark = images(&s) - before; + s.execute("edit.undo", &json!({})).unwrap(); + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + let expanded = s.execute("effect.expandAppearance", &json!({})).unwrap(); + assert_eq!(expanded["ids"], json!([mark.0])); + assert_eq!(look(&s, copy), copy_was); + assert_eq!(images(&s) - before, per_mark, "only the mark's shadow becomes an image"); +} + +/// A geometry effect of a series group that Expand Appearance bakes moves the art of a design in that series with the +/// marks. +#[test] +fn expand_appearance_moves_design_art_with_its_series_groups_effect() { + let (mut s, id, copy, _, _) = design_art(); + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + let group = series(&n, 0).id; + let shift = an_effect(&mut s, "distort.transform", json!({"moveH": 50})); + std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(group).unwrap().appearance.effects.push(shift); + let left = |s: &Session| { + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + series(&n, 0).children().unwrap()[0].geometric_bounds().unwrap().x0 + }; + let was = left(&s); + assert_eq!(series(&n, 0).children().unwrap()[0].id, copy); + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + s.execute("effect.expandAppearance", &json!({})).unwrap(); + assert!((left(&s) - was - 50.0).abs() < 1e-6, "{} then {}", was, left(&s)); +} + /// The commands that give rows, effects or graphic styles refuse the art of a graph design inside a series, given by /// id (the design's copy or a path inside it) or selected: the graph draws that art again from the design. #[test] diff --git a/crates/engine/tests/plugin_safe_mode.rs b/crates/engine/tests/plugin_safe_mode.rs index 2c5fc1c307..8829c056b3 100644 --- a/crates/engine/tests/plugin_safe_mode.rs +++ b/crates/engine/tests/plugin_safe_mode.rs @@ -463,6 +463,52 @@ fn expand_appearance_keeps_a_plug_in_effect_safe_mode_skips() { s.execute("effect.expandAppearance", &json!({})).unwrap(); } +/// In Safe Mode, a plug-in effect in the art of a graph design in a series stops Expand Appearance of the graph only +/// when an effect of the series group draws that art with the group. +#[test] +fn expand_appearance_in_safe_mode_checks_design_art_its_series_group_draws() { + let _f = fresh(); + let mut s = Session::new(); + let fx = wat::parse_str(tpl::returning(&tpl::manifest("test.sm.graph", "effect", "{}"), r#"{"objects":[]}"#)).unwrap(); + s.execute("plugin.install", &json!({"dataBase64": vectorcraft_format::base64_encode(&fx)})).unwrap(); + s.execute("file.new", &json!({"width": 800, "height": 800})).unwrap(); + let csv = ",2024,2025\nQ1,3,2\nQ2,5,4"; + let graph = s.execute("graph.create", &json!({"type": "column", "x": 100, "y": 100, "width": 300, "height": 200, "csv": csv})).unwrap()["id"] + .as_u64() + .unwrap(); + let r = s.execute("shape.rectangle", &json!({"x": 600, "y": 600, "width": 10, "height": 10})).unwrap()["id"].clone(); + s.execute("effect.apply", &json!({"effect": "plugin.test.sm.graph", "ids": [r]})).unwrap(); + s.execute("select.set", &json!({"ids": [r]})).unwrap(); + s.execute("graph.design", &json!({"new": "Plug"})).unwrap(); + s.execute("graph.column", &json!({"id": graph, "seriesIndexes": [0], "design": "Plug"})).unwrap(); + let series = |s: &Session, index: u32| { + let d = &s.doc().unwrap().doc; + let n = d.node(vectorcraft_engine::doc::NodeId(graph)).unwrap(); + n.children().unwrap().iter().find(|c| c.extras().series_index == Some(index)).unwrap().id + }; + let (art_series, other_series) = (series(&s, 0), series(&s, 1)); + // A mark in the other series has an effect to expand. + let mark = s.doc().unwrap().doc.node(other_series).unwrap().children().unwrap()[0].id; + s.execute("effect.apply", &json!({"effect": "distort.puckerBloat", "ids": [mark.0]})).unwrap(); + s.execute("select.set", &json!({"ids": [graph]})).unwrap(); + safe_mode::set_active(Some(safe_mode::Source::Flag)); + s.execute("effect.expandAppearance", &json!({})).unwrap(); + safe_mode::set_active(None); + s.execute("edit.undo", &json!({})).unwrap(); + // With a Transform effect on the art's series group, expanding the group draws the art's plug-in effect. + let shift = { + let t = s.execute("shape.rectangle", &json!({"x": 700, "y": 20, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap(); + s.execute("effect.apply", &json!({"effect": "distort.transform", "ids": [t], "params": {"moveH": 5}})).unwrap(); + s.doc().unwrap().doc.node(vectorcraft_engine::doc::NodeId(t)).unwrap().appearance.effects[0].clone() + }; + std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(art_series).unwrap().appearance.effects.push(shift); + s.execute("select.set", &json!({"ids": [graph]})).unwrap(); + safe_mode::set_active(Some(safe_mode::Source::Flag)); + let err = s.execute("effect.expandAppearance", &json!({})).unwrap_err().to_string(); + safe_mode::set_active(None); + assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}"); +} + /// In Safe Mode, a plug-in effect on a dimension selected with the art it measures does not stop /// Expand Appearance: the dimension is left as it is, its effect included, and the art expands. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index e186501302..5bc56a95c0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -817,9 +817,9 @@ inside a series group other than a path directly in it, a legend swatch's includ reached through `target: "contents"`. These commands leave that art out, edit the other objects they are given, and are an error when all their objects are design art: the `appearance.*` commands listed above, `effect.apply`, `appearance.addEffect` and the other `effect.*` commands that edit, move or remove an effect, -`effect.expandAppearance` (which also leaves the art inside a selected graph or series group as it was, unless an -effect of that group turns the whole group into other art, and is disabled when only design art is selected or -given), `threeD.mapGraphic`, +`effect.expandAppearance` (which also leaves the art inside a selected graph or series group as it was, except that +an effect of that group which reshapes or replaces the whole group bakes into that art too, and is disabled when only +design art is selected or given), `threeD.mapGraphic`, `graphicStyle.apply`, `graphicStyle.addFromLibrary` with `apply`, `graphicStyle.breakLink`, `transparency.set`, the `paint.freeform.*` commands that edit points and lines, and `appearance.copyFrom` as the target. `appearance.transfer` with design art as its `target`, or as its `source` without `copy`, is an error. From 4b9d56154068f203b5474bb814571deb29b12972 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 13:37:24 -0800 Subject: [PATCH 02/14] Graphs: paint edits of a design's art alone leave the new-art paint as it is With only the art of a graph design in a series given or selected, paint.editGradient still set the default fill or stroke and the remembered paint, paint.swap swapped the default fill and stroke, paint.default reset them, and paint.invert and paint.complement with an item remembered the art's color. Each now returns without changing anything. An empty selection still edits the defaults as before. --- crates/engine/src/cmd/gradient.rs | 4 +++ crates/engine/src/cmd/graph/tests.rs | 37 ++++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 20 +++++++++++++-- docs/mcp.md | 4 ++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index 291aa1b59f..c6534c6367 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -579,6 +579,10 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result { }; let new_default = apply_gradient_edit_in_model(&default_paint, &with_stored_stops(&for_default, &default_paint, &stored), None, &|_| true, model) .map_err(|e| bad(C, e))?; + // Only design art was given or selected: nothing changes, the defaults and the remembered paint included. + if selected && ids.is_empty() { + return Ok(json!({"ids": []})); + } let freeform = str_param(p, "kind").and_then(GradientKind::parse) == Some(GradientKind::Freeform); edit_items(s, &ids, item, C, "Gradient", !stroke, |n, index| { if index.is_none() diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index f8cf0af4ab..6a2e3cd3ad 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -507,6 +507,43 @@ fn stroke_edits_of_selected_design_art_leave_the_new_art_stroke() { assert_eq!(s.new_art_stroke().gradient_mode, mode, "paint.editGradient"); } +/// With only the art of a graph design given or selected, the gradient, swap, default and recolor commands leave the +/// paint for new art and the remembered colors as they are. +#[test] +fn paint_edits_of_design_art_alone_leave_the_defaults() { + let (mut s, _, _, art, _) = design_art(); + let fill = top_row(&s, art, true); + s.execute("select.set", &json!({"ids": []})).unwrap(); + s.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap(); + s.execute("stroke.set", &json!({"weight": 3})).unwrap(); + let defaults = |s: &Session| format!("{:?}", (&s.paint, s.last_solid, &s.last_gradient, &s.recent_colors)); + let commands = [ + ("paint.editGradient", json!({"kind": "linear"})), + ("paint.editGradient", json!({"kind": "radial", "stroke": true})), + ("paint.swap", json!({})), + ("paint.default", json!({})), + ("paint.invert", json!({"item": fill, "stroke": false})), + ("paint.complement", json!({"item": fill, "stroke": false})), + ]; + for (cmd, p) in &commands { + let was = defaults(&s); + let mut q = p.clone(); + q["ids"] = json!([art.0]); + s.execute(cmd, &q).unwrap(); + assert_eq!(defaults(&s), was, "{cmd}, given"); + // Selecting the art makes the defaults take its paint. + s.execute("select.set", &json!({"ids": [art.0]})).unwrap(); + let was = defaults(&s); + s.execute(cmd, p).unwrap(); + assert_eq!(defaults(&s), was, "{cmd}, selected"); + s.execute("select.set", &json!({"ids": []})).unwrap(); + } + // With nothing selected, the swap still swaps the defaults. + let was = defaults(&s); + s.execute("paint.swap", &json!({})).unwrap(); + assert_ne!(defaults(&s), was); +} + /// `transparency.set` without `item` refuses the art of a graph design in a series, and given it with other objects /// sets only theirs. #[test] diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index a37c407041..73c92ac113 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -966,7 +966,13 @@ pub(super) fn restore_unpainted_stroke(ap: &mut Appearance, index: Option } fn swap(s: &mut Session, p: &Value) -> Result { - let ids = super::appearance::drop_design_art(&s.doc()?.doc, paint_targets(s, p)?); + let targets = paint_targets(s, p)?; + let given = !targets.is_empty(); + let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets); + // Only design art was given or selected: nothing changes, the defaults included. + if given && ids.is_empty() { + return ok(); + } if !ids.is_empty() { // When every object comes out as it was, the document and its undo history stay as they are. let before = s.doc()?.doc.clone(); @@ -1001,7 +1007,13 @@ fn swap(s: &mut Session, p: &Value) -> Result { } fn default_paint(s: &mut Session, p: &Value) -> Result { - let ids = super::appearance::drop_design_art(&s.doc()?.doc, paint_targets(s, p)?); + let targets = paint_targets(s, p)?; + let given = !targets.is_empty(); + let ids = super::appearance::drop_design_art(&s.doc()?.doc, targets); + // Only design art was given or selected: nothing changes, the defaults included. + if given && ids.is_empty() { + return ok(); + } if !ids.is_empty() { // When every object comes out as it was, the document and its undo history stay as they are. let before = s.doc()?.doc.clone(); @@ -1073,6 +1085,10 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( let (r, shown_item) = match item { ItemTarget::Item { index, .. } => { let ids = super::appearance::drop_design_art(&s.doc()?.doc, item.targets(s, p)?); + // Only design art was given or selected: nothing changes, the remembered colors included. + if ids.is_empty() { + return Ok(json!({ "changed": 0 })); + } let mut changed = 0; edit_items(s, &ids, item, cmd, label, !stroke, |n, i| { let paint = diff --git a/docs/mcp.md b/docs/mcp.md index 3ec471eb84..a60a9dea96 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -832,7 +832,9 @@ design art is selected or given), `threeD.mapGraphic`, `appearance.transfer` with design art as its `target`, or as its `source` without `copy`, is an error. `paint.setFill`, `paint.setStroke`, `paint.swap`, `paint.default`, `paint.invert` and `paint.complement` with an `item`, `stroke.set`, `stroke.weightUp`, `stroke.weightDown`, `stroke.setAdvanced`, `paint.editGradient`, -`paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When the first selected object is design art, the commands +`paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When all their objects are design art, +`paint.editGradient`, `paint.swap`, `paint.default`, and `paint.invert` and `paint.complement` with an `item` also leave +the paint for new art and the remembered colors as they are. When the first selected object is design art, the commands do not use the Appearance panel's active row. To change the art, edit the design with `graph.design`. The graph also stores a paint or stroke weight that one of these commands changes on the topmost visible fill or stroke From f6ecf49a1926eda8b5802baef60e15dea119aca6 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 16:07:37 -0800 Subject: [PATCH 03/14] Graphs: Invert, Complement and stroke weights of a design's art alone leave the new-art defaults With only the art of a graph design in a series given or selected, paint.invert and paint.complement without an item recolored that art and remembered its new color, and stroke.set with a weight set the stroke weight for new art. Invert and Complement now leave the art out, as they do with an item, also when they are given the whole graph or a series group, and with only design art they change nothing. stroke.set with only design art leaves the weight for new art as it is. An item the art has no row of that kind for is still an error in the commands that leave the art out, as on any other object, and so is a bad aligned or target param. Without stroke, paint.editGradient and paint.setGradientGeom read the kind of an item named on design art alone from that art's row. --- crates/engine/src/cmd/appearance.rs | 19 +++++++++++- crates/engine/src/cmd/gradient.rs | 4 +-- crates/engine/src/cmd/graph/tests.rs | 46 +++++++++++++++++++++++++++- crates/engine/src/cmd/overprint.rs | 17 +++++++--- crates/engine/src/cmd/paint.rs | 19 ++++++++++-- crates/engine/src/cmd/stroke.rs | 13 +++++--- docs/mcp.md | 8 ++--- 7 files changed, 106 insertions(+), 20 deletions(-) diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 38668bd814..95b5936af5 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -451,6 +451,20 @@ pub(crate) fn drop_design_art(d: &Document, mut ids: Vec) -> Vec ids } +/// [`drop_design_art`] for an edit of the `item` rows of `ids` (`fill`: fill rows): an explicit `item` that a design's +/// art has no row of that kind for is still an error of `cmd`, as on any other object. +pub(crate) fn drop_design_art_rows(s: &Session, ids: Vec, item: ItemTarget, fill: bool, cmd: &str) -> Result> { + let d = &s.doc()?.doc; + for (id, it) in ids.iter().zip(item.per_target(s, &ids)) { + if let (Some(it), Some(n)) = (it, d.node(*id)) + && super::graph::is_design_art(d, *id) + { + it.resolve(&n.appearance, fill, cmd)?; + } + } + Ok(drop_design_art(d, ids)) +} + /// The outermost art of graph designs drawn in graph series inside `roots`: the objects directly in a series group that /// [`super::graph::is_design_art`] accepts. pub(crate) fn design_art_in(d: &Document, roots: &[NodeId]) -> Vec { @@ -633,7 +647,10 @@ pub(crate) fn edits_stroke(s: &Session, p: &Value, item: ItemTarget, default: bo } let ItemTarget::Item { index, .. } = item else { return Ok(default) }; let d = &s.doc()?.doc; - let ids = drop_design_art(d, appearance_targets(s, p)?); + let all = appearance_targets(s, p)?; + // The art of a graph design is left out, unless it is all there is: the item is then a row of that art. + let kept = drop_design_art(d, all.clone()); + let ids = if kept.is_empty() { all } else { kept }; Ok(ids.get(item.anchor(s, &ids)).and_then(|id| d.node(*id)?.appearance.items.get(index)).map_or(default, |it| !it.is_fill())) } diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index c6534c6367..89b8daa342 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -534,7 +534,7 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result { // Objects were given or selected, even when all of them are graph design art left out below: the stroke mode is then // not one for new art. let selected = !ids.is_empty(); - let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids); + let ids = super::appearance::drop_design_art_rows(s, ids, item, !stroke, C)?; // How the gradient lies on a stroke (the panel's Stroke buttons). let mode = match str_param(p, "strokeMode") { None => None, @@ -768,7 +768,7 @@ fn set_gradient_geom(s: &mut Session, p: &Value) -> Result { if targets.is_empty() { return Err(EngineError::Other("nothing selected".into())); } - let targets = super::appearance::drop_design_art(&s.doc()?.doc, targets); + let targets = super::appearance::drop_design_art_rows(s, targets, item, !stroke, C)?; let model = super::paint::new_color_model(s, &Value::Null); edit_items(s, &targets, item, C, "Gradient", !stroke, |n, index| { if index.is_none() diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 6a2e3cd3ad..a34ac0f724 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -454,7 +454,7 @@ fn an_edit_of_a_graph_designs_art_is_lost_when_the_graph_is_drawn_again() { /// it, and edit the other objects they are given. #[test] fn paint_commands_leave_a_graph_designs_art_out() { - let (mut s, _, copy, art, mark) = design_art(); + let (mut s, graph, copy, art, mark) = design_art(); let fill = top_row(&s, art, true); let commands = [ ("stroke.set", json!({"weight": 5})), @@ -466,6 +466,7 @@ fn paint_commands_leave_a_graph_designs_art_out() { ("paint.swap", json!({})), ("paint.default", json!({})), ("paint.invert", json!({"item": fill, "stroke": false})), + ("paint.invert", json!({})), ]; let (copy_was, art_was) = (look(&s, copy), look(&s, art)); for (cmd, p) in &commands { @@ -489,6 +490,11 @@ fn paint_commands_leave_a_graph_designs_art_out() { s.execute("select.set", &json!({"ids": [art.0]})).unwrap(); s.execute("stroke.set", &json!({"weight": 5})).unwrap(); assert_eq!(look(&s, art), art_was); + // Given the whole graph, Invert recolors the marks and leaves the art. + let mark_was = look(&s, mark); + s.execute("paint.invert", &json!({"ids": [graph.0]})).unwrap(); + assert_eq!(look(&s, art), art_was); + assert_ne!(look(&s, mark), mark_was); // A freeform gradient point is refused on the art alone. refused_on_design_art(&mut s, "paint.freeform.addPoint", json!({"ids": [art.0], "at": [0, 0]})); } @@ -524,6 +530,10 @@ fn paint_edits_of_design_art_alone_leave_the_defaults() { ("paint.default", json!({})), ("paint.invert", json!({"item": fill, "stroke": false})), ("paint.complement", json!({"item": fill, "stroke": false})), + ("paint.invert", json!({})), + ("paint.complement", json!({"stroke": true})), + ("stroke.set", json!({"weight": 7})), + ("stroke.weightUp", json!({})), ]; for (cmd, p) in &commands { let was = defaults(&s); @@ -538,6 +548,40 @@ fn paint_edits_of_design_art_alone_leave_the_defaults() { assert_eq!(defaults(&s), was, "{cmd}, selected"); s.execute("select.set", &json!({"ids": []})).unwrap(); } + // A bad `item`, `aligned` or `target` is still an error with only design art given. + for bad in [ + json!({"ids": [art.0], "item": "top"}), + json!({"ids": [art.0], "item": fill, "aligned": "yes"}), + json!({"ids": [art.0], "item": fill, "target": "nowhere"}), + ] { + assert!(s.execute("paint.invert", &bad).is_err(), "{bad}"); + } + // So is an `item` the art has no row for, in each command that leaves the art out. + let steps = s.doc().unwrap().history.undo.len(); + for (cmd, p) in [ + ("paint.invert", json!({})), + ("stroke.set", json!({"weight": 2})), + ("stroke.weightUp", json!({})), + ("stroke.setAdvanced", json!({"swapArrows": true})), + ("paint.editGradient", json!({"kind": "linear"})), + ("paint.setGradientGeom", json!({"start": [0, 0], "end": [50, 50]})), + ("object.setOverprint", json!({"fill": true})), + ] { + let mut q = p.clone(); + q["ids"] = json!([art.0]); + q["item"] = json!(99); + assert!(s.execute(cmd, &q).is_err(), "{cmd}"); + } + // The art's stroke row named without `stroke` is a stroke row: the gradient commands succeed and change nothing. + let stroke_row = top_row(&s, art, false); + for p in [json!({"kind": "linear"}), json!({"start": [0, 0], "end": [50, 50]})] { + let cmd = if p.get("kind").is_some() { "paint.editGradient" } else { "paint.setGradientGeom" }; + let mut q = p.clone(); + q["ids"] = json!([art.0]); + q["item"] = json!(stroke_row); + s.execute(cmd, &q).unwrap(); + } + assert_eq!(s.doc().unwrap().history.undo.len(), steps); // With nothing selected, the swap still swaps the defaults. let was = defaults(&s); s.execute("paint.swap", &json!({})).unwrap(); diff --git a/crates/engine/src/cmd/overprint.rs b/crates/engine/src/cmd/overprint.rs index 781a8242ce..cbc639f1ce 100644 --- a/crates/engine/src/cmd/overprint.rs +++ b/crates/engine/src/cmd/overprint.rs @@ -126,14 +126,21 @@ fn kinds(p: &Value, cmd: &str, keys: [&str; 2]) -> Result> { .collect() } -/// Each kind's item target and objects: (fill?, item, ids). -fn aims(s: &Session, p: &Value, cmd: &str, kinds: impl IntoIterator) -> Result)>> { +/// Each kind's item target and objects: (fill?, item, ids). With `edit`, an explicit item that the graph design art left +/// out has no row of that kind for is an error, as when the edit resolves it on the other objects. +fn aims(s: &Session, p: &Value, cmd: &str, kinds: impl IntoIterator, edit: bool) -> Result)>> { let item = item_target(s, p, cmd)?; kinds .into_iter() .map(|fill| { let it = item.of_kind(s, fill); - Ok((fill, it, super::appearance::drop_design_art(&s.doc()?.doc, it.targets(s, p)?))) + let ids = it.targets(s, p)?; + let ids = if edit { + super::appearance::drop_design_art_rows(s, ids, it, fill, cmd)? + } else { + super::appearance::drop_design_art(&s.doc()?.doc, ids) + }; + Ok((fill, it, ids)) }) .collect() } @@ -159,7 +166,7 @@ pub(super) type OverprintJob = ((bool, ItemTarget, Vec), bool); /// `object.setOverprint` aims. pub(super) fn overprint_jobs(s: &Session, p: &Value, cmd: &str, keys: [&str; 2]) -> Result> { let kinds = kinds(p, cmd, keys)?; - Ok(aims(s, p, cmd, kinds.iter().map(|k| k.0))?.into_iter().zip(kinds.iter().map(|k| k.1)).collect()) + Ok(aims(s, p, cmd, kinds.iter().map(|k| k.0), true)?.into_iter().zip(kinds.iter().map(|k| k.1)).collect()) } /// Apply `jobs` to `d`, adding the objects changed to `changed`. @@ -198,7 +205,7 @@ fn attributes(s: &Session, p: &Value) -> Result { let d = &s.doc()?.doc; let mut info = AttributesInfo { ids: targets(s, p)?, recent_urls: s.recent_urls.clone(), ..Default::default() }; super::attributes::fill_info(d, &mut info); - for (fill, item, ids) in aims(s, p, C, [true, false])? { + for (fill, item, ids) in aims(s, p, C, [true, false], false)? { let mut all = ids.iter().filter_map(|id| d.node(*id)).filter_map(|n| Some(flags(n, fill, item.resolve(&n.appearance, fill, C).ok()?))).flatten(); let same = all.next().and_then(|first| all.all(|b| b == first).then_some(first)); diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 73c92ac113..d42ecaf1df 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1082,9 +1082,17 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( return Ok(json!({ "changed": changed as usize })); } let item = item_target(s, p, cmd)?.of_kind(s, !stroke); + // Read before the check below, so that a bad param (such as `target`, or an explicit `item` the art has no row + // for) is still an error. + let targets = super::appearance::drop_design_art_rows(s, item.targets(s, p)?, item, !stroke, cmd)?; + let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids); + // Only design art was given or selected: nothing changes, the defaults and remembered colors included. + if ids.is_empty() { + return Ok(json!({ "changed": 0 })); + } let (r, shown_item) = match item { ItemTarget::Item { index, .. } => { - let ids = super::appearance::drop_design_art(&s.doc()?.doc, item.targets(s, p)?); + let ids = targets; // Only design art was given or selected: nothing changes, the remembered colors included. if ids.is_empty() { return Ok(json!({ "changed": 0 })); @@ -1099,12 +1107,17 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( (json!({ "changed": changed }), Some(index)) } // The proxy recolors its paints, including a colorized image's fill, without changing image pixels or pattern tiles. + // Design art inside a given graph or series group is left out too. ItemTarget::Top => { - let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": ids.iter().map(|i| i.0).collect::>()}); + let leaves = targets; + if leaves.is_empty() { + return Ok(json!({ "changed": 0 })); + } + let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": leaves.iter().map(|i| i.0).collect::>()}); (super::colorcmds::recolor(s, &q, cmd, label, f)?, None) } }; - let shown_ids = if shown_item.is_some() { ids } else { leaf_targets(s, &ids)? }; + let shown_ids = if shown_item.is_some() { ids } else { super::appearance::drop_design_art(&s.doc()?.doc, leaf_targets(s, &ids)?) }; if let Some(shown) = shown_ids.first().and_then(|id| s.doc().ok()?.doc.node(*id).map(|n| proxy_paint(n, stroke, shown_item))) { s.remember_paint(&shown); } diff --git a/crates/engine/src/cmd/stroke.rs b/crates/engine/src/cmd/stroke.rs index f268eee9c8..1e9c290ed6 100644 --- a/crates/engine/src/cmd/stroke.rs +++ b/crates/engine/src/cmd/stroke.rs @@ -234,8 +234,11 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result { let item = item_target(s, p, C)?.of_kind(s, false); let mut ids = if item == ItemTarget::Top { own_stroke_or_leaves(s, p)? } else { item.targets(s, p)? }; let new_art = no_targets(&ids, p); + let given = !ids.is_empty(); // The art of a graph design in a series keeps the design's stroke. - ids = super::appearance::drop_design_art(&s.doc()?.doc, ids); + ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?; + // With only design art, the weight for new art stays as it is too. + let only_design_art = given && ids.is_empty(); if item == ItemTarget::Top { // Images and symbol instances take no stroke from the panel. let d = &s.doc()?.doc; @@ -327,7 +330,9 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result { })?; // Commit the new-art template only after the complete request is validated // and the selected artwork edit has succeeded. - if let Some(w) = change.weight { + if let Some(w) = change.weight + && !only_design_art + { s.paint.stroke_width = w; } if new_art && let Some(st) = s.new_art_stroke_mut() { @@ -370,7 +375,7 @@ fn stroke_step(s: &mut Session, p: &Value, up: bool) -> Result { } return Ok(json!({"objects": 0})); } - let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids); + let ids = super::appearance::drop_design_art_rows(s, ids, item, false, c)?; let label = if up { "Stroke Weight Up" } else { "Stroke Weight Down" }; edit_items(s, &ids, item, c, label, false, |n, index| { if index.is_none() @@ -515,7 +520,7 @@ fn stroke_advanced(s: &mut Session, p: &Value) -> Result { let ids = item.targets(s, p)?; let new_art = no_targets(&ids, p); // The art of a graph design in a series keeps the design's stroke. - let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids); + let ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?; let arrows_and_profile = |st: &mut StrokeLayer| { if let Some(sc) = scale { st.arrow_scale = sc; diff --git a/docs/mcp.md b/docs/mcp.md index a60a9dea96..49569acfc1 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -830,11 +830,11 @@ design art is selected or given), `threeD.mapGraphic`, `graphicStyle.apply`, `graphicStyle.addFromLibrary` with `apply`, `graphicStyle.breakLink`, `transparency.set`, the `paint.freeform.*` commands that edit points and lines, and `appearance.copyFrom` as the target. `appearance.transfer` with design art as its `target`, or as its `source` without `copy`, is an error. -`paint.setFill`, `paint.setStroke`, `paint.swap`, `paint.default`, `paint.invert` and `paint.complement` with an -`item`, `stroke.set`, `stroke.weightUp`, `stroke.weightDown`, `stroke.setAdvanced`, `paint.editGradient`, +`paint.setFill`, `paint.setStroke`, `paint.swap`, `paint.default`, `paint.invert`, `paint.complement`, +`stroke.set`, `stroke.weightUp`, `stroke.weightDown`, `stroke.setAdvanced`, `paint.editGradient`, `paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When all their objects are design art, -`paint.editGradient`, `paint.swap`, `paint.default`, and `paint.invert` and `paint.complement` with an `item` also leave -the paint for new art and the remembered colors as they are. When the first selected object is design art, the commands +`paint.editGradient`, `paint.swap`, `paint.default`, `paint.invert`, `paint.complement` and `stroke.set` also leave +the paint and stroke weight for new art and the remembered colors as they are. When the first selected object is design art, the commands do not use the Appearance panel's active row. To change the art, edit the design with `graph.design`. The graph also stores a paint or stroke weight that one of these commands changes on the topmost visible fill or stroke From 63aeb358c953a3219c85b70dc65ac6e372af5e06 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 19:05:43 -0800 Subject: [PATCH 04/14] Graphs: proxy recolors keep a group's own paint and spread checks on design art alone paint.invert and paint.complement without an item recolor a given group's own fills and strokes with the objects inside it again, except with target "contents", and leave the art of graph designs inside it as it is. A given member of a compound path stands for the compound path. paint.editGradient with a spread or a negative aspect for design art alone no longer checks it against the kind of the default gradient, so it changes nothing instead of failing. A bad value is still an error. --- crates/doc/src/recolor.rs | 8 +++++ crates/engine/src/cmd/appearance.rs | 2 +- crates/engine/src/cmd/colorcmds.rs | 13 ++++++++- crates/engine/src/cmd/gradient.rs | 4 +-- crates/engine/src/cmd/graph/tests.rs | 42 +++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 27 +++++++++++++---- crates/engine/src/tests/paintproxy.rs | 13 +++++++++ 7 files changed, 100 insertions(+), 9 deletions(-) diff --git a/crates/doc/src/recolor.rs b/crates/doc/src/recolor.rs index 0efa82296a..f25340b29f 100644 --- a/crates/doc/src/recolor.rs +++ b/crates/doc/src/recolor.rs @@ -16,6 +16,11 @@ pub trait ColorVisitor { fn color(&mut self, c: Color) -> Color; /// The key of embedded image `key` recoloured, `None` when it stays as it is. fn image(&mut self, key: &str) -> Option; + /// Whether the pass recolors child `n` of a container: false leaves `n` and everything inside + /// it as they are. + fn enters(&mut self, _n: &Node) -> bool { + true + } } /// What a recolouring pass reaches: fills (including colorized image fills and gradient-mesh @@ -82,6 +87,9 @@ pub fn recolor_node(n: &mut Node, reach: Reach, v: &mut dyn ColorVisitor) -> usi } _ => { for c in n.children_mut().into_iter().flatten() { + if !v.enters(c) { + continue; + } let mut m = (**c).clone(); let k = recolor_node(&mut m, reach, v); if k > 0 { diff --git a/crates/engine/src/cmd/appearance.rs b/crates/engine/src/cmd/appearance.rs index 95b5936af5..17df7dab8a 100644 --- a/crates/engine/src/cmd/appearance.rs +++ b/crates/engine/src/cmd/appearance.rs @@ -389,7 +389,7 @@ pub(crate) fn items_per_target(d: &vectorcraft_doc::Document, ids: &[NodeId], id } /// Whether the `target` param asks for the contents of groups and layers (see the module docs). -fn targets_contents(p: &Value) -> Result { +pub(crate) fn targets_contents(p: &Value) -> Result { match p.get("target") { None | Some(Value::Null) => Ok(false), Some(v) => match v.as_str() { diff --git a/crates/engine/src/cmd/colorcmds.rs b/crates/engine/src/cmd/colorcmds.rs index 8377822094..9006b1f4be 100644 --- a/crates/engine/src/cmd/colorcmds.rs +++ b/crates/engine/src/cmd/colorcmds.rs @@ -221,6 +221,8 @@ pub(crate) struct Recolor<'a> { patterns: HashMap>, new_images: Vec<(String, ImageBlob)>, new_patterns: Vec, + /// Objects inside the recolored ones that keep their colors, with everything inside them. + skip: HashSet, changed: usize, } @@ -236,6 +238,7 @@ impl<'a> Recolor<'a> { patterns: HashMap::new(), new_images: vec![], new_patterns: vec![], + skip: HashSet::new(), changed: 0, } } @@ -254,7 +257,7 @@ impl<'a> Recolor<'a> { /// A pass that maps colors as this one does, with nothing recolored yet. fn again(&self) -> Self { - Self { links: self.links, gray_images: self.gray_images, remake: self.remake, ..Self::new(self.scope, self.f) } + Self { links: self.links, gray_images: self.gray_images, remake: self.remake, skip: self.skip.clone(), ..Self::new(self.scope, self.f) } } /// The entries of `objects` (ids, each with a flag) whose object this pass would change, other @@ -440,12 +443,20 @@ impl ColorVisitor for Visit<'_, '_> { fn image(&mut self, key: &str) -> Option { self.pass.image(self.d, key) } + fn enters(&mut self, n: &Node) -> bool { + !self.pass.skip.contains(&n.id) + } } pub(crate) fn recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(Color) -> Color) -> Result { run_pass(s, p, cmd, label, Recolor::new(Scope::of(p, cmd)?, f)) } +/// [`recolor`] that leaves the objects `skip` inside the recolored ones, and everything inside them, as they are. +pub(crate) fn recolor_except(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(Color) -> Color, skip: HashSet) -> Result { + run_pass(s, p, cmd, label, Recolor { skip, ..Recolor::new(Scope::of(p, cmd)?, f) }) +} + /// [`recolor`] where `f` gives gray colors, so embedded images are stored with one gray channel. fn recolor_gray(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(Color) -> Color) -> Result { run_pass(s, p, cmd, label, Recolor { gray_images: true, ..Recolor::new(Scope::of(p, cmd)?, f) }) diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index 89b8daa342..fbbb992fa8 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -558,7 +558,7 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result { _ => None, }); let for_default = match p.get("aspect").and_then(Value::as_f64) { - Some(a) if a < 0.0 && !ids.is_empty() && default_kind != Some(GradientKind::Conic) => { + Some(a) if a < 0.0 && selected && default_kind != Some(GradientKind::Conic) => { let mut q = p.clone(); q["aspect"] = json!(-a); std::borrow::Cow::Owned(q) @@ -568,7 +568,7 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result { // A spread for selected gradients leaves a freeform default (which has no ends) as it is. let spreads = matches!(spread_param(p), Ok(Some(sp)) if !sp.is_pad()); let for_default = match for_default { - q if spreads && !ids.is_empty() && default_kind == Some(GradientKind::Freeform) => { + q if spreads && selected && default_kind == Some(GradientKind::Freeform) => { let mut q = q.into_owned(); if let Some(o) = q.as_object_mut() { o.remove("spread"); diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index a34ac0f724..45673cc1fa 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -588,6 +588,48 @@ fn paint_edits_of_design_art_alone_leave_the_defaults() { assert_ne!(defaults(&s), was); } +/// A spread or a negative aspect for the art of a graph design alone changes nothing, whatever kind of gradient the +/// default fill is; a bad value is still an error. +#[test] +fn gradient_edits_of_design_art_alone_skip_the_default_kind_checks() { + let (mut s, _, _, art, _) = design_art(); + for (default, p) in [("freeform", json!({"spread": "repeat"})), ("linear", json!({"aspect": -50}))] { + s.execute("select.set", &json!({"ids": []})).unwrap(); + s.execute("paint.editGradient", &json!({"kind": default})).unwrap(); + let (was, art_was, steps) = (format!("{:?}", s.paint), look(&s, art), s.doc().unwrap().history.undo.len()); + let mut q = p.clone(); + q["ids"] = json!([art.0]); + s.execute("paint.editGradient", &q).unwrap_or_else(|e| panic!("{q}: {e}")); + assert_eq!(format!("{:?}", s.paint), was, "{default}"); + assert_eq!(look(&s, art), art_was, "{default}"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps, "{default}"); + } + assert!(s.execute("paint.editGradient", &json!({"ids": [art.0], "spread": "sideways"})).is_err()); +} + +/// Invert given a group around a graph recolors the group's own fill and the series marks, and leaves the art of a +/// graph design as it is. With `target: "contents"` the group's own fill stays as it is. +#[test] +fn invert_of_a_group_recolors_its_own_fill_and_leaves_design_art() { + let (mut s, graph, _, art, mark) = design_art(); + s.execute("select.set", &json!({"ids": [graph.0]})).unwrap(); + let group = NodeId(s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap()); + s.execute("appearance.addFill", &json!({"ids": [group.0]})).unwrap(); + let row = top_row(&s, group, true); + s.execute("paint.setFill", &json!({"ids": [group.0], "item": row, "color": "#ff0000"})).unwrap(); + let own = |s: &Session| format!("{:?}", s.doc().unwrap().doc.node(group).unwrap().appearance.items); + let (own_was, art_was, mark_was) = (own(&s), look(&s, art), look(&s, mark)); + s.execute("paint.invert", &json!({"ids": [group.0]})).unwrap(); + assert_ne!(own(&s), own_was, "the group's own fill"); + assert_ne!(look(&s, mark), mark_was); + assert_eq!(look(&s, art), art_was); + let (own_was, mark_was) = (own(&s), look(&s, mark)); + s.execute("paint.invert", &json!({"ids": [group.0], "target": "contents"})).unwrap(); + assert_eq!(own(&s), own_was, "target: contents"); + assert_ne!(look(&s, mark), mark_was); + assert_eq!(look(&s, art), art_was); +} + /// `transparency.set` without `item` refuses the art of a graph design in a series, and given it with other objects /// sets only theirs. #[test] diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index d42ecaf1df..7aa96e7db4 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1107,14 +1107,31 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( (json!({ "changed": changed }), Some(index)) } // The proxy recolors its paints, including a colorized image's fill, without changing image pixels or pattern tiles. - // Design art inside a given graph or series group is left out too. + // A given group's own fills and strokes change with the objects inside it, except with `target: "contents"`; other + // objects change as their paint targets do (a compound path's member stands for the compound path). Design art + // inside a given graph or series group is left out. ItemTarget::Top => { - let leaves = targets; - if leaves.is_empty() { + let contents = super::appearance::targets_contents(p)?; + let mut roots = vec![]; + for id in &ids { + let group = !contents + && s.doc()?.doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }) && !n.is_compound_shape()); + if group { + roots.push(*id); + } else { + roots.extend(leaf_targets(s, &[*id])?); + } + } + let d = &s.doc()?.doc; + let mut seen = std::collections::HashSet::new(); + roots.retain(|id| seen.insert(*id)); + let roots = super::appearance::drop_design_art(d, roots); + if roots.is_empty() { return Ok(json!({ "changed": 0 })); } - let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": leaves.iter().map(|i| i.0).collect::>()}); - (super::colorcmds::recolor(s, &q, cmd, label, f)?, None) + let art = super::appearance::design_art_in(d, &roots).into_iter().collect(); + let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": roots.iter().map(|i| i.0).collect::>()}); + (super::colorcmds::recolor_except(s, &q, cmd, label, f, art)?, None) } }; let shown_ids = if shown_item.is_some() { ids } else { super::appearance::drop_design_art(&s.doc()?.doc, leaf_targets(s, &ids)?) }; diff --git a/crates/engine/src/tests/paintproxy.rs b/crates/engine/src/tests/paintproxy.rs index b270826e7a..e10f2df6d8 100644 --- a/crates/engine/src/tests/paintproxy.rs +++ b/crates/engine/src/tests/paintproxy.rs @@ -706,3 +706,16 @@ fn a_marker_designs_art_in_a_series_keeps_its_paint() { s.execute("addon.color.fillToStroke", &json!({"ids": [series.id.0]})).unwrap(); assert_eq!(design_strokes(&s), before, "the design's art keeps its paint"); } + +/// Invert given a member of a compound path inverts the compound path's fill, which the member stands for. +#[test] +fn invert_of_a_compound_member_inverts_the_compound_path() { + let mut s = session(); + let (a, b) = (rect(&mut s), rect(&mut s)); + s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + let comp = NodeId(s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap()); + s.execute("paint.setFill", &json!({"ids": [comp.0], "color": "#ff0000"})).unwrap(); + let member = node(&s, comp).children().into_iter().flatten().next().unwrap().id; + s.execute("paint.invert", &json!({"ids": [member.0]})).unwrap(); + assert_eq!(node(&s, comp).appearance.fill_paint().color().unwrap().to_hex(), "#00ffff"); +} From 27704b477ea01b72740a7ffbb6e353b5d202967b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 19:45:11 -0800 Subject: [PATCH 05/14] fmt: wrap the proxy recolor group check --- crates/engine/src/cmd/paint.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 1c9d7928ef..57ba4b1f0b 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1114,8 +1114,9 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( let contents = super::appearance::targets_contents(p)?; let mut roots = vec![]; for id in &ids { - let group = !contents - && s.doc()?.doc.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }) && !n.is_compound_shape()); + let n = s.doc()?.doc.node(*id); + let group = + !contents && n.is_some_and(|n| matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. }) && !n.is_compound_shape()); if group { roots.push(*id); } else { From 49635e9b5fea5c8a320788e4267f5cb90414dd3d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 19:47:15 -0800 Subject: [PATCH 06/14] Docs: paint.invert and paint.complement on a group recolor its own fills or strokes --- crates/engine/src/cmd/paint.rs | 2 +- docs/mcp.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 57ba4b1f0b..085482da16 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -96,7 +96,7 @@ pub fn proxy_specs() -> Vec { "Invert", [], None, - "{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows for every label of its kind (docs/mcp.md); no undo step when no color changes → {changed}", + "{stroke?: bool (default: the active proxy), ids?|id?, item?: appearance item index|null, target?: \"object\"|\"contents\"} invert the active proxy's colours of the selection (or ids; groups recolour their contents and, except with target \"contents\", their own fills and strokes; a compound path's member stands for its compound path) keeping each colour's model, as edit.colors.invert does; the Appearance panel's active fill/stroke item (appearance.setActiveItem) is inverted instead when it is of that kind and no ids are given; with an object of a dynamic symbol instance selected by Direct Selection and no ids, id or item, that object's solid color changes for this instance only, and a gradient or pattern, or type whose characters differ in color, is refused; with nothing selected, invert the default. On a path directly in a graph series, the graph also stores the new color of the topmost visible fill or stroke, and on a graph label the new color of its characters and rows for every label of its kind (docs/mcp.md); no undo step when no color changes → {changed}", has_doc, |s, p| proxy_recolor(s, p, "paint.invert", "Invert", &super::colorcmds::invert) ), diff --git a/docs/mcp.md b/docs/mcp.md index b61c4a97ed..a7d2cf2f3f 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -611,7 +611,9 @@ For `draw_shape` and `draw_path`, omitted paint fields inherit the current [new- For a filled shape or path without an outline, pass an explicit `fill` and `stroke: "none"`. Lines start with no fill and a visible stroke. The Fill/Stroke proxy commands run through `run_command`: `paint.invert` and `paint.complement` recolor the active -proxy, including a grayscale image's colorized fill, while keeping each color's model. `paint.lastColor` / +proxy, including a grayscale image's colorized fill, while keeping each color's model. Given a group without an +Appearance item, they recolor the active proxy's fills or strokes of the objects inside it and of the group itself; +`target: "contents"` leaves the group's own fills or strokes as they are. `paint.lastColor` / `paint.lastGradient` re-apply the last solid color or gradient, and `paint.recent` returns the recent colors that every paint command (and the eyedropper) feeds: up to 30, newest first and each once, kept across documents for the session. `paint.proxies` returns what the proxies show: the fill and stroke, which one is active, and whether the selected From ffd959680f7f2d5a17c85113fbc6a3f8f667c03f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 20:46:27 -0800 Subject: [PATCH 07/14] Graphs: copies of design art made by a series group's Transform effect keep their effects on Expand Appearance Expand Appearance leaves the art of a graph design in a series as it is. A Transform effect of a series group that makes copies gave each copy new ids, so the copies were expanded and their own effects, such as a drop shadow, became embedded images. The new ids of those copies are now left out too; the series group's own effect still bakes into them. --- crates/engine/src/cmd/effectcmd.rs | 32 ++++++++++++++++++++++------ crates/engine/src/cmd/graph/tests.rs | 26 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index 9cb3f46a0d..915163ee55 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -982,14 +982,16 @@ fn raster_image(d: &mut Document, n: &Node) -> Option<(Node, bool)> { /// that repeat an id ([`repeats_an_id`]) and hold a random Transform effect ([`has_seeded`]) are /// expanded as well ([`expand_in_place`]), except the objects `skip` lists. Then the members get ids /// of their own. Random in a Transform effect takes its seed from the id, and the canvas draws the -/// pieces with the ids they have before that. Returns what each of those other members' expansions -/// lists, by the member's new id. +/// pieces with the ids they have before that. `kept` gets the new id of each object in them that +/// had an id `skip` lists before. Returns what each of those other members' expansions lists, by +/// the member's new id. fn expand_pieces( d: &mut Document, m: &mut Node, all: bool, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], + kept: &mut Vec, stroke_art: effects::StrokeArt, ) -> std::collections::HashMap> { let id = m.id; @@ -1007,7 +1009,21 @@ fn expand_pieces( } else if has_seeded(c) && repeats_an_id(c, &seen) { listed = Some(expand_in_place(d, c, brushes, skip)); } + let mut was = vec![]; + if !skip.is_empty() { + c.walk(&mut |n| was.push(n.id)); + } fresh_ids_listed(d, c, &mut seen, listed.as_deref_mut().unwrap_or_default()); + if !was.is_empty() { + // A copy of an object `skip` lists is left as it is too. + let mut at = 0; + c.walk(&mut |n| { + if was.get(at).is_some_and(|old| *old != n.id && skip.contains(old)) { + kept.push(n.id); + } + at += 1; + }); + } if let Some(listed) = listed { expanded.insert(c.id, listed); } @@ -1091,7 +1107,8 @@ pub(crate) fn expand_node(d: &mut Document, id: NodeId, brushes: &[vectorcraft_b } /// [`expand_node`], leaving the objects `skip` lists, and what they hold, as they are. A geometry -/// effect of a group or layer around one still reshapes it with the rest of its members. +/// effect of a group or layer around one still reshapes it with the rest of its members, and the +/// copies of it that such an effect makes are left as they are too. fn expand_node_except(d: &mut Document, id: NodeId, brushes: &[vectorcraft_brush::Brush], skip: &[NodeId], out: &mut Vec) { let Some(n) = d.node(id).cloned() else { return }; let mut listed = vec![]; @@ -1178,6 +1195,8 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br |d: &mut Document, path: &PathData, rule: FillRule, st: &StrokeLayer| super::pathops::outlined_stroke(d, brushes, path, rule, st); // Members of a group or layer that `expand_pieces` expanded, by id, with what their expansion lists. let mut members = std::collections::HashMap::new(); + // New ids of the copies of objects `skip` lists among those members. + let mut kept = vec![]; let expanded = match image { // Blur, feather and inner glow change the object itself: it becomes the image (a layer // keeps it as its only member). @@ -1189,7 +1208,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br } else if container { // A group's or layer's own fills and strokes become art among its members. effects::evaluate_container(Some(&*d), &v).map(|mut m| { - members = expand_pieces(d, &mut m, false, brushes, skip, &mut stroke_art); + members = expand_pieces(d, &mut m, false, brushes, skip, &mut kept, &mut stroke_art); m }) } else if matches!(n.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) @@ -1210,7 +1229,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br effects::expand_outlined(Some(&*d), &v, symbol.as_ref()).map(|mut m| { let mut budget = vectorcraft_doc::MAX_SYMBOL_NODES; expand_nested_instances(d, &mut m, 1, &mut budget); - expand_pieces(d, &mut m, true, brushes, skip, &mut stroke_art); + expand_pieces(d, &mut m, true, brushes, skip, &mut kept, &mut stroke_art); m }) }; @@ -1232,6 +1251,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br } } if container { + let skip = if kept.is_empty() { std::borrow::Cow::Borrowed(skip) } else { std::borrow::Cow::Owned([skip, &kept].concat()) }; // The place of each member in the walk of `n`: after `n` and the members before it. let mut at = 1; for c in n.children_mut().into_iter().flatten() { @@ -1244,7 +1264,7 @@ fn expanded_node(d: &mut Document, mut n: Node, brushes: &[vectorcraft_brush::Br match members.remove(&c.id) { Some(listed) => out.extend(listed), None => { - if let Some(e) = expanded_node(d, (**c).clone(), brushes, skip, out) { + if let Some(e) = expanded_node(d, (**c).clone(), brushes, &skip, out) { *c = Arc::new(e); changed = true; } diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 07b5ba2b8f..a6aea80408 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -768,6 +768,32 @@ fn expand_appearance_moves_design_art_with_its_series_groups_effect() { assert!((left(&s) - was - 50.0).abs() < 1e-6, "{} then {}", was, left(&s)); } +/// The copies that a Transform effect of a series group makes of a design's art keep their own effects when Expand +/// Appearance bakes the series group's effect, as the art they copy does. +#[test] +fn expand_appearance_leaves_the_effects_of_design_art_copies() { + let (mut s, id, copy, _, _) = design_art(); + let n = s.doc().unwrap().doc.node(id).unwrap().clone(); + let group = series(&n, 0).id; + let shadow = an_effect(&mut s, "stylize.dropShadow", json!({})); + let copies = an_effect(&mut s, "distort.transform", json!({"moveH": 50, "copies": 2})); + let doc = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); + doc.node_mut(copy).unwrap().appearance.effects.push(shadow); + doc.node_mut(group).unwrap().appearance.effects.push(copies); + let shadows = |s: &Session| { + let mut count = 0; + s.doc().unwrap().doc.node(id).unwrap().walk(&mut |m| count += m.appearance.effects.iter().filter(|e| e.id == "stylize.dropShadow").count()); + count + }; + let images = |s: &Session| s.doc().unwrap().doc.images.len(); + let before = images(&s); + assert_eq!(shadows(&s), 1); + s.execute("select.set", &json!({"ids": [id.0]})).unwrap(); + s.execute("effect.expandAppearance", &json!({})).unwrap(); + assert_eq!(shadows(&s), 3, "the art and its two copies keep their shadows"); + assert_eq!(images(&s), before, "no shadow becomes an image"); +} + /// The commands that give rows, effects or graphic styles refuse the art of a graph design inside a series, given by /// id (the design's copy or a path inside it) or selected: the graph draws that art again from the design. #[test] From 7cc604a003294991548b29df2aad47f3294193b9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 20:46:28 -0800 Subject: [PATCH 08/14] Attributes: overprint reads the art of graph designs in series again The merge of main dropped the art from attributes.info's overprint read, so overprintFill and overprintStroke came back null with only that art selected. The edits still leave the art out. --- crates/engine/src/cmd/overprint.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/overprint.rs b/crates/engine/src/cmd/overprint.rs index 0da36a3270..e8957691ec 100644 --- a/crates/engine/src/cmd/overprint.rs +++ b/crates/engine/src/cmd/overprint.rs @@ -126,8 +126,9 @@ fn kinds(p: &Value, cmd: &str, keys: [&str; 2]) -> Result> { .collect() } -/// Each kind's item target and objects: (fill?, item, ids). With `edit`, an explicit item that the graph design art left -/// out has no row of that kind for is an error, as when the edit resolves it on the other objects. +/// Each kind's item target and objects: (fill?, item, ids). With `edit`, the art of graph designs drawn in graph series +/// is left out, and an explicit item that the art left out has no row of that kind for is an error, as when the edit +/// resolves it on the other objects. Without it, the art is read with the other objects. fn aims(s: &Session, p: &Value, cmd: &str, kinds: impl IntoIterator, edit: bool) -> Result)>> { let item = item_target(s, p, cmd)?; kinds @@ -135,11 +136,7 @@ fn aims(s: &Session, p: &Value, cmd: &str, kinds: impl IntoIterator .map(|fill| { let it = item.of_kind(s, fill); let ids = it.targets(s, p)?; - let ids = if edit { - super::appearance::drop_design_art_rows(s, ids, it, fill, cmd)? - } else { - super::appearance::drop_design_art(&s.doc()?.doc, ids) - }; + let ids = if edit { super::appearance::drop_design_art_rows(s, ids, it, fill, cmd)? } else { ids }; Ok((fill, it, ids)) }) .collect() From d5b2318b75538b9f92426a89073dafdb0e12cc22 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 20:46:29 -0800 Subject: [PATCH 09/14] Docs: one paragraph for the commands that leave graph design art out The merge of main left two copies of the paragraph. The merged one keeps the rows and effects given with aligned: true, and the commands that leave the defaults for new art as they are. --- docs/mcp.md | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/docs/mcp.md b/docs/mcp.md index 0dc3e847c4..c2c30b0a01 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -836,25 +836,6 @@ inside a series group other than a path directly in it, a legend swatch's includ reached through `target: "contents"`. These commands leave that art out, edit the other objects they are given, and are an error when all their objects are design art: the `appearance.*` commands listed above, `effect.apply`, `appearance.addEffect` and the other `effect.*` commands that edit, move or remove an effect, -`effect.expandAppearance` (which also leaves the art inside a selected graph or series group as it was, unless an -effect of that group turns the whole group into other art, and is disabled when only design art is selected or -given), `threeD.mapGraphic`, -`graphicStyle.apply`, `graphicStyle.addFromLibrary` with `apply`, `graphicStyle.breakLink`, `transparency.set`, the -`paint.freeform.*` commands that edit points and lines, and `appearance.copyFrom` as the target. -`appearance.transfer` with design art as its `target`, or as its `source` without `copy`, is an error. -`paint.setFill`, `paint.setStroke`, `paint.swap`, `paint.default`, `paint.invert` and `paint.complement` with an -`item`, `stroke.set`, `stroke.weightUp`, `stroke.weightDown`, `stroke.setAdvanced`, `paint.editGradient`, -`paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When the first selected object is design art, the commands -do not use the Appearance panel's active row. When the first object given is design art, rows and effects given with -`aligned: true` are rows of its stack in `appearance.setItem`, `appearance.removeItem`, `appearance.duplicateItem`, -`transparency.set` with an `item`, `effect.apply`, `appearance.addEffect` and the other `effect.*` commands that edit, -move or remove an effect: each other object edits the row or effect equal to it, and an object without one is left as -it is. When no object has one, `appearance.setItem` and `appearance.removeItem` leave the document as it is, as they do -for a row no object has, and the other commands are an error. `appearance.moveItem`, `effect.move` and -`appearance.duplicateItem` with `to` are an error when the art's stack differs from the other objects', and -`appearance.duplicateItem` with `to` is also an error when two or more other objects are given, as it is without the -art. To change the art, edit the design with `graph.design`. - `effect.expandAppearance` (which also leaves the art inside a selected graph or series group as it was, except that an effect of that group which reshapes or replaces the whole group bakes into that art too, and is disabled when only design art is selected or given), `threeD.mapGraphic`, @@ -866,7 +847,15 @@ design art is selected or given), `threeD.mapGraphic`, `paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When all their objects are design art, `paint.editGradient`, `paint.swap`, `paint.default`, `paint.invert`, `paint.complement` and `stroke.set` also leave the paint and stroke weight for new art and the remembered colors as they are. When the first selected object is design art, the commands -do not use the Appearance panel's active row. To change the art, edit the design with `graph.design`. +do not use the Appearance panel's active row. When the first object given is design art, rows and effects given with +`aligned: true` are rows of its stack in `appearance.setItem`, `appearance.removeItem`, `appearance.duplicateItem`, +`transparency.set` with an `item`, `effect.apply`, `appearance.addEffect` and the other `effect.*` commands that edit, +move or remove an effect: each other object edits the row or effect equal to it, and an object without one is left as +it is. When no object has one, `appearance.setItem` and `appearance.removeItem` leave the document as it is, as they do +for a row no object has, and the other commands are an error. `appearance.moveItem`, `effect.move` and +`appearance.duplicateItem` with `to` are an error when the art's stack differs from the other objects', and +`appearance.duplicateItem` with `to` is also an error when two or more other objects are given, as it is without the +art. To change the art, edit the design with `graph.design`. The graph also stores a paint or stroke weight that one of these commands changes on the topmost visible fill or stroke of a path directly in a series: a weight set with `stroke.set`, `stroke.weightUp` or `stroke.weightDown`; a gradient From 5ed83e0daa20af6d7520685b4e8052503da5c4e9 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 06:39:46 -0800 Subject: [PATCH 10/14] Gradients: an aligned row of a graph design's art alone is still checked by paint.editGradient With only the art of a graph design in a series given, paint.editGradient returned before it checked an explicit aligned item, so a row the art lacks, or one no other object has, was accepted instead of refused. The row is now checked first, as paint.setFill does. --- crates/engine/src/cmd/gradient.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/gradient.rs b/crates/engine/src/cmd/gradient.rs index b7eb7235f6..00575695d4 100644 --- a/crates/engine/src/cmd/gradient.rs +++ b/crates/engine/src/cmd/gradient.rs @@ -579,12 +579,14 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result { }; let new_default = apply_gradient_edit_in_model(&default_paint, &with_stored_stops(&for_default, &default_paint, &stored), None, &|_| true, model) .map_err(|e| bad(C, e))?; + let of = super::appearance::reference_of(s, p, item, C)?; // Only design art was given or selected: nothing changes, the defaults and the remembered paint included. if selected && ids.is_empty() { + // An aligned `item` of the art alone is still checked: a row the art lacks, or that no other object has, is an error. + edit_items(s, &ids, item, of, C, "Gradient", !stroke, |_, _| Ok(()))?; return Ok(json!({"ids": []})); } let freeform = str_param(p, "kind").and_then(GradientKind::parse) == Some(GradientKind::Freeform); - let of = super::appearance::reference_of(s, p, item, C)?; let shown_at = super::appearance::first_edited(s, item, of, &ids); // The objects returned: with a design's art, those with a row equal to the art's. let edited = edit_items(s, &ids, item, of, C, "Gradient", !stroke, |n, index| { From 531ce2a10e62ba731048c0d572b753fd05fdf401 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 08:07:49 -0800 Subject: [PATCH 11/14] Effects: Safe Mode checks graph design art that a blurred fill of its series group draws effect.expandAppearance in Safe Mode left the art of a graph design in a series out of the plug-in check unless an effect of the series group itself would draw it. A raster effect on one of the group's fills or strokes, such as a Gaussian Blur, also turns the whole group into an image when it expands, art included, so a plug-in effect in that art was expanded without drawing. Such a raster effect now keeps the art in the check, and the command returns the Safe Mode error. --- crates/engine/src/cmd/effectcmd.rs | 7 ++++--- crates/engine/tests/plugin_safe_mode.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/effectcmd.rs b/crates/engine/src/cmd/effectcmd.rs index 5ca2055178..625300cd25 100644 --- a/crates/engine/src/cmd/effectcmd.rs +++ b/crates/engine/src/cmd/effectcmd.rs @@ -1302,15 +1302,16 @@ fn expand_appearance(s: &mut Session, p: &Value) -> Result { if vectorcraft_plugins::safe_mode::active() { // A dimension selected with the art it measures is left as it is, and so is the art of a graph design in a // series, unless an effect of a group around it, the selected graph or series group or one inside it, draws it - // with that group. + // with that group: an effect of the group's own, or a raster effect of one of its fills or strokes (the group + // then becomes an image of all of it). let mut d = super::dimension::without_kept(&s.doc()?.doc, &roots); + let draws_members = |g: &Node| g.appearance.effects.iter().any(|e| e.visible) || !rasterfx::raster_fx(g).is_empty(); let designs: Vec = super::appearance::design_art_in(&d, &roots) .into_iter() .filter(|art| { !d.ancestry(*art).is_some_and(|up| { let from = up.iter().position(|a| roots.contains(a)).unwrap_or(up.len()); - up.get(from..up.len().saturating_sub(1)) - .is_some_and(|around| around.iter().filter_map(|a| d.node(*a)).any(|g| g.appearance.effects.iter().any(|e| e.visible))) + up.get(from..up.len().saturating_sub(1)).is_some_and(|around| around.iter().filter_map(|a| d.node(*a)).any(draws_members)) }) }) .collect(); diff --git a/crates/engine/tests/plugin_safe_mode.rs b/crates/engine/tests/plugin_safe_mode.rs index 8829c056b3..9ff0d0668a 100644 --- a/crates/engine/tests/plugin_safe_mode.rs +++ b/crates/engine/tests/plugin_safe_mode.rs @@ -507,6 +507,23 @@ fn expand_appearance_in_safe_mode_checks_design_art_its_series_group_draws() { let err = s.execute("effect.expandAppearance", &json!({})).unwrap_err().to_string(); safe_mode::set_active(None); assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}"); + // With a Gaussian Blur on a fill of the art's series group instead, expanding the group makes an image of it, art included. + let blurred_fill = { + let t = s.execute("shape.rectangle", &json!({"x": 700, "y": 40, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap(); + s.execute("effect.apply", &json!({"effect": "blur.gaussian", "ids": [t], "item": 0, "params": {"radius": 2}})).unwrap(); + s.doc().unwrap().doc.node(vectorcraft_engine::doc::NodeId(t)).unwrap().appearance.items[0].clone() + }; + { + let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); + let g = d.node_mut(art_series).unwrap(); + g.appearance.effects.clear(); + g.appearance.items.push(blurred_fill); + } + s.execute("select.set", &json!({"ids": [graph]})).unwrap(); + safe_mode::set_active(Some(safe_mode::Source::Flag)); + let err = s.execute("effect.expandAppearance", &json!({})).unwrap_err().to_string(); + safe_mode::set_active(None); + assert!(err.contains("a plug-in effect in the selection can't be expanded in Safe Mode"), "{err}"); } /// In Safe Mode, a plug-in effect on a dimension selected with the art it measures does not stop From 94c815d97194d97cf3a290b438b267c933893d4f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 08:36:20 -0800 Subject: [PATCH 12/14] Paint: invert and complement of design art alone still reject a bad target paint.invert and paint.complement given only the art of a graph design, with no item, returned success for a target other than "object" or "contents", because the topmost-fill path read the target only after the early return for design art. The target is now read before that return. --- crates/engine/src/cmd/graph/tests.rs | 2 ++ crates/engine/src/cmd/paint.rs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 93cf1cf51b..65715e44d1 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -563,8 +563,10 @@ fn paint_edits_of_design_art_alone_leave_the_defaults() { json!({"ids": [art.0], "item": "top"}), json!({"ids": [art.0], "item": fill, "aligned": "yes"}), json!({"ids": [art.0], "item": fill, "target": "nowhere"}), + json!({"ids": [art.0], "target": "nowhere"}), ] { assert!(s.execute("paint.invert", &bad).is_err(), "{bad}"); + assert!(s.execute("paint.complement", &bad).is_err(), "{bad}"); } // So is an `item` the art has no row for, in each command that leaves the art out. let steps = s.doc().unwrap().history.undo.len(); diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index 0870c1cd1a..ef15f896cd 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1098,6 +1098,8 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( ItemTarget::Item { .. } => super::appearance::reference_of(s, p, item, cmd)?, ItemTarget::Top => None, }; + // Read before the check below too: `targets` reads no `target` for the topmost fill or stroke. + let contents = super::appearance::targets_contents(p)?; let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids); // Only design art was given or selected: nothing changes, the defaults and remembered colors included. if ids.is_empty() { @@ -1128,7 +1130,6 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( // objects change as their paint targets do (a compound path's member stands for the compound path). Design art // inside a given graph or series group is left out. ItemTarget::Top => { - let contents = super::appearance::targets_contents(p)?; let mut roots = vec![]; for id in &ids { let n = s.doc()?.doc.node(*id); From 3e2a2ad9ac74f51cfeeba19e48609548af137e12 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 09:41:04 -0800 Subject: [PATCH 13/14] Paint: invert and complement of a group of design art remember its new fill paint.invert and paint.complement given a group whose own fill or stroke changed, with only graph design art inside it, left the last color and the recent colors as they were, because the remembered paint was taken only from the objects inside the group. It now comes from the first group whose own fill or stroke changed. A recolor that changes no group's paint, such as the complement of a gray fill, remembers nothing. --- crates/engine/src/cmd/graph/tests.rs | 52 ++++++++++++++++++++++++++++ crates/engine/src/cmd/paint.rs | 17 ++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 65715e44d1..2ead810dff 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -642,6 +642,58 @@ fn invert_of_a_group_recolors_its_own_fill_and_leaves_design_art() { assert_eq!(look(&s, art), art_was); } +/// Invert and Complement given a series group that holds only a graph design's art recolor the group's own fill and +/// remember that color, as the last color and the newest recent color. With several such groups the color remembered +/// is that of the first group whose fill changed. +#[test] +fn recoloring_a_group_of_design_art_alone_remembers_its_own_fill() { + // A fill of its own for `group`, painted `hex` (the color of a rectangle painted with it). + let paint_own = |s: &mut Session, group: NodeId, hex: &str| { + s.execute("appearance.addFill", &json!({"ids": [group.0]})).unwrap(); + let t = NodeId(s.execute("shape.rectangle", &json!({"x": 700, "y": 700, "width": 5, "height": 5})).unwrap()["id"].as_u64().unwrap()); + s.execute("paint.setFill", &json!({"ids": [t.0], "color": hex})).unwrap(); + let d = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc); + let paint = d.node(t).unwrap().proxy_paint_only(false, None).unwrap().clone(); + d.node_mut(group).unwrap().appearance.fill_at_mut(None).unwrap().paint = paint; + }; + // Series 0's group with its own fill painted `hex`. + let painted_series = |hex: &str| { + let (mut s, graph, _, art, _) = design_art(); + let group = series(s.doc().unwrap().doc.node(graph).unwrap(), 0).id; + paint_own(&mut s, group, hex); + (s, group, art) + }; + for cmd in ["paint.invert", "paint.complement"] { + let (mut s, group, art) = painted_series("#ff0000"); + let fill = |s: &Session| s.doc().unwrap().doc.node(group).unwrap().proxy_paint_only(false, None).unwrap().clone(); + let (art_was, fill_was) = (look(&s, art), fill(&s)); + s.execute(cmd, &json!({"ids": [group.0]})).unwrap(); + assert_eq!(look(&s, art), art_was, "{cmd}"); + assert_ne!(fill(&s), fill_was, "{cmd}: the group's fill is recolored"); + let Paint::Solid { color, .. } = fill(&s) else { panic!("{cmd}: the group's fill is not a solid color") }; + assert_eq!((s.last_solid, s.recent_colors.first().copied()), (color, Some(color)), "{cmd}"); + } + // A gray fill is its own complement: nothing changes, and the remembered colors stay as they were. + let (mut s, group, _) = painted_series("#808080"); + s.execute("select.set", &json!({"ids": []})).unwrap(); + s.execute("paint.setFill", &json!({"color": "#00ff00"})).unwrap(); + let remembered = |s: &Session| format!("{:?}", (s.last_solid, &s.recent_colors)); + let was = remembered(&s); + assert_eq!(s.execute("paint.complement", &json!({"ids": [group.0]})).unwrap()["changed"], json!(0)); + assert_eq!(remembered(&s), was); + // Both series groups hold only the design's art: a gray one first and a red one, given together. + let (mut s, graph, _, _, _) = design_art(); + s.execute("graph.column", &json!({"id": graph.0, "seriesIndexes": [1], "design": "Square"})).unwrap(); + let groups = [0, 1].map(|i| series(s.doc().unwrap().doc.node(graph).unwrap(), i).id); + paint_own(&mut s, groups[0], "#808080"); + paint_own(&mut s, groups[1], "#ff0000"); + s.execute("paint.complement", &json!({"ids": [groups[0].0, groups[1].0]})).unwrap(); + let Some(Paint::Solid { color, .. }) = s.doc().unwrap().doc.node(groups[1]).unwrap().proxy_paint_only(false, None).cloned() else { + panic!("the red group's fill is not a solid color") + }; + assert_eq!((s.last_solid, s.recent_colors.first().copied()), (color, Some(color))); +} + /// `transparency.set` without `item` refuses the art of a graph design in a series, and given it with other objects /// sets only theirs. #[test] diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index ef15f896cd..c37d6519bd 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1149,9 +1149,24 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( return Ok(json!({ "changed": 0 })); } let art = super::appearance::design_art_in(d, &roots).into_iter().collect(); + // The fill or stroke the proxy shows of each group among the roots, before the edit. + let own = |d: &Document, id: NodeId| { + d.node(id) + .filter(|n| matches!(n.kind, NodeKind::Group { .. } | NodeKind::Layer { .. })) + .and_then(|n| n.proxy_paint_only(stroke, None)) + .cloned() + }; + let own_before: Vec> = roots.iter().map(|id| own(d, *id)).collect(); let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": roots.iter().map(|i| i.0).collect::>()}); let r = super::colorcmds::recolor_except(s, &q, cmd, label, f, art)?; - let shown_at = super::appearance::drop_design_art(&s.doc()?.doc, leaf_targets(s, &ids)?).first().map(|id| (*id, None)); + let d = &s.doc()?.doc; + let leaves = super::appearance::drop_design_art(d, leaf_targets(s, &ids)?); + // With only design art inside, which keeps its paint, the first group whose own fill or stroke changed shows it. + let shown_at = leaves + .first() + .copied() + .or_else(|| roots.iter().zip(&own_before).find(|(id, was)| was.is_some() && own(d, **id) != **was).map(|(id, _)| *id)) + .map(|id| (id, None)); (r, shown_at) } }; From f73280731a9f76ebf161ab586a274d069345a45a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 15 Nov 2026 10:07:33 -0800 Subject: [PATCH 14/14] Paint: invert and complement of a group remember the fill its proxy shows paint.invert and paint.complement given a group with a fill or stroke of its own remembered the new paint of the first object inside it, while the Fill and Stroke proxies show the group's own paint. The remembered paint now follows the proxy: for each object given, in order, a group whose own fill or stroke changed gives that paint, otherwise the first object inside it that is not graph design art does. --- crates/engine/src/cmd/graph/tests.rs | 5 +++++ crates/engine/src/cmd/paint.rs | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/graph/tests.rs b/crates/engine/src/cmd/graph/tests.rs index 2ead810dff..ae48718a63 100644 --- a/crates/engine/src/cmd/graph/tests.rs +++ b/crates/engine/src/cmd/graph/tests.rs @@ -635,6 +635,11 @@ fn invert_of_a_group_recolors_its_own_fill_and_leaves_design_art() { assert_ne!(own(&s), own_was, "the group's own fill"); assert_ne!(look(&s, mark), mark_was); assert_eq!(look(&s, art), art_was); + // The color remembered is the group's own new fill, which the Fill proxy shows. + let Some(Paint::Solid { color, .. }) = s.doc().unwrap().doc.node(group).unwrap().proxy_paint_only(false, None).cloned() else { + panic!("the group's fill is not a solid color") + }; + assert_eq!((s.last_solid, s.recent_colors.first().copied()), (color, Some(color))); let (own_was, mark_was) = (own(&s), look(&s, mark)); s.execute("paint.invert", &json!({"ids": [group.0], "target": "contents"})).unwrap(); assert_eq!(own(&s), own_was, "target: contents"); diff --git a/crates/engine/src/cmd/paint.rs b/crates/engine/src/cmd/paint.rs index c37d6519bd..5ae2ebd4c9 100644 --- a/crates/engine/src/cmd/paint.rs +++ b/crates/engine/src/cmd/paint.rs @@ -1156,17 +1156,25 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn( .and_then(|n| n.proxy_paint_only(stroke, None)) .cloned() }; - let own_before: Vec> = roots.iter().map(|id| own(d, *id)).collect(); + let own_before: std::collections::HashMap = roots.iter().filter_map(|id| Some((*id, own(d, *id)?))).collect(); let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": roots.iter().map(|i| i.0).collect::>()}); let r = super::colorcmds::recolor_except(s, &q, cmd, label, f, art)?; + // As the proxy shows a group: its own fill or stroke when the edit changed it, else the first object inside it + // that is not design art (which keeps its paint). The first object given that has either shows it. let d = &s.doc()?.doc; - let leaves = super::appearance::drop_design_art(d, leaf_targets(s, &ids)?); - // With only design art inside, which keeps its paint, the first group whose own fill or stroke changed shows it. - let shown_at = leaves - .first() - .copied() - .or_else(|| roots.iter().zip(&own_before).find(|(id, was)| was.is_some() && own(d, **id) != **was).map(|(id, _)| *id)) - .map(|id| (id, None)); + let mut shown_at = None; + for id in &ids { + if let Some(was) = own_before.get(id) + && own(d, *id).as_ref() != Some(was) + { + shown_at = Some((*id, None)); + break; + } + if let Some(leaf) = super::appearance::drop_design_art(d, leaf_targets(s, &[*id])?).first() { + shown_at = Some((*leaf, None)); + break; + } + } (r, shown_at) } };