diff --git a/crates/engine/src/cmd/clipboard/resources.rs b/crates/engine/src/cmd/clipboard/resources.rs index 56cf4f5b96..9a5be1fc4f 100644 --- a/crates/engine/src/cmd/clipboard/resources.rs +++ b/crates/engine/src/cmd/clipboard/resources.rs @@ -758,14 +758,21 @@ impl Relink { } } } - /// Relink a node tree (the mirror of [`node_refs`]). + /// Relink a node tree (the mirror of [`node_refs`]). A pie's legend labels in wedges that now show a color of the + /// other darkness take the contrast a redraw sets there. fn node(&self, n: &mut Node) { + let shades = crate::cmd::graph::wedge_shades(n); + self.links(n); + crate::cmd::graph::follow_wedge_shades(n, &shades); + } + /// [`Self::node`] without the legend labels' contrast. + fn links(&self, n: &mut Node) { self.appearance(&mut n.appearance); if !self.keep_styles { n.extras_mut().graphic_style = n.extras().graphic_style.and_then(|id| self.styles.get(&id).copied()); } if let Some(m) = n.extras_if_any().and_then(|e| e.mask.as_mut()) { - self.node(Arc::make_mut(&mut m.art)); + self.links(Arc::make_mut(&mut m.art)); } if let Some(cm) = n.extras_if_any().and_then(|e| e.color_mask.as_deref_mut()) { self.name(Res::Image, &mut cm.key); @@ -831,7 +838,7 @@ impl Relink { _ => {} } for c in n.children_mut().into_iter().flatten() { - self.node(Arc::make_mut(c)); + self.links(Arc::make_mut(c)); } } } @@ -1183,9 +1190,7 @@ impl Imported { /// other darkness take the contrast a redraw sets there. Fonts the copy carries are bound to the faces `d` holds. pub(crate) fn apply(&mut self, n: &mut Node, d: &Document) { if self.relinks { - let shades = super::super::graph::wedge_shades(n); self.relink.node(n); - super::super::graph::follow_wedge_shades(n, &shades); } for note in vectorcraft_text::FontDb::global().bind_node_file_fonts(n, &|key| d.images.get(key)) { if !self.warnings.contains(¬e) { diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index c633835697..43151bbebb 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -180,7 +180,7 @@ pub fn specs() -> Vec { "Paste", ["Edit"], Some("Cmd+V"), - "{center?: [x, y], artboardsAt?: [x, y], dx?, dy?, swatchConflict?, profileMismatch?: \"preserveNumbers\"|\"convert\"|{rgb?, cmyk?}} paste centred on `center` (the app passes the view centre), else offset by dx/dy (default: the Paste Offset preference). Pasting brings the image blobs, symbols, patterns, global and spot swatches (with the tint swatches of the tints used), gradient swatches, graphic styles, character and paragraph styles and brushes the objects use; one of the same name that differs comes in renamed. swatchConflict, for a swatch whose name the document gives another colour (clipboard.conflicts): \"merge\" (default: the objects take the document's swatch; legend labels in a pie's wedges that it turns dark or light take a redraw's contrast, unless their fill is their own) | \"add\" (the pasted swatch comes in renamed) | {name: \"merge\"|\"add\"}. profileMismatch, for colors copied from a document whose RGB or CMYK profile is not this document's (clipboard.profileMismatch): \"preserveNumbers\" keeps their numbers, \"convert\" converts them into this document's profile with the working intent, and {rgb?, cmyk?} gives one of those for each model (default, also for a model left out and for null: as the model's policy of edit.colorSettings says; any other value is an error; colors whose source or destination profile is not available keep their numbers, also with \"convert\" (clipboard.profileMismatch's convertible: false); every paste command takes it, and the reply's profileMismatch lists [{model, clipboard, document, choice}]). With Paste Remembers Layers on (layer.pasteRemembersLayers), objects go back into the layers and sublayers they came from (by the names of the layer and the layers around it in another document; a missing sublayer is made inside its layer; a hidden or locked one is an error and nothing is pasted). Artboards copied with artboard.copy come with their art, together right of the last artboard as they lay, or centered on `artboardsAt` (the Artboard tool's canvas menu passes the right-click point; a value that is not [x, y] is an error) (the other paste commands but Paste on All Artboards: where they were), their art back in the layers it came from, and the Artboard tool, when chosen, selects them. In Draw Inside (view.drawMode) the objects go inside the object drawn into, as new art does, and Paste Remembers Layers doesn't apply; edit.pasteInPlace and edit.pasteOnAllArtboards do the same, and in Draw Behind they go behind the selection as edit.pasteInBack puts them; edit.pasteInFront and edit.pasteInBack ignore the drawing mode → {ids, artboard: the first new artboard's index or null, artboards: the new artboards' indices, added: resources added, merged: conflicts merged, renamed: [{kind, from, to}]}", + "{center?: [x, y], artboardsAt?: [x, y], dx?, dy?, swatchConflict?, profileMismatch?: \"preserveNumbers\"|\"convert\"|{rgb?, cmyk?}} paste centred on `center` (the app passes the view centre), else offset by dx/dy (default: the Paste Offset preference). Pasting brings the image blobs, symbols, patterns, global and spot swatches (with the tint swatches of the tints used), gradient swatches, graphic styles, character and paragraph styles and brushes the objects use; one of the same name that differs comes in renamed. swatchConflict, for a swatch whose name the document gives another colour (clipboard.conflicts): \"merge\" (default: the objects take the document's swatch; legend labels in a pie's wedges that it turns dark or light take a redraw's contrast, unless their fill is their own, also for a pie in the art of a symbol, pattern, brush or graph design the paste brings) | \"add\" (the pasted swatch comes in renamed) | {name: \"merge\"|\"add\"}. profileMismatch, for colors copied from a document whose RGB or CMYK profile is not this document's (clipboard.profileMismatch): \"preserveNumbers\" keeps their numbers, \"convert\" converts them into this document's profile with the working intent, and {rgb?, cmyk?} gives one of those for each model (default, also for a model left out and for null: as the model's policy of edit.colorSettings says; any other value is an error; colors whose source or destination profile is not available keep their numbers, also with \"convert\" (clipboard.profileMismatch's convertible: false); every paste command takes it, and the reply's profileMismatch lists [{model, clipboard, document, choice}]). With Paste Remembers Layers on (layer.pasteRemembersLayers), objects go back into the layers and sublayers they came from (by the names of the layer and the layers around it in another document; a missing sublayer is made inside its layer; a hidden or locked one is an error and nothing is pasted). Artboards copied with artboard.copy come with their art, together right of the last artboard as they lay, or centered on `artboardsAt` (the Artboard tool's canvas menu passes the right-click point; a value that is not [x, y] is an error) (the other paste commands but Paste on All Artboards: where they were), their art back in the layers it came from, and the Artboard tool, when chosen, selects them. In Draw Inside (view.drawMode) the objects go inside the object drawn into, as new art does, and Paste Remembers Layers doesn't apply; edit.pasteInPlace and edit.pasteOnAllArtboards do the same, and in Draw Behind they go behind the selection as edit.pasteInBack puts them; edit.pasteInFront and edit.pasteInBack ignore the drawing mode → {ids, artboard: the first new artboard's index or null, artboards: the new artboards' indices, added: resources added, merged: conflicts merged, renamed: [{kind, from, to}]}", has_clipboard, |s, p| paste(s, p, PasteMode::Offset) ), diff --git a/crates/engine/src/tests/clipboard.rs b/crates/engine/src/tests/clipboard.rs index ffb842bca8..7b72a06089 100644 --- a/crates/engine/src/tests/clipboard.rs +++ b/crates/engine/src/tests/clipboard.rs @@ -847,6 +847,87 @@ fn pie_legend_labels_follow_wedges_that_take_the_documents_swatch() { assert_eq!(north, Some(Paint::solid(Color::WHITE)), "in an opacity mask"); } +/// A pie in the art of a symbol or a pattern that a paste brings in follows the document's swatch as a pasted pie does: +/// with Merge, its legend label in the wedge that turned dark is white, and pasting again uses the symbol or pattern the +/// first paste added. With Add the label stays black. +#[test] +fn pie_legend_labels_in_a_pasted_symbol_or_pattern_follow_wedges_that_take_the_documents_swatch() { + let csv = ",North,South\nP,1,1"; + /// A pie with Legends in Wedges whose first wedge is filled with the global swatch "Brand", light yellow. + fn branded_pie(s: &mut Session, csv: &str) -> NodeId { + if doc(s).swatch("Brand").is_none() { + s.execute("swatch.new", &json!({"name": "Brand", "color": "#ffff66", "global": true})).unwrap(); + } + let g = id_of(&s.execute("graph.create", &json!({"type": "pie", "x": 50, "y": 50, "width": 200, "height": 200, "csv": csv})).unwrap()); + s.execute("graph.setType", &json!({"id": g.0, "pieLegend": "wedges"})).unwrap(); + let mut wedges = vec![]; + for c in node(s, g).children().unwrap().iter().filter(|c| c.extras().series_index == Some(0)) { + c.walk(&mut |m| { + if matches!(m.kind, NodeKind::Path { .. }) { + wedges.push(m.id.0); + } + }); + } + assert!(!wedges.is_empty()); + s.execute("paint.setFill", &json!({"ids": wedges, "swatch": "Brand"})).unwrap(); + s.execute("graph.setData", &json!({"id": g.0, "csv": csv})).unwrap(); + g + } + /// The fill of the legend label that says `name` in `art`. + fn label_in(art: &[std::sync::Arc], name: &str) -> Paint { + let mut out = None; + for a in art { + a.walk(&mut |n| { + if let NodeKind::Text(t) = &n.kind + && t.plain_text() == name + { + out = Some(t.first_style().fill.clone()); + } + }); + } + out.unwrap() + } + let symbol_art = |s: &Session| vec![doc(s).symbols.iter().find(|x| x.name == "Chart").unwrap().art.clone()]; + let pattern_art = |s: &Session| doc(s).pattern("Chart").unwrap().art.clone(); + + let mut s = session(); + let g = branded_pie(&mut s, csv); + sel(&mut s, &[g]); + let instance = id_of(&s.execute("symbol.new", &json!({"name": "Chart"})).unwrap()); + assert_eq!(label_in(&symbol_art(&s), "North"), Paint::solid(Color::BLACK), "black on the light wedge"); + copy(&mut s, &[instance]); + for (choice, north) in [("merge", Color::WHITE), ("add", Color::BLACK)] { + new_doc(&mut s); + s.execute("swatch.new", &json!({"name": "Brand", "color": "#202020", "global": true})).unwrap(); + s.execute("edit.paste", &json!({"swatchConflict": choice})).unwrap(); + assert_eq!(label_in(&symbol_art(&s), "North"), Paint::solid(north), "symbol {choice}"); + assert_eq!(label_in(&symbol_art(&s), "South"), Paint::solid(Color::BLACK), "symbol {choice}"); + // Pasting again uses the symbol the first paste added. + s.execute("edit.paste", &json!({"swatchConflict": choice})).unwrap(); + let names: Vec<&str> = doc(&s).symbols.iter().map(|x| x.name.as_str()).collect(); + assert_eq!(names, ["Chart"], "symbol {choice}"); + } + + let mut s = session(); + let g = branded_pie(&mut s, csv); + s.execute("object.pattern.make", &json!({"name": "Chart", "edit": false, "ids": [g.0]})).unwrap(); + assert_eq!(label_in(&pattern_art(&s), "North"), Paint::solid(Color::BLACK), "black on the light wedge"); + let r = rect(&mut s, 300.0, 300.0, 100.0, 100.0); + s.execute("paint.setFill", &json!({"ids": [r.0], "swatch": "Chart"})).unwrap(); + copy(&mut s, &[r]); + for (choice, north) in [("merge", Color::WHITE), ("add", Color::BLACK)] { + new_doc(&mut s); + s.execute("swatch.new", &json!({"name": "Brand", "color": "#202020", "global": true})).unwrap(); + s.execute("edit.paste", &json!({"swatchConflict": choice})).unwrap(); + assert_eq!(label_in(&pattern_art(&s), "North"), Paint::solid(north), "pattern {choice}"); + assert_eq!(label_in(&pattern_art(&s), "South"), Paint::solid(Color::BLACK), "pattern {choice}"); + // Pasting again uses the pattern the first paste added. + s.execute("edit.paste", &json!({"swatchConflict": choice})).unwrap(); + let names: Vec<&str> = doc(&s).patterns.iter().map(|x| x.name.as_str()).collect(); + assert_eq!(names, ["Chart"], "pattern {choice}"); + } +} + /// A two-line legend label in a narrow dark wedge, whose text sits off the wedge's middle line, stays white when its graph /// is pasted without formatting. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 83c92e63cb..b24b3e06eb 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -10224,7 +10224,8 @@ them (with `allArtboards: true`, the colors as Paste on All Artboards brings the copied artboards), and `swatchConflict` answers: `"merge"` (the default: the objects take the document's swatch), `"add"` (the pasted swatch comes in renamed) or one answer per name. When a merged swatch turns a pie's wedge from light to dark or back, the legend labels in that pie's wedges take the contrast a redraw gives them (white on a dark wedge, black on -a light one), unless the legend labels have a fill of their own. Pasting back into the document the objects came from +a light one), unless the legend labels have a fill of their own. The same applies to a pie in the art of a symbol, +pattern, brush or graph design that the paste brings in. Pasting back into the document the objects came from uses its resources as they are now and raises no conflict. Placement: `edit.paste {center}` centres the objects on a point (the app passes the view centre), else offsets them