diff --git a/crates/engine/src/script/dom/colors.rs b/crates/engine/src/script/dom/colors.rs index f2ed0c0b24..371b72ed62 100644 --- a/crates/engine/src/script/dom/colors.rs +++ b/crates/engine/src/script/dom/colors.rs @@ -26,7 +26,8 @@ use vectorcraft_js::{Data, HostClass, HostError, HostFunction}; use super::{Link, current, num, text}; -/// The classes whose objects can be read from a fill or stroke but not assigned yet. +/// The classes whose objects [`assigned`] refuses as not available yet. A path's `fillColor` and +/// `strokeColor` take a `SpotColor` before [`assigned`] runs; a swatch's or spot's `color` does not. const LATER: &[&str] = &["GradientColor", "SpotColor", "PatternColor"]; /// The components of each color class, with the value `new` gives them. diff --git a/crates/engine/src/script/dom/paths.rs b/crates/engine/src/script/dom/paths.rs index 32793a0828..59aebf5f67 100644 --- a/crates/engine/src/script/dom/paths.rs +++ b/crates/engine/src/script/dom/paths.rs @@ -752,7 +752,7 @@ fn path_stroke_color(h: &super::Host, a: &[Data]) -> Answer { /// process swatch reads, throws: it does not name the swatch it was read from. fn set_spot_color(h: &super::Host, a: &[Data], fill: bool, spot: &Data, tint: f64) -> Answer { if matches!(spot, Data::Undefined) { - return Err(HostError::Error("assigning a SpotColor without a spot is not available yet".into())); + return Err(HostError::Error("SpotColor.spot must be a Spot; a color read from a global process swatch cannot be assigned yet".into())); } let (item, look) = this_look(h, a)?; let now = if fill { &look.fill } else { &look.stroke }; diff --git a/crates/engine/src/script/dom/resources.rs b/crates/engine/src/script/dom/resources.rs index dc3985f5c6..c2b5460618 100644 --- a/crates/engine/src/script/dom/resources.rs +++ b/crates/engine/src/script/dom/resources.rs @@ -727,9 +727,10 @@ fn set_swatch_color(h: &Host, kind: Kind, a: &[Data]) -> Answer { return Err(HostError::Error("a spot's color must be an RGBColor, a CMYKColor or a LabColor".into())); } // A spot keeps the color space it is given; a process swatch stores an RGB color in a CMYK - // document as CMYK, as `swatch.edit` does without `keepModel`. + // document as CMYK, as `swatch.edit` does without `keepModel`, unless the color is the + // swatch's own, which `swatch.edit` keeps as it is. let stored = if w.spot { color } else { stored_in(h, r.doc, color) }; - if now == stored { + if now == color || now == stored { return Ok(Data::Undefined); } let mut params = json!({"name": r.name, "color": colors::param(&color)}); diff --git a/crates/engine/src/tests/script_dom_paths.rs b/crates/engine/src/tests/script_dom_paths.rs index db2a6223e1..7604d69601 100644 --- a/crates/engine/src/tests/script_dom_paths.rs +++ b/crates/engine/src/tests/script_dom_paths.rs @@ -404,7 +404,7 @@ fn a_global_process_link_read_as_a_spot_color_is_not_assigned() { "var q = app.activeDocument.pathItems; q[3].fillColor = q[0].fillColor;", ] { let e = failure(&mut s, script); - assert!(e.contains("without a spot is not available yet"), "{script}: {e}"); + assert!(e.contains("global process swatch cannot be assigned yet"), "{script}: {e}"); assert_eq!(paints(&s), before, "{script}"); assert_eq!(undo_steps(&s), steps, "{script}"); } @@ -431,7 +431,7 @@ fn a_spot_color_without_a_spot_of_the_document_is_refused() { let before = layers(&s); let steps = undo_steps(&s); for (source, part) in [ - ("app.documents[0].pathItems[0].fillColor = new SpotColor();", "without a spot is not available yet"), + ("app.documents[0].pathItems[0].fillColor = new SpotColor();", "SpotColor.spot must be a Spot; a color read"), ("var c = new SpotColor(); c.spot = 5; app.documents[0].pathItems[0].fillColor = c;", "SpotColor.spot must be a Spot"), ("var a = app.documents[0], c = new SpotColor(); c.spot = a.swatches.getByName('Ink'); a.pathItems[0].fillColor = c;", "must be a Spot"), ( @@ -828,7 +828,7 @@ fn bad_color_components_throw_and_change_nothing() { ("app.activeDocument.pathItems[0].fillColor = {typename: 'Foo'};", "color object"), ("app.activeDocument.pathItems[0].fillColor = 5;", "color object"), ("app.activeDocument.pathItems[0].fillColor = new GradientColor();", "not available yet"), - ("app.activeDocument.pathItems[0].strokeColor = new SpotColor();", "without a spot is not available yet"), + ("app.activeDocument.pathItems[0].strokeColor = new SpotColor();", "SpotColor.spot must be a Spot; a color read"), ] { let e = failure(&mut s, source); assert!(e.contains(part), "{source}: {e}"); diff --git a/crates/engine/src/tests/script_dom_resources.rs b/crates/engine/src/tests/script_dom_resources.rs index 89cb6f7d1e..c77dc3de39 100644 --- a/crates/engine/src/tests/script_dom_resources.rs +++ b/crates/engine/src/tests/script_dom_resources.rs @@ -255,6 +255,21 @@ fn a_spot_keeps_an_rgb_color_in_a_cmyk_document() { assert_eq!(undo_steps(&s), steps, "assigning Leaf the RGB color it was given records no step"); } +#[test] +fn a_process_swatch_that_kept_an_rgb_color_takes_it_back_without_a_step() { + let mut s = Session::new(); + s.execute("file.new", &json!({"width": 400, "height": 300, "colorMode": "cmyk"})).unwrap(); + s.execute("swatch.new", &json!({"name": "Sky", "color": "#3080c0", "keepModel": true})).unwrap(); + let paint = |s: &Session| s.active().unwrap().doc.swatch("Sky").map(|w| w.paint.clone()); + let rgb = matches!(paint(&s), Some(vectorcraft_color::Paint::Solid { color: vectorcraft_color::Color::Rgb { .. }, .. })); + assert!(rgb, "the process swatch holds an RGB color in the CMYK document"); + let before = paint(&s); + let steps = undo_steps(&s); + log(&mut s, "var w = app.activeDocument.swatches.getByName('Sky'); w.color = w.color;"); + assert_eq!(paint(&s), before, "the swatch keeps its RGB color"); + assert_eq!(undo_steps(&s), steps, "assigning the swatch its own color records no step"); +} + #[test] fn spots_list_registration_and_keep_it() { let (mut s, _) = doc(); diff --git a/docs/mcp.md b/docs/mcp.md index 3d62e22312..c9d06f8b7e 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2731,8 +2731,8 @@ app through the global object `vc`, and writes to the Script Console and runs ot Registration). Assigning a `SpotColor` (https://ai-scripting.docsforadobe.dev/jsobjref/SpotColor/) links the fill or stroke to its `spot`, a `Spot` of the path's document, at its `tint` (0 to 100; VectorCraft's own defaults are 100 for `new SpotColor()` and 0 for a color object without a `tint`), with `paint.setFill` or `paint.setStroke`. A `SpotColor` read from a color linked to a global process - swatch has no `spot` and does not name the swatch, so assigning it throws an error that says it is not available yet, - and the path keeps its paint. Assigning a `GradientColor` or `PatternColor` throws an error that says it is not available yet. `filled = true` on a path without a fill gives it the fill new + swatch has no `spot` and does not name the swatch, so assigning it, or a `SpotColor` whose `spot` was never set, + throws an error that says `SpotColor.spot` must be a Spot, and the path keeps its paint. Assigning a `GradientColor` or `PatternColor` throws an error that says it is not available yet. `filled = true` on a path without a fill gives it the fill new art gets (a color, gradient or pattern), or black when new art has none, and `stroked = true` does the same with the stroke; a new-art gradient goes on the bounds of the path, or of the compound path or compound shape whose paint it shows, and a new-art pattern with a placement of its own, or one missing from the document, throws an error. @@ -2793,7 +2793,7 @@ app through the global object `vc`, and writes to the Script Console and runs ot removed, or renamed or deleted with `vc.run`, every member throws `Stale Swatch` (`Stale Spot`, `Stale SwatchGroup`, `Stale Symbol`, `Stale GraphicStyle`, `Stale Brush`). A run holds at most 100,000 of these objects. An object of another document throws `Cross-document placement is not available`. `Document.gradients`, `Document.patterns` and - assigning a `SpotColor` to art are not available yet. + assigning a `SpotColor` to a swatch's or spot's `color` are not available yet. - `$.write(...values)` writes the values to the Script Console with no separator, each as `String(value)` gives it, and `$.writeln(...values)` does the same and ends the line. Each call counts as a host call. - `$.evalFile(path, timeout?)` runs the file `path` names, relative to the file being run, in the same global