mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Merge pull request #8942 from dotCooCoo/fix/paste-all-artboards-conflicts
Paste on All Artboards: swatch conflicts leave copied artboard backgrounds out
This commit is contained in:
6 files changed
+77
-13
No files matched your search
@@ -47,7 +47,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Swatch Conflicts",
|
||||
[],
|
||||
None,
|
||||
"{profileMismatch?: as edit.paste} → {swatches: [{name, document, clipboard, spot}]} the global or spot swatches the copied objects use whose name the active document gives another colour (`document`/`clipboard`: #rrggbb, the pasted colour as the paste brings it, converted when profileMismatch or the policy converts it): Paste asks Merge or Add for each (pass the answer as edit.paste* {swatchConflict}). Pasting back into the document the objects came from raises none, unless the paste converts its colours",
|
||||
"{profileMismatch?: as edit.paste, allArtboards?: false (true: for edit.pasteOnAllArtboards, which leaves the background colors of copied artboards behind)} → {swatches: [{name, document, clipboard, spot}]} the global or spot swatches the copied objects use whose name the active document gives another colour (`document`/`clipboard`: #rrggbb, the pasted colour as the paste brings it, converted when profileMismatch or the policy converts it): Paste asks Merge or Add for each (pass the answer as edit.paste* {swatchConflict}). Pasting back into the document the objects came from raises none, unless the paste converts its colours",
|
||||
has_doc,
|
||||
conflicts
|
||||
),
|
||||
@@ -568,9 +568,12 @@ fn import_svg(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
fn conflicts(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let hex = |w: &Swatch| w.paint.color().map(|c| c.to_hex());
|
||||
// The swatches as the paste brings them: converted from another profile when it converts.
|
||||
let profile = super::colormgmt::PasteProfile::param(p, "clipboard.conflicts")?;
|
||||
const CMD: &str = "clipboard.conflicts";
|
||||
let profile = super::colormgmt::PasteProfile::param(p, CMD)?;
|
||||
// Paste on All Artboards leaves the copied artboards, and so their backgrounds, behind.
|
||||
let all_artboards = super::switch_or(p, "allArtboards", false, CMD)?;
|
||||
let st = s.doc()?;
|
||||
let (converted, _) = super::colormgmt::paste_profiles(&s.clipboard, &st.doc, profile, true);
|
||||
let (converted, _) = super::colormgmt::paste_profiles(&s.clipboard, &st.doc, profile, !all_artboards);
|
||||
let list: Vec<Value> = converted
|
||||
.as_ref()
|
||||
.unwrap_or(&s.clipboard)
|
||||
|
||||
@@ -1793,6 +1793,37 @@ fn paste_on_all_artboards_leaves_artboard_backgrounds_out() {
|
||||
assert!(r.get("profileMismatch").is_none(), "{r}");
|
||||
}
|
||||
|
||||
/// The swatch conflicts Paste on All Artboards raises leave copied artboard backgrounds out, as the
|
||||
/// paste does: pasting back into the document the objects came from, where only the RGB background
|
||||
/// of the copied artboard now has another profile, converts nothing for it, so its edited CMYK
|
||||
/// swatch raises no conflict. A plain paste, which brings the background and converts it, compares
|
||||
/// the swatches and lists the edited one.
|
||||
#[test]
|
||||
fn swatch_conflicts_on_all_artboards_leave_artboard_backgrounds_out() {
|
||||
let _g = settings();
|
||||
let _reset = ColorSettingsReset { profile: None, paths: vec![] };
|
||||
let mut s = session();
|
||||
exec(&mut s, "swatch.new", json!({"name": "Brand", "color": {"c": 20, "m": 40, "y": 60, "k": 10}, "global": true}));
|
||||
let ink = rect(&mut s, 0.0, 0.0, 10.0, 10.0);
|
||||
exec(&mut s, "paint.setFill", json!({"ids": [ink.0], "swatch": "Brand"}));
|
||||
exec(&mut s, "paint.setStroke", json!({"ids": [ink.0], "none": true}));
|
||||
exec(&mut s, "artboard.setProps", json!({"index": 0, "color": "#3366cc"}));
|
||||
exec(&mut s, "edit.assignProfile", json!({"rgb": cms::WIDE_GAMUT_RGB}));
|
||||
exec(&mut s, "artboard.copy", json!({"index": 0}));
|
||||
exec(&mut s, "edit.assignProfile", json!({"rgb": null}));
|
||||
exec(&mut s, "swatch.edit", json!({"name": "Brand", "color": {"c": 60, "m": 40, "y": 20, "k": 0}}));
|
||||
let conflicts = |s: &mut Session, p: serde_json::Value| exec(s, "clipboard.conflicts", p)["swatches"].as_array().unwrap().len();
|
||||
assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert"})), 1, "a plain paste converts the RGB background");
|
||||
assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert", "allArtboards": true})), 0);
|
||||
assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert", "allArtboards": false})), 1);
|
||||
assert_eq!(conflicts(&mut s, json!({"profileMismatch": "convert", "allArtboards": null})), 1, "null is the default");
|
||||
for bad in [json!("yes"), json!(1)] {
|
||||
assert!(s.execute("clipboard.conflicts", &json!({ "allArtboards": bad })).is_err(), "{bad}");
|
||||
}
|
||||
let r = exec(&mut s, "edit.pasteOnAllArtboards", json!({"profileMismatch": "convert"}));
|
||||
assert!(r.get("profileMismatch").is_none(), "{r}");
|
||||
}
|
||||
|
||||
/// A converting paste back into the document the objects came from (its profile changed since the
|
||||
/// copy) still takes its image blobs as the document's own: an image whose blob under its key
|
||||
/// changed since keeps that key, and so shows the document's blob.
|
||||
|
||||
@@ -475,6 +475,7 @@ fn opening_and_pasting_ask_about_profiles() {
|
||||
assert_eq!(count(&app), before + 1);
|
||||
swatch_conflicts_are_asked_again_when_they_change(&mut app);
|
||||
all_artboards_leaves_backgrounds_out(&mut app);
|
||||
all_artboards_asks_no_swatch_conflict_for_backgrounds(&mut app);
|
||||
// It changes the working space: last.
|
||||
app.run("edit.colorSettings", json!({"askMismatchOpen": true})).unwrap();
|
||||
an_answer_waits_for_the_question_it_answers(&mut app, &tagged);
|
||||
@@ -500,3 +501,27 @@ fn all_artboards_leaves_backgrounds_out(app: &mut VectorcraftApp) {
|
||||
assert_eq!(listed(app, "edit.paste"), Some(1), "the background is RGB");
|
||||
assert_eq!(listed(app, ALL_ARTBOARDS), Some(0));
|
||||
}
|
||||
|
||||
/// Swatch Conflict for Paste on All Artboards asks about the colors it brings, without the
|
||||
/// backgrounds of copied artboards: pasting back into the document the art came from, where only
|
||||
/// the RGB background now has another profile, converts nothing, so the edited CMYK swatch is no
|
||||
/// conflict and the paste runs. A plain paste converts the background and asks.
|
||||
fn all_artboards_asks_no_swatch_conflict_for_backgrounds(app: &mut VectorcraftApp) {
|
||||
use super::super::swatch_conflict;
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
app.run("swatch.new", json!({"name": "Brand", "color": {"c": 20, "m": 40, "y": 60, "k": 10}, "global": true})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
|
||||
app.run("paint.setFill", json!({"swatch": "Brand"})).unwrap();
|
||||
app.run("paint.setStroke", json!({"none": true})).unwrap();
|
||||
app.run("artboard.setProps", json!({"index": 0, "color": "#3366cc"})).unwrap();
|
||||
app.run("edit.assignProfile", json!({ "rgb": cms::WIDE_GAMUT_RGB })).unwrap();
|
||||
app.run("artboard.copy", json!({"index": 0})).unwrap();
|
||||
app.run("edit.assignProfile", json!({ "rgb": null })).unwrap();
|
||||
app.run("swatch.edit", json!({"name": "Brand", "color": {"c": 60, "m": 40, "y": 20, "k": 0}})).unwrap();
|
||||
let r = app.run("edit.paste", json!({"profileMismatch": "convert"})).unwrap();
|
||||
assert_eq!(r["dialog"], swatch_conflict::KIND, "{r}");
|
||||
answer_cancel(app, swatch_conflict::id(app).expect("Swatch Conflict is open"));
|
||||
let r = app.run(ALL_ARTBOARDS, json!({"profileMismatch": "convert"})).unwrap();
|
||||
assert!(r.get("dialog").is_none() && r["ids"].as_array().is_some_and(|ids| !ids.is_empty()), "{r}");
|
||||
assert!(swatch_conflict::id(app).is_none());
|
||||
}
|
||||
@@ -220,7 +220,7 @@ pub fn ask(app: &mut VectorcraftApp, command: &str, params: &Value) -> Option<Re
|
||||
if params.get("swatchConflict").is_some() {
|
||||
return None;
|
||||
}
|
||||
let conflicts = found(app, params).filter(|a| !a.is_empty())?;
|
||||
let conflicts = found(app, command, params).filter(|a| !a.is_empty())?;
|
||||
let dialog = SwatchConflictDialog::new(conflicts, command, params, app.session.active().map(|doc| doc.uid));
|
||||
let Some(host) = app.dialogs() else { return Some(Err(NO_WINDOW.into())) };
|
||||
host.with(|h| h.open(dialog));
|
||||
@@ -258,19 +258,23 @@ pub(crate) fn defer(app: &VectorcraftApp, chain: u64) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the conflicts the paste with `params` raises are no longer the `asked` ones (another profile converts
|
||||
/// the pasted swatches meanwhile): it asks about them again.
|
||||
pub(crate) fn changed(app: &mut VectorcraftApp, params: &Value, asked: &Value) -> bool {
|
||||
found(app, params).is_some_and(|now| Value::Array(now) != *asked)
|
||||
/// Whether the conflicts paste `command` with `params` raises are no longer the `asked` ones (another profile
|
||||
/// converts the pasted swatches meanwhile): it asks about them again.
|
||||
pub(crate) fn changed(app: &mut VectorcraftApp, command: &str, params: &Value, asked: &Value) -> bool {
|
||||
found(app, command, params).is_some_and(|now| Value::Array(now) != *asked)
|
||||
}
|
||||
|
||||
/// The swatch conflicts pasting with `params` raises (`clipboard.conflicts`), with the swatches as
|
||||
/// the paste brings them: converted from another profile when it converts.
|
||||
fn found(app: &mut VectorcraftApp, params: &Value) -> Option<Vec<Value>> {
|
||||
/// The swatch conflicts paste `command` with `params` raises (`clipboard.conflicts`), with the
|
||||
/// swatches as the paste brings them: converted from another profile when it converts, and for
|
||||
/// Paste on All Artboards without the backgrounds of copied artboards, which it leaves behind.
|
||||
fn found(app: &mut VectorcraftApp, command: &str, params: &Value) -> Option<Vec<Value>> {
|
||||
let mut q = json!({});
|
||||
if let Some(m) = params.get("profileMismatch") {
|
||||
q["profileMismatch"] = m.clone();
|
||||
}
|
||||
if command == "edit.pasteOnAllArtboards" {
|
||||
q["allArtboards"] = json!(true);
|
||||
}
|
||||
let found = app.session.execute("clipboard.conflicts", &q).ok()?;
|
||||
found["swatches"].as_array().cloned()
|
||||
}
|
||||
@@ -658,7 +658,7 @@ pub(crate) fn settle_swatch_paste(app: &mut VectorcraftApp) {
|
||||
let command = answer["command"].as_str().unwrap_or_default().to_string();
|
||||
let seen = answer["asked"].clone();
|
||||
let changed = |app: &mut VectorcraftApp, command: &str, params: &Value| match question {
|
||||
Question::SwatchConflict => crate::dialogs::swatch_conflict::changed(app, params, &seen),
|
||||
Question::SwatchConflict => crate::dialogs::swatch_conflict::changed(app, command, params, &seen),
|
||||
Question::ProfileMismatch => {
|
||||
crate::dialogs::profile_mismatch::paste_changed(app, command, params, seen.as_array().map_or(&[], Vec::as_slice))
|
||||
}
|
||||
|
||||
+2
-1
@@ -9812,7 +9812,8 @@ light one, by the wedge colors as pasted: a wedge linked to a swatch merged with
|
||||
color first.
|
||||
|
||||
A global or spot swatch whose name the document gives another colour is a conflict: `clipboard.conflicts` lists
|
||||
them, and `swatchConflict` answers: `"merge"` (the default: the objects take the document's swatch), `"add"` (the
|
||||
them (with `allArtboards: true`, the colors as Paste on All Artboards brings them, without the background colors of
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user