mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 13:32:45 -05:00
Scripts: a swatch given its own color back records no step, and a SpotColor without a spot names the rule
- A process swatch that holds an RGB color in a CMYK document (made with keepModel, as a color theme's swatches are) records no undo step when a script assigns it that color again. swatch.edit keeps a swatch's own color as it is, so the assignment changed nothing. - Assigning a SpotColor whose spot is unset, or one read from a global process swatch, throws "SpotColor.spot must be a Spot; a color read from a global process swatch cannot be assigned yet". The SpotColor page (https://ai-scripting.docsforadobe.dev/jsobjref/SpotColor/) requires spot. The path keeps its paint. - docs/mcp.md now says that a SpotColor cannot be assigned to a swatch's or spot's color yet; a path's fillColor and strokeColor take one.
This commit is contained in:
1 parent
3aaea54d86
commit
6c7fd4490a
6 files changed
+27
-10
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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)});
|
||||
|
||||
@@ -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}");
|
||||
|
||||
@@ -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();
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
Reference in new issue
Block a user