diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index c3dbf78293..18951b9c90 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -995,7 +995,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.recolorDialog", "Recolor Artwork…", "", - "{colors?: n (an n-colour job: n rows, Scale Tints) | [colour] (new colours to assign, in order; with no art selected and no group they are the rows, and OK saves them as a new colour group, field `groupName`: the Color Guide's Edit or Apply Colors), library?: id or name; or \"document\" (Limit to Library; \"\" the first library), group?: colour group (Edit or Apply Color Group: OK rewrites the group with the new colours and recolours the selected art, if any)} open Recolor Artwork (dialog `recolor`; engine: recolor.reduce / recolor.apply)", + "{colors?: n (an n-colour job: n rows, Scale Tints) | [colour] (new colours to assign, in order; with no art selected and no group they are the rows, and OK saves them as a new colour group, field `groupName`: the Color Guide's Edit or Apply Colors), library?: id or name; or \"document\" (Limit to Library; \"\" the first library), group?: colour group (Edit or Apply Color Group: OK rewrites the group with the new colours and recolours the selected art, if any), preset?: bool (Recolor with Preset: first open the `recolorPreset` dialog, whose Limit to Library field `limitTo` starts on `library`; its OK opens Recolor Artwork with `colors` and that library)} open Recolor Artwork (dialog `recolor`; engine: recolor.reduce / recolor.apply)", ), ( "ui.recolorUndo", diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index a24755ab12..0376bf83f3 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -113,6 +113,7 @@ mod psd_options; pub mod raster_effects; pub mod rearrange_artboards; pub mod recolor; +pub mod recolor_preset; mod recovery; pub mod relink; pub mod rename_artboards; @@ -337,6 +338,7 @@ registry! { ArtboardOptions: [artboard_options::KIND] => artboard_options::SPEC, ExportForScreens: ["exportForScreens"] => export_for_screens::SPEC, Recolor: [recolor::KIND] => recolor::SPEC, + RecolorPreset: [recolor_preset::KIND] => recolor_preset::SPEC, Command: ["command"] => command::SPEC, Variables: [variables::KIND] => variables::SPEC, Effect: ["effect"] => effect::SPEC, diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index 1b80ce5e35..2901c69bd9 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -192,6 +192,11 @@ const COMPS: &str = "__comps"; /// rows, which OK saves as a new colour group); `library` limits to a library or "document" ("" /// picks the first library). pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { + match p.get("preset") { + None | Some(Value::Bool(false)) => {} + Some(Value::Bool(true)) => return super::recolor_preset::open(app, p), + Some(_) => return Err("`preset` must be true or false".into()), + } let st = app.session.active().ok_or("no document open")?; let art = !st.selection.is_empty(); let group = p.get("group").and_then(Value::as_str); @@ -217,11 +222,7 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { None if !assign.is_empty() => json!(assign.len()), None => Value::Null, }; - let limit = match p.get("library").and_then(Value::as_str) { - Some("") => first_library(app).unwrap_or_default(), - Some(l) => limit_key(app, l)?, - None => String::new(), - }; + let limit = library_param(app, p)?; // Without art the rows are the group's colours, as they are. let mut start: Vec = if art { vec![] } else { assign.iter().map(|k| json!({"from": [k], "to": k})).collect() }; number_slots(&mut start); @@ -241,6 +242,10 @@ pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { snap(app, &d, &mut rs); d.fields.insert("rows".into(), Value::Array(rs)); // Undo Changes has nothing to undo on a new opening. + // A dialog this one replaces ends as Cancel ends it, its preview rolled back. + if app.ui.dialog.is_some() { + super::cancel(app); + } app.ui.recolor_history = History { opened: Some(snapshot(&d)), ..History::default() }; app.ui.dialog = Some(d); Ok(Value::Null) @@ -253,6 +258,27 @@ fn key(c: &Color) -> Value { /// The name a new colour group (opened on colours alone) starts with. const NEW_GROUP: &str = "Color Group"; +/// Limit to Library's choices, as keys of `limitTo` and the names shown: None, the document's +/// swatches, then the colour libraries: the built-in ones (at the top level of the library menu) +/// translated, those the user saved or loaded by their names. +pub(super) fn library_choices(app: &VectorcraftApp) -> (Vec, Vec) { + let libs = colour_libraries(app); + let keys = ["", swatchlib::DOCUMENT_SWATCHES].into_iter().map(String::from).chain(libs.iter().map(|l| l.id.clone())).collect(); + let names: Vec<&str> = ["None", DOCUMENT_SWATCHES].into_iter().chain(libs.iter().map(|l| l.name.as_str())).collect(); + let builtin = |k: usize| k.checked_sub(2).is_none_or(|i| libs.get(i).is_some_and(|l| l.submenu.is_none())); + let shown = super::shown_names(crate::i18n::current(), &names, builtin).into_iter().map(String::from).collect(); + (keys, shown) +} + +/// The `limitTo` key of `ui.recolorDialog`'s `library` (none without it, the first library for ""). +pub(super) fn library_param(app: &VectorcraftApp, p: &Value) -> Result { + match p.get("library").and_then(Value::as_str) { + Some("") => Ok(first_library(app).unwrap_or_default()), + Some(l) => limit_key(app, l), + None => Ok(String::new()), + } +} + fn first_library(app: &VectorcraftApp) -> Option { colour_libraries(app).into_iter().next().map(|l| l.id) } @@ -1956,13 +1982,8 @@ fn assign_tab(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut } ui.end_row(); ui.label(egui::RichText::new(tl!("Limit to Library:")).color(t.text_dim)); - // None, the document's swatches, then the colour libraries: the built-in ones (at the top - // level of the library menu) translated, those the user saved or loaded by their names. - let libs = colour_libraries(app); - let keys: Vec<&str> = ["", swatchlib::DOCUMENT_SWATCHES].into_iter().chain(libs.iter().map(|l| l.id.as_str())).collect(); - let names: Vec<&str> = ["None", DOCUMENT_SWATCHES].into_iter().chain(libs.iter().map(|l| l.name.as_str())).collect(); - let builtin = |k: usize| k.checked_sub(2).is_none_or(|i| libs.get(i).is_some_and(|l| l.submenu.is_none())); - let shown = super::shown_names(crate::i18n::current(), &names, builtin); + let (keys, shown) = library_choices(app); + let shown: Vec<&str> = shown.iter().map(String::as_str).collect(); let cur = d.str("limitTo"); let at = keys.iter().position(|k| *k == cur).unwrap_or(0); let current = shown.get(at).copied().unwrap_or_default(); diff --git a/crates/ui-egui/src/dialogs/recolor_preset.rs b/crates/ui-egui/src/dialogs/recolor_preset.rs new file mode 100644 index 0000000000..a9063c8945 --- /dev/null +++ b/crates/ui-egui/src/dialogs/recolor_preset.rs @@ -0,0 +1,77 @@ +//! Edit → Edit Colors → Recolor with Preset: before Recolor Artwork opens on a preset (an n-color +//! job or Color Library), this dialog asks whether to limit the new colors to a swatch library +//! (`ui.recolorDialog {preset: true, colors?, library?}`). OK opens Recolor Artwork with the +//! preset's colors and the library chosen (None: no limit); Cancel opens nothing. +//! +//! Fields: `colors` (the preset's count, null for Color Library) and `limitTo` (a library id, +//! `"document"` for the document's swatches, `""` for None), as Recolor Artwork's. + +use serde_json::{Value, json}; + +use super::DialogSpec; +use super::recolor::{library_choices, library_param}; +use super::swatch_options::{grid, label}; +use crate::state::Dialog; +use crate::{VectorcraftApp, widgets}; + +/// The dialog kind of Recolor with Preset. +pub const KIND: &str = "recolorPreset"; + +pub(super) const SPEC: DialogSpec = + DialogSpec { heading: |_| tl!("Recolor with Preset").into(), body, confirm, min_width: 340.0, ..DialogSpec::FORM }; + +/// Open the dialog for the preset of `p` (`colors`: a count; `library`: the library it starts on, +/// "" the first library) on the selected art. +pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result { + let st = app.session.active().ok_or("no document open")?; + if st.selection.is_empty() { + return Err("select artwork to recolor".into()); + } + let colors = count(p.get("colors"))?; + let limit = library_param(app, p)?; + // A dialog this one replaces ends as Cancel ends it, its preview rolled back. + if app.ui.dialog.is_some() { + super::cancel(app); + } + app.ui.dialog = Some(Dialog::new(KIND, json!({"colors": colors, "limitTo": limit}))); + Ok(Value::Null) +} + +/// The preset's count of new colors: none for Color Library, else at least 1. +fn count(v: Option<&Value>) -> Result { + match v { + None | Some(Value::Null) => Ok(Value::Null), + Some(n) => Ok(json!(n.as_u64().filter(|n| *n >= 1).ok_or("`colors` must be a count of at least 1")?)), + } +} + +fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { + let (keys, shown) = library_choices(app); + let shown: Vec<&str> = shown.iter().map(String::as_str).collect(); + let cur = d.str("limitTo"); + let at = keys.iter().position(|k| *k == cur).unwrap_or(0); + let current = shown.get(at).copied().unwrap_or_default(); + grid(ui, |ui| { + label(ui, tl!("Limit to Library:")); + let library = ui.name_inputs(tl!("Limit to Library:"), |ui| widgets::dropdown_names(ui, "recolor-preset-library", current, &shown, 200.0)); + if let Some(k) = library.and_then(|i| keys.get(i)) { + d.fields.insert("limitTo".into(), json!(k)); + } + ui.end_row(); + }); + false +} + +fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { + let mut p = serde_json::Map::new(); + let n = count(d.fields.get("colors"))?; + if !n.is_null() { + p.insert("colors".into(), n); + } + let limit = d.str("limitTo"); + if !limit.is_empty() { + p.insert("library".into(), json!(limit)); + } + // Recolor Artwork takes the dialog's place; when it cannot open, this dialog stays. + super::recolor::open(app, &Value::Object(p)) +} diff --git a/crates/ui-egui/src/menus/tree.rs b/crates/ui-egui/src/menus/tree.rs index 3e68b98c92..c0f10056cc 100644 --- a/crates/ui-egui/src/menus/tree.rs +++ b/crates/ui-egui/src/menus/tree.rs @@ -109,10 +109,10 @@ pub fn menu_tree_named(english_names: bool) -> Vec<(&'static str, Vec)> { sub( "Recolor with Preset", vec![ - cp("1 Color Job…", "ui.recolorDialog", json!({"colors": 1})), - cp("2 Color Job…", "ui.recolorDialog", json!({"colors": 2})), - cp("3 Color Job…", "ui.recolorDialog", json!({"colors": 3})), - cp("Color Library…", "ui.recolorDialog", json!({"library": ""})), + cp("1 Color Job…", "ui.recolorDialog", json!({"colors": 1, "preset": true})), + cp("2 Color Job…", "ui.recolorDialog", json!({"colors": 2, "preset": true})), + cp("3 Color Job…", "ui.recolorDialog", json!({"colors": 3, "preset": true})), + cp("Color Library…", "ui.recolorDialog", json!({"library": "", "preset": true})), ], ), c("Adjust Color Balance…", "ui.colorBalanceDialog"), diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index d2c72aae40..27bcf98155 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -996,7 +996,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "ui.recolorDialog", "Recolor Artwork…", "", - "{colors?: n (an n-colour job: n rows, Scale Tints) | [colour] (new colours to assign, in order; with no art selected and no group they are the rows, and OK saves them as a new colour group, field `groupName`: the Color Guide's Edit or Apply Colors), library?: id or name; or \"document\" (Limit to Library; \"\" the first library), group?: colour group (Edit or Apply Color Group: OK rewrites the group with the new colours and recolours the selected art, if any)} open Recolor Artwork (dialog `recolor`; engine: recolor.reduce / recolor.apply)", + "{colors?: n (an n-colour job: n rows, Scale Tints) | [colour] (new colours to assign, in order; with no art selected and no group they are the rows, and OK saves them as a new colour group, field `groupName`: the Color Guide's Edit or Apply Colors), library?: id or name; or \"document\" (Limit to Library; \"\" the first library), group?: colour group (Edit or Apply Color Group: OK rewrites the group with the new colours and recolours the selected art, if any), preset?: bool (Recolor with Preset: first open the `recolorPreset` dialog, whose Limit to Library field `limitTo` starts on `library`; its OK opens Recolor Artwork with `colors` and that library)} open Recolor Artwork (dialog `recolor`; engine: recolor.reduce / recolor.apply)", ), ( "ui.recolorUndo", diff --git a/crates/ui-egui/src/tests/recolor.rs b/crates/ui-egui/src/tests/recolor.rs index 986dbb6290..d55b9f1882 100644 --- a/crates/ui-egui/src/tests/recolor.rs +++ b/crates/ui-egui/src/tests/recolor.rs @@ -104,6 +104,7 @@ fn presets_open_colour_jobs_and_libraries_and_both_tabs_draw() { entries.iter().filter(|e| e.path.last().is_some_and(|p| p == "Recolor with Preset")).map(|e| (e.label.as_str(), &e.params)).collect(); assert_eq!(presets.iter().map(|p| p.0).collect::>(), ["1 Color Job…", "2 Color Job…", "3 Color Job…", "Color Library…"]); app.run("ui.recolorDialog", presets[1].1.clone()).unwrap(); + dialogs::confirm(&mut app).unwrap(); dialog_frame(&mut app, &ctx); assert_eq!((field(&app, "colors"), field(&app, "method")), (json!(2), json!("scaleTints"))); assert_eq!(field(&app, "rows").as_array().unwrap().len(), 2); @@ -111,6 +112,8 @@ fn presets_open_colour_jobs_and_libraries_and_both_tabs_draw() { dialog_frame(&mut app, &ctx); dialogs::cancel(&mut app); app.run("ui.recolorDialog", presets[3].1.clone()).unwrap(); + assert_eq!(field(&app, "limitTo"), "web-safe-216", "Color Library asks with the first library chosen"); + dialogs::confirm(&mut app).unwrap(); assert_eq!(field(&app, "limitTo"), "web-safe-216", "Color Library starts on the first library"); dialog_frame(&mut app, &ctx); let web = |k: &Value| vectorcraft_engine::cmd::color_value(k).unwrap().to_rgb().iter().all(|v| ((v * 5.0).round() - v * 5.0).abs() < 1e-3); @@ -1992,3 +1995,184 @@ fn the_color_picker_leaves_the_dialog_in_place() { } assert_eq!(h.state().ui.dialog.as_ref().map(|d| d.kind.as_str()), Some("recolor")); } + +fn dialog_kind(app: &VectorcraftApp) -> Option<&str> { + app.ui.dialog.as_ref().map(|d| d.kind.as_str()) +} + +/// Edit › Edit Colors › Recolor with Preset asks whether to limit the colors to a swatch library +/// before Recolor Artwork opens: Cancel opens nothing, and OK opens Recolor Artwork with the +/// preset's colors and the library chosen. +#[test] +fn recolor_with_preset_asks_for_a_library_first() { + let mut app = app(); + let ctx = context(); + assert!(app.run("ui.recolorDialog", json!({"colors": 1, "preset": true})).is_err(), "nothing selected"); + assert_eq!(dialog_kind(&app), None); + art(&mut app, &["#333333", "#999999"]); + assert!(app.run("ui.recolorDialog", json!({"colors": 1, "preset": 1})).is_err(), "`preset` is true or false"); + assert!(app.run("ui.recolorDialog", json!({"colors": 0, "preset": true})).is_err(), "a preset has at least one color"); + assert_eq!(dialog_kind(&app), None); + let entries = crate::menus::menu_entries(&app); + let presets: Vec = + entries.iter().filter(|e| e.path.last().is_some_and(|p| p == "Recolor with Preset")).map(|e| e.params.clone()).collect(); + assert_eq!(presets.len(), 4); + for p in &presets { + app.run("ui.recolorDialog", p.clone()).unwrap(); + assert_eq!(dialog_kind(&app), Some(dialogs::recolor_preset::KIND), "{p}"); + dialog_frame(&mut app, &ctx); + dialogs::cancel(&mut app); + assert_eq!(dialog_kind(&app), None, "Cancel opens nothing: {p}"); + } + // A preset opened over Recolor Artwork's preview rolls the preview back. + let start = colors(&mut app); + app.run("ui.recolorDialog", json!({})).unwrap(); + set(&mut app, "colors", json!(1)); + set(&mut app, "method", json!("exact")); + dialog_frame(&mut app, &ctx); + assert_eq!(colors(&mut app), 1, "previewed"); + app.run("ui.recolorDialog", presets[0].clone()).unwrap(); + assert_eq!(dialog_kind(&app), Some(dialogs::recolor_preset::KIND)); + assert_eq!(colors(&mut app), start, "the preview is rolled back"); + assert_eq!(field(&app, "limitTo"), json!(""), "a color job starts on None"); + set(&mut app, "colors", json!("two")); + assert!(dialogs::confirm(&mut app).is_err(), "the count is checked again on OK"); + assert_eq!(dialog_kind(&app), Some(dialogs::recolor_preset::KIND), "the dialog stays"); + set(&mut app, "colors", json!(1)); + set(&mut app, "limitTo", json!("document")); + dialogs::confirm(&mut app).unwrap(); + assert_eq!(dialog_kind(&app), Some(dialogs::recolor::KIND)); + assert_eq!((field(&app, "colors"), field(&app, "method"), field(&app, "limitTo")), (json!(1), json!("scaleTints"), json!("document"))); + // Recolor Artwork opened over its own preview rolls that preview back too. + set(&mut app, "method", json!("exact")); + set(&mut app, "limitTo", json!("")); + dialog_frame(&mut app, &ctx); + assert_eq!(colors(&mut app), 1, "previewed"); + app.run("ui.recolorDialog", json!({})).unwrap(); + assert_eq!(colors(&mut app), start, "the preview is rolled back"); + dialogs::cancel(&mut app); +} + +/// Every paint under `v`, in order: its color, the swatch it is linked to and its tint. +fn paints_in(v: &Value, out: &mut Vec<(Color, Option, f64)>) { + match v { + Value::Object(m) => { + if let Some(c) = m.get("color").and_then(|c| serde_json::from_value::(c.clone()).ok()) { + out.push((c, m.get("swatch").and_then(Value::as_str).map(String::from), m.get("tint").and_then(Value::as_f64).unwrap_or(1.0))); + } + m.values().for_each(|x| paints_in(x, out)); + } + Value::Array(a) => a.iter().for_each(|x| paints_in(x, out)), + _ => {} + } +} + +/// Every number under an `opacity` key under `v`, in order. +fn opacities_in(v: &Value, out: &mut Vec) { + match v { + Value::Object(m) => { + out.extend(m.get("opacity").and_then(Value::as_f64)); + m.values().for_each(|x| opacities_in(x, out)); + } + Value::Array(a) => a.iter().for_each(|x| opacities_in(x, out)), + _ => {} + } +} + +/// The art of every layer as saved. +fn art_json(app: &VectorcraftApp) -> Value { + let d = &app.session.doc().unwrap().doc; + Value::Array(d.layers.iter().filter_map(|l| l.children()).map(|c| serde_json::to_value(c).unwrap()).collect()) +} + +fn art_paints(app: &VectorcraftApp) -> Vec<(Color, Option, f64)> { + let mut out = vec![]; + paints_in(&art_json(app), &mut out); + out +} + +/// A gray other than black or white, with its lightness. +fn gray(c: &Color) -> Option { + let [r, g, b] = c.to_rgb(); + ((r - g).abs() < 1e-3 && (g - b).abs() < 1e-3 && r > 0.01 && r < 0.99).then_some(r) +} + +/// Gray art placed from an SVG file (fills, a stroke, a group at 50% opacity, `fill-opacity`, a +/// compound path, a gradient's stops and type) with a 1 Color Job of Recolor with Preset limited +/// to the document's swatches and a spot or global ink picked for its row becomes tints of that +/// ink linked to its swatch, darker grays at higher tints, with its opacities kept; editing the +/// swatch then recolors the art at the same tints. A process swatch gives tints of its color with +/// no link. +#[test] +fn a_one_color_job_limited_to_document_swatches_links_gray_art_to_the_ink() { + let svg = r##"Ink"##; + let path = std::env::temp_dir().join(format!("vectorcraft-recolor-preset-{}.svg", std::process::id())); + std::fs::write(&path, svg).unwrap(); + for (kind, options, linked) in [("spot", json!({"spot": true}), true), ("global", json!({"global": true}), true), ("process", json!({}), false)] { + let mut app = app(); + let ctx = context(); + let mut swatch = json!({"name": "Ink", "color": "cmyk 0 100 0 0"}); + swatch.as_object_mut().unwrap().extend(options.as_object().unwrap().clone()); + app.run("swatch.new", swatch).unwrap(); + app.run("file.place", json!({"path": path.to_string_lossy(), "at": [120, 50]})).unwrap(); + app.run("select.all", json!({})).unwrap(); + let before = art_paints(&app); + let grays: Vec = (0..before.len()).filter(|&i| gray(&before[i].0).is_some()).collect(); + assert!(grays.len() >= 9, "{kind}: the fills, the stroke, the stops and the type are gray: {before:?}"); + let mut opacities = vec![]; + opacities_in(&art_json(&app), &mut opacities); + assert!(opacities.iter().any(|o| (o - 0.5).abs() < 1e-6), "the group's opacity came in: {opacities:?}"); + assert!(opacities.iter().any(|o| (o - 0.7).abs() < 1e-6), "the fill opacity came in: {opacities:?}"); + + let entries = crate::menus::menu_entries(&app); + let job = entries.iter().find(|e| e.label == "1 Color Job…").unwrap().params.clone(); + app.run("ui.recolorDialog", job).unwrap(); + set(&mut app, "limitTo", json!("document")); + dialogs::confirm(&mut app).unwrap(); + dialog_frame(&mut app, &ctx); + let ink = app.session.doc().unwrap().doc.swatch("Ink").unwrap().paint.color().unwrap(); + let mut rows = field(&app, "rows").as_array().unwrap().clone(); + let row = rows.iter().position(|r| !r["exclude"].as_bool().unwrap_or(false)).unwrap(); + assert!(rows.iter().enumerate().all(|(i, r)| i == row || r["exclude"].as_bool().unwrap_or(false)), "one row: {rows:?}"); + rows[row]["to"] = json!(ColorKey::of(&ink).to_string()); + set(&mut app, "rows", Value::Array(rows)); + dialog_frame(&mut app, &ctx); + dialogs::confirm(&mut app).unwrap(); + assert_eq!(dialog_kind(&app), None); + + let after = art_paints(&app); + assert_eq!(after.len(), before.len(), "{kind}: the art has the same paints"); + let mut kept = vec![]; + opacities_in(&art_json(&app), &mut kept); + assert_eq!(kept, opacities, "{kind}: the opacities are kept"); + for &i in &grays { + let (c, link, tint) = &after[i]; + assert!(gray(c).is_none(), "{kind}: paint {i} is no longer gray: {c:?}"); + assert_eq!(link.is_some(), linked, "{kind}: paint {i} linked: {link:?}"); + if linked { + assert_eq!(link.as_deref(), Some("Ink")); + assert!(*tint > 0.0 && *tint <= 1.0, "{kind}: paint {i} at a tint: {tint}"); + } + } + for (i, c) in before.iter().enumerate().filter(|(i, _)| !grays.contains(i)) { + assert_eq!(after[i].0, c.0, "{kind}: black and white are kept"); + } + if linked { + for &a in &grays { + for &b in &grays { + if gray(&before[a].0) < gray(&before[b].0) { + assert!(after[a].2 >= after[b].2, "{kind}: a darker gray takes more ink: {:?} {:?}", after[a], after[b]); + } + } + } + app.run("swatch.edit", json!({"name": "Ink", "color": "cmyk 100 0 0 0"})).unwrap(); + let edited = art_paints(&app); + for &i in &grays { + assert_eq!(edited[i].1.as_deref(), Some("Ink"), "{kind}: paint {i} stays linked"); + assert!((edited[i].2 - after[i].2).abs() < 1e-6, "{kind}: paint {i} keeps its tint"); + assert_ne!(edited[i].0, after[i].0, "{kind}: paint {i} takes the edited ink"); + } + } + } + let _ = std::fs::remove_file(&path); +} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index dafab93a58..2f19b5fd37 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -287,9 +287,12 @@ canvas while open; `ui.dialog.confirm` keeps the result as one undo step (`edit. `edit.colors.saturate`) and `ui.dialog.cancel` rolls it back. Global mode answers with an error until tints of global and spot colours exist; the dialog then stays open. -Recolor Artwork: `ui.recolorDialog {colors?, library?, group?}` opens the `recolor` dialog on the selected art +Recolor Artwork: `ui.recolorDialog {colors?, library?, group?, preset?}` opens the `recolor` dialog on the selected art (`colors`: a count for an n-colour job, or colours to assign as the new colours; `library`: Limit to Library, a library -or `"document"`, `""` for the first library; `group`: a colour group, Edit or Apply Color Group). Fields: `rows` (`[{from: [keys], to: key, exclude?, tint?, model?}]` +or `"document"`, `""` for the first library; `group`: a colour group, Edit or Apply Color Group). With `preset: true` +(the Edit › Edit Colors › Recolor with Preset items) it first opens the `recolorPreset` dialog, which asks whether to +limit the colors to a swatch library: its field `limitTo` (a library id, `"document"`, or `""` for None) starts on +`library`, and its OK opens the `recolor` dialog with `colors` and that library. Fields: `rows` (`[{from: [keys], to: key, exclude?, tint?, model?}]` as `recolor.reduce` returns them), `colors` (null for Auto), `method`, `preserveWhite`, `preserveBlack`, `preserveGrays`, `limitTo`, `groupName`, `tab` (`assign` or `edit`), `rule` (harmony id), `linked`, `preview`, `sliderMode` (the mode of the color sliders under the rows: `hsb`, `rgb`, `cmyk`, `lab`, or `tint` for a row whose new diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3da663c191..bf1b6461a3 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -641,6 +641,7 @@ since 2026-10-01. - **Trim View hides guides and the grid (#8363):** while View › Trim View is on, the canvas and tiled panes draw no ruler guides, no guide paths and no grid, the guides are neither snapped to nor picked, and Show/Hide Guides and Show/Hide Grid are greyed out (menu bar, canvas context menu, Properties) and refuse to run; the stored choices come back when it is turned off, and the rulers stay ([trim view hides guides](https://community.adobe.com/t5/illustrator-discussions/trim-view-hides-guides/td-p/14066140), [guides greyed out](https://community.adobe.com/t5/illustrator-discussions/guides-greyed-out/m-p/11132728)). A drag or double-click on a ruler makes no guide while it is on (no preview, no undo step, a status message). `trim_view_hides_the_guides_and_the_grid`, `trim_view_deselects_selected_guide_paths`, `trim_view_makes_no_guide_from_the_rulers` in `crates/ui-egui/src/canvas/tests.rs`; `trim_view_greys_out_show_guides_and_show_grid` in `crates/ui-egui/src/menus/tests.rs`. - **Recolor picker follow-up (#8031/#4028):** native Lab numeric entry, document/loaded-library swatches in the Color Picker, and Assign-row Pick from Swatches / Limit to Library menus. #4090 provided the double-click picker and #5113 the Assign sliders. Regression tests `native_lab_entry_in_color_picker` and `row_context_menu_pick_from_swatches_and_limit_to_library` exercise the fields and menu callbacks rather than writing their result state. Area score and hours unchanged. +- **Recolor with Preset asks for a library first:** Edit › Edit Colors › Recolor with Preset (1, 2 and 3 Color Job, Color Library) opens a Recolor with Preset dialog whose Limit to Library menu (None, Document Swatches or a library) is applied when Recolor Artwork opens (, "Quickly reduce colors using a preset"). A 1 Color Job limited to the document's swatches with a spot or global ink picked turns gray art into tints of that ink linked to its swatch, so editing the swatch recolors the art. Tests `recolor_with_preset_asks_for_a_library_first` and `a_one_color_job_limited_to_document_swatches_links_gray_art_to_the_ink`. Area score and hours unchanged. - **Quick Pen tool (#2660, in part):** a tool in the Pen tool's group (Alt+P, Option+P on macOS) draws straight lines, continuous arcs and sharp-corner arcs, one undo step per piece; Alt pressed and let go on its own switches the action, C flips the last sharp-corner arc, `[` and `]` change the arc size by 15°, a click on the first point closes the path, a click on an open end continues it, and Escape or Enter ends it (`path.quickPen`), as [Draw with the Quick Pen tool](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/draw-with-quick-pen-tool.html) and [Quick Pen tool keyboard shortcuts](https://helpx.adobe.com/illustrator/web/add-and-edit-artwork/draw-and-edit-paths/quick-pen-tool-keyboard-shortcuts.html) describe. The 180° default arc, its 15° steps, the side an arc bulges to, a dragged piece ending where the press is let go, and C, `[` and `]` changing the arc being dragged are VectorCraft's own rules. Tests: tools `quickpen::tests`, engine `tests::quickpen`, ui-egui `shortcuts::alt_tap::tests`, `alt_p_chooses_the_quick_pen_and_an_alt_tap_switches_its_action` and `brackets_size_the_quick_pen_arc_being_dragged`. Score and hours unchanged. - **Quick Pen protractor:** while an arc is drawn, by a drag or as the piece the next click adds, the Quick Pen tool shows a protractor around the arc's center: a tick every 15° from the arc's start, a longer one every 90°, and one at its end; the next click's piece shows it only with Enable Rubber Band for the Pen tool on. With Smart Guides on, the end of a continuous arc snaps onto the nearest tick within the snapping tolerance of the pointer when no other Smart Guide snaps the point and neither Snap to Grid nor Snap to Pixel snaps drawn points; Shift does not change it. A continuous arc that starts a path sweeps the arc size and does not snap to a tick, Alt tapped during a press moves the piece's end onto or off the tick for the new action, and a hover hides its preview after a snap setting changes until the pointer moves. The protractor, its 15° step and the tick snapping are VectorCraft's own behavior. Tests: tools `the_arc_circle_is_the_circle_the_arc_is_drawn_on`, `a_continuous_arc_end_goes_to_the_nearest_tick`, `a_tick_past_the_coordinate_limit_is_not_used`, `a_continuous_arc_without_a_direction_has_no_tick`, `the_protractor_ticks_lie_across_the_arc`; engine `a_continuous_arc_end_snaps_to_the_protractor`, `a_click_puts_a_continuous_arc_end_on_a_tick`, `an_alt_tap_during_a_press_moves_the_end_for_the_new_action`, `a_click_on_a_tick_leaves_no_preview_back_to_the_pointer`, `a_hover_snaps_to_a_tick_only_for_a_continuous_arc`, `a_hover_shows_nothing_after_smart_guides_change`, `a_click_that_adds_nothing_keeps_a_stale_hover_hidden`, `a_hover_is_hovered_again_when_the_art_changes`, `an_arc_drag_shows_the_protractor`, `a_hovered_arc_shows_the_protractor_with_the_rubber_band`. New tests of existing Quick Pen behavior: `a_point_snaps_to_a_smart_guide`, `hovering_shows_the_distance_label`. Score and hours unchanged.