diff --git a/crates/engine/src/cmd.rs b/crates/engine/src/cmd.rs index 4afcb08ea4..93ad8ae4c5 100644 --- a/crates/engine/src/cmd.rs +++ b/crates/engine/src/cmd.rs @@ -966,7 +966,7 @@ pub(crate) use buildcmds::TracePresetChanges; /// Whether an object is an Image Trace object, the source image of one, or the seam fills group in /// one. -pub(crate) use buildcmds::{is_seam_fills, is_trace_group, is_trace_source}; +pub(crate) use buildcmds::{TRACE_NAME, is_seam_fills, is_trace_group, is_trace_source}; /// The shapes a group selected alone gives the Pathfinder panel. pub use pathops::shape_count; diff --git a/crates/engine/src/script/dom.rs b/crates/engine/src/script/dom.rs index c0beb1f30d..5d155b5c2d 100644 --- a/crates/engine/src/script/dom.rs +++ b/crates/engine/src/script/dom.rs @@ -130,6 +130,8 @@ pub const NO_ACTIVE_DOCUMENT: &str = "No active document"; pub const STALE_ITEM: &str = "Stale page item"; /// The error for a new name given to a `PluginItem`. const TRACING_NAME: &str = "The name of a tracing cannot be changed"; +/// The error for the tracing's name given to a group that holds an image first. +const NOT_A_TRACING: &str = "Only Image Trace can make a tracing"; /// The error for a document that was closed, or that came from an earlier run. pub const STALE_DOCUMENT: &str = "Stale document"; /// The error of `index` and `getByName` when nothing matches. @@ -2283,12 +2285,27 @@ fn item_set_name(h: &Host, a: &[Data]) -> Answer { if name.len() > MAX_TEXT_BYTES { return Err(HostError::Range("the name is too long".into())); } - // An Image Trace object is known by its name, so renaming one would end the tracing. + // An Image Trace object is known by its name, so renaming one would end the tracing, and giving + // an ordinary group that holds an image first the tracing's name would make it one. let item = this_item(h, a)?; - let tracing = - with_doc(h, item.doc, |_, st| st.doc.node(item.id).is_some_and(|n| crate::cmd::is_trace_group(n) && n.name.as_deref() != Some(&**name))); - if tracing { - return Err(HostError::Error(TRACING_NAME.into())); + let refused = with_doc(h, item.doc, |_, st| { + st.doc.node(item.id).and_then(|n| { + let tracing = crate::cmd::is_trace_group(n); + let would_trace = !tracing + && name == crate::cmd::TRACE_NAME + && matches!(n.kind, crate::doc::NodeKind::Group { clip: false, .. }) + && n.children().is_some_and(|c| c.first().is_some_and(|i| matches!(i.kind, crate::doc::NodeKind::Image(_)))); + if tracing && n.name.as_deref() != Some(&**name) { + Some(TRACING_NAME) + } else if would_trace { + Some(NOT_A_TRACING) + } else { + None + } + }) + }); + if let Some(msg) = refused { + return Err(HostError::Error(msg.into())); } set_props(h, a, |n| n.name.as_deref().unwrap_or("") == name, json!({"name": name})) } diff --git a/crates/engine/src/script/dom/tracing.rs b/crates/engine/src/script/dom/tracing.rs index d4e249796c..cdc82e21fb 100644 --- a/crates/engine/src/script/dom/tracing.rs +++ b/crates/engine/src/script/dom/tracing.rs @@ -174,8 +174,16 @@ fn replaced(h: &Host, uid: u64, old: NodeId, new: NodeId) { } pub(super) fn remember_source(h: &Host, uid: u64, group: &Node) { + let mut first = true; if let Some(source) = group.children().and_then(|c| c.first()) { - h.dom.tracing.sources.borrow_mut().entry((uid, group.id.0)).or_insert(source.id); + let mut sources = h.dom.tracing.sources.borrow_mut(); + first = !sources.contains_key(&(uid, group.id.0)); + sources.entry((uid, group.id.0)).or_insert(source.id); + } + // Only a tracing saved without the record of the objects its trace made needs the snapshot, + // taken the first time this run sees it. + if !first || group.trace_made().is_some() { + return; } h.dom.tracing.descendants.borrow_mut().entry((uid, group.id.0)).or_insert_with(|| { let mut ids = HashSet::new(); @@ -309,14 +317,22 @@ fn retrace(h: &Host, item: Item, mut params: Map) -> Result<(), H } read_group(h, item, |_, group| { remember_source(h, item.doc.uid, group); - let descendants = h.dom.tracing.descendants.borrow(); - let ids = descendants.get(&(item.doc.uid, item.id.0)).ok_or_else(stale)?; // The objects the trace made, as the tracing records them; a tracing saved without that // record is checked against the objects it held when this run first saw it. let made = group.trace_made(); + let descendants = h.dom.tracing.descendants.borrow(); + let ids = match made { + Some(_) => None, + None => Some(descendants.get(&(item.doc.uid, item.id.0)).ok_or_else(stale)?), + }; let mut added = false; group.walk(&mut |n| { - added |= n.id != group.id && made.as_ref().map_or(!ids.contains(&n.id), |m| !m.contains(n.id)); + added |= n.id != group.id + && match (&made, ids) { + (Some(m), _) => !m.contains(n.id), + (None, Some(ids)) => !ids.contains(&n.id), + (None, None) => false, + }; }); if added { return Err(HostError::Error(ADDED_ARTWORK.into())); diff --git a/crates/engine/src/tests/script_dom_tracing.rs b/crates/engine/src/tests/script_dom_tracing.rs index a87cb7dd6d..73e75d4637 100644 --- a/crates/engine/src/tests/script_dom_tracing.rs +++ b/crates/engine/src/tests/script_dom_tracing.rs @@ -1108,6 +1108,21 @@ fn trace_plugin_keeps_its_name() { let _ = std::fs::remove_dir_all(base); } +#[test] +fn a_group_holding_an_image_cannot_take_the_tracing_name() { + let base = folder("rename-to-trace"); + let (mut s, _) = session(&base, false); + let out = log( + &mut s, + &base, + "var d = app.activeDocument, m = ''; d.selection = [d.rasterItems[0]]; vc.run('object.group'); var g = d.pageItems[0];\ + try { g.name = 'Image Trace'; } catch (e) { m = e.message; } vc.log(m); vc.log(g.typename); g.name = 'Logo'; vc.log(g.name);", + ); + assert_eq!(out, [json!("Only Image Trace can make a tracing"), json!("GroupItem"), json!("Logo")]); + assert!(traces(&s).is_empty()); + let _ = std::fs::remove_dir_all(base); +} + #[test] fn retrace_keeps_the_tracing_opacity_and_blend_mode() { let base = folder("retrace-appearance"); diff --git a/docs/mcp.md b/docs/mcp.md index db7a87b126..d60ee1064a 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3266,7 +3266,8 @@ through `$`: `imageTrace.presets.save`. A tracing that was expanded, released, deleted, traced again by a command, or whose source image was deleted throws `Stale page item`. A script gets the source image from `sourceArt`, and `pageItems`, `placedItems` and `rasterItems` do not list it. Assigning a different `name` to a `PluginItem` throws - `The name of a tracing cannot be changed`. `areaCount`, `cornerAngle`, `livePaintOutput`, + `The name of a tracing cannot be changed`, and assigning `Image Trace` as the `name` of a group whose first object + is an image throws `Only Image Trace can make a tracing`. `areaCount`, `cornerAngle`, `livePaintOutput`, `maxStrokeWeight`, `minStrokeLength`, `outputToSwatches`, `pathFitting`, `preprocessBlur`, `resample` and `resampleResolution` throw an error that says they are not implemented. With a script running, `imageTrace.make` stops at the run's stop request and changes nothing. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index ddc27573bd..66ea39e54c 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1111,7 +1111,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - The control server writes each reply through a 64 KiB buffer. On Windows 11 it sends the 17 MB `document.inspect` reply of a document with 50,000 objects on one layer to a client over loopback in 0.09 s instead of 34 s. - Scripts: File › Scripts › Other Script… and `script.run` run a JavaScript file against the open documents as one transaction with one undo step for each changed document. A failed or stopped run puts every document back. `crates/engine/src/tests/script_run.rs`. - Scripts: `Document.placedItems` and `Document.rasterItems` list a document's linked and embedded images; `placedItems.add()` with a `File` assigned to `file` places an image linked, and `PlacedItem.relink(file)` and `embed()` relink and embed it, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItem/, https://ai-scripting.docsforadobe.dev/jsobjref/RasterItems/ and https://ai-scripting.docsforadobe.dev/jsobjref/RasterItem/ describe them. A raster item's bits per channel, channels, color space and transparency come from its encoded pixels' header. Only files the script may read, of at most 256 MiB and holding an image, are placed or relinked. Rasterizing and capturing are not there yet. `crates/engine/src/tests/script_dom_images.rs`. - - Scripts: `PlacedItem.trace()` and `RasterItem.trace()` make an Image Trace object and return it as a `PluginItem` whose `tracing` gives its path, anchor and color counts, the source image's resolution, `expandTracing()`, `releaseTracing()` and its `TracingOptions`; assigning an option or loading a preset traces it again, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TracingObject/ and https://ai-scripting.docsforadobe.dev/jsobjref/TracingOptions/ describe them. Option values are checked for type and range before any trace, a script cannot save a preset, and the options without a VectorCraft setting throw. `crates/engine/src/tests/script_dom_tracing.rs`. + - Scripts: `PlacedItem.trace()` and `RasterItem.trace()` make an Image Trace object and return it as a `PluginItem` whose `tracing` gives its path, anchor and color counts, the source image's resolution, `expandTracing()`, `releaseTracing()` and its `TracingOptions`; assigning an option or loading a preset traces it again, except that the view options (`viewRaster` and `viewVector`) only change the view, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/PluginItem/, https://ai-scripting.docsforadobe.dev/jsobjref/TracingObject/ and https://ai-scripting.docsforadobe.dev/jsobjref/TracingOptions/ describe them. Option values are checked for type and range before any trace, a script cannot save a preset, and the options without a VectorCraft setting throw. `crates/engine/src/tests/script_dom_tracing.rs`. - Scripts: `Document.pathItems` lists the paths and makes rectangles, rounded rectangles, ellipses, polygons, stars and empty paths with the defaults the help page https://ai-scripting.docsforadobe.dev/jsobjref/PathItems/ gives; each path's points, closed state, fill rule, area, length, guide state, selected points, fill and stroke colors, stroke options and transforms read and change as https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/, https://ai-scripting.docsforadobe.dev/jsobjref/PathPoints/ and https://ai-scripting.docsforadobe.dev/jsobjref/PathPoint/ describe them, and `RGBColor`, `CMYKColor`, `GrayColor`, `LabColor` and `NoColor` make colors (`docs/mcp.md`). The transforms move gradients with the art: `changeFillGradients` false throws an error, as do `changeFillPatterns` and `changeStrokePattern` given as different values, and `transform` is not there yet (`docs/mcp.md` lists these limits). Gradient stops are not there yet. A `PathPoint` of a path in an Objects on Path group goes stale when an edit of another path in the group moves it. `crates/engine/src/tests/script_dom_paths.rs`. - Scripts: a document's `default*` members (https://ai-scripting.docsforadobe.dev/jsobjref/Document/) read and set the fill, stroke and stroke options of the next object drawn through `appearance.setNewArt`, leaving the selection and its art as they were, and `scaleFactor` reads 1 (`docs/mcp.md`). `crates/engine/src/tests/script_dom_defaults.rs`. - Scripts: `app.undo()` and `app.redo()` undo and redo the edits the run made, and each document open before and after the run that it changed gets one undo step. `crates/engine/src/tests/script_dom.rs`.