From 62ce314f752fddd5de5994e09bfafddb36fa2928 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 18:03:22 -0800 Subject: [PATCH 1/7] New Document: test that the column count the rows show leaves a preset unchanged --- crates/ui-egui/src/dialogs/new_document.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index 1bcfb52473..1f42df5ae1 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -885,7 +885,7 @@ mod tests { let rows = DocSettings { artboards: 9, layout: ArtboardLayout::GridByColumn, columns: 2, rows: 4, ..DocSettings::default() }; let mut s = rows.clone(); set_columns(&mut s, 3); - assert_eq!((s.columns, s.rows), (3, 4), "3 is what the rows show"); + assert_eq!(s, rows, "3 is what the rows show"); set_columns(&mut s, 2); assert_eq!((s.layout, s.columns, s.rows), (ArtboardLayout::GridByColumn, 2, 0)); assert_eq!(s.grid_columns(), 2); From b54c9f063f9103f14e211d60def24bb1fe1b7e26 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 27 Nov 2026 23:10:27 -0800 Subject: [PATCH 2/7] Scripts: placedItems and rasterItems list the topmost image first, as pageItems does pageItems on main lists the topmost object first, and the image lists are built from it, so their order now follows it. The raster metadata test places its images in the order that keeps its assertions, and the plugins test that main added gives ScriptGate the held field this branch adds. --- crates/engine/src/script/dom/images.rs | 3 ++- crates/engine/src/tests/plugins.rs | 1 + crates/engine/src/tests/script_dom_images.rs | 3 ++- docs/mcp.md | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/script/dom/images.rs b/crates/engine/src/script/dom/images.rs index 0e7be90dfe..4528151057 100644 --- a/crates/engine/src/script/dom/images.rs +++ b/crates/engine/src/script/dom/images.rs @@ -135,7 +135,8 @@ pub(super) fn pending_as_item(h: &Host, d: &Data) -> Result, Ho Ok(Some([run, uid, high, low])) } -/// The ids of a document's linked (`placed`) or embedded images in paint order. +/// The ids of a document's linked (`placed`) or embedded images, topmost first, in the order of +/// `pageItems`. fn images(h: &Host, st: &DocState, placed: bool) -> Result>, HostError> { let pick = |l: &Lists| if placed { l.2.clone() } else { l.3.clone() }; if let Some(l) = &*h.dom.images.lists.borrow() diff --git a/crates/engine/src/tests/plugins.rs b/crates/engine/src/tests/plugins.rs index 1ae16ec6a8..c6da92ac55 100644 --- a/crates/engine/src/tests/plugins.rs +++ b/crates/engine/src/tests/plugins.rs @@ -2202,6 +2202,7 @@ fn a_script_loads_no_plugin_from_outside_its_folder_through_a_name_that_is_not_t read: ScriptScope::of_folder(&inside), write: ScriptScope::default(), documents: vec![], + held: vec![], linked: Default::default(), also: None, }; diff --git a/crates/engine/src/tests/script_dom_images.rs b/crates/engine/src/tests/script_dom_images.rs index 594582e9f9..f1f58a3c96 100644 --- a/crates/engine/src/tests/script_dom_images.rs +++ b/crates/engine/src/tests/script_dom_images.rs @@ -319,8 +319,9 @@ fn raster_metadata_uses_encoded_header_not_rgb_fallback() { std::fs::write(&g, gray_png(6, 4)).unwrap(); std::fs::write(&c, super::links::png(3, 2, [10, 20, 30])).unwrap(); let mut s = session(); - place(&mut s, &g, false); + // `rasterItems` lists the topmost image first, so the gray image placed last is `r[0]`. place(&mut s, &c, false); + place(&mut s, &g, false); let out = log( &mut s, &base, diff --git a/docs/mcp.md b/docs/mcp.md index 85c29806de..fbba0226f2 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2933,7 +2933,8 @@ other files through `$`: keeps the preset's value. A bad value throws an error before anything is written. - `Document.placedItems` (https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItems/) lists the document's linked images and `Document.rasterItems` (https://ai-scripting.docsforadobe.dev/jsobjref/RasterItems/) its embedded ones, - in paint order, each with `length`, `[i]`, `index(key)`, `getByName(name)` and `removeAll()`. `placedItems.add()` + topmost first as `pageItems` lists them, each with `length`, `[i]`, `index(key)`, `getByName(name)` and + `removeAll()`. `placedItems.add()` gives a `PlacedItem` with no file; assigning a `File` to its `file` runs `file.place` with `link: true`, and every other member of it throws `PlacedItem.file is required` until then. A `PlacedItem` (https://ai-scripting.docsforadobe.dev/jsobjref/PlacedItem/) has `file`, `relink(file)` (`links.relink`), `embed()` From 51778505363acbe79a38e0f4fd5497e17acbe329 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 00:17:08 -0800 Subject: [PATCH 3/7] Scripts: placed and raster items take contentVariable Every page item kind that holds content now binds a variable through contentVariable on main, and the placed and raster item classes this branch adds defined it as not available yet. They now take the same member, so a linked image binds an image variable and an embedded one refuses it, as script_variables' an_embedded_image_cannot_take_an_image_variable checks. --- crates/engine/src/script/dom/images.rs | 6 ++++-- docs/mcp.md | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/script/dom/images.rs b/crates/engine/src/script/dom/images.rs index 4528151057..06e1774536 100644 --- a/crates/engine/src/script/dom/images.rs +++ b/crates/engine/src/script/dom/images.rs @@ -660,7 +660,8 @@ pub(super) fn classes(l: &Link) -> Vec { ("matrix", property(l, placed_matrix, placed_set_matrix)), ("boundingBox", get(l, placed_box)), ]); - placed.extend(["contentVariable", "trace"].into_iter().map(|m| later(l, "PlacedItem", m))); + placed.extend(super::variables::item_members(l, "PlacedItem")); + placed.push(later(l, "PlacedItem", "trace")); let mut raster = named(vec![ ("bitsPerChannel", get(l, raster_bits)), ("channels", get(l, raster_channels)), @@ -673,7 +674,8 @@ pub(super) fn classes(l: &Link) -> Vec { ("transparent", get(l, raster_transparent)), ("boundingBox", get(l, raster_box)), ]); - raster.extend(["colorants", "colorize", "contentVariable", "overprint", "trace"].into_iter().map(|m| later(l, "RasterItem", m))); + raster.extend(super::variables::item_members(l, "RasterItem")); + raster.extend(["colorants", "colorize", "overprint", "trace"].into_iter().map(|m| later(l, "RasterItem", m))); vec![ class("PlacedItems", None, placed_list, Some(super::function(l, placed_at))), class("RasterItems", None, raster_list, Some(super::function(l, raster_at))), diff --git a/docs/mcp.md b/docs/mcp.md index 2b40fb55e5..b43a7c7841 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2960,8 +2960,7 @@ other files through `$`: item before the value, so a stale item throws `Stale page item` whatever the value. Assigning `matrix` to an `add()` result without a file throws `PlacedItem.file is required` whatever the value, and assigning `file` to one checks the file and places the image. A run keeps at most 1,024 `placedItems.add()` results, and one that was not given a - file is dropped at the end of the run. `contentVariable`, `trace`, `colorants`, `colorize` and `overprint` are not - available yet. + file is dropped at the end of the run. `trace`, `colorants`, `colorize` and `overprint` are not available yet. - A `Document` also has `variables`, `dataSets`, `activeDataset`, `variablesLocked`, `importVariables(file)` and `exportVariables(file)` (https://ai-scripting.docsforadobe.dev/jsobjref/Document/). `variables` (https://ai-scripting.docsforadobe.dev/jsobjref/Variables/) and `dataSets` From 1e2b68b71cc3a27e7381f1efddac32f8e1fb261a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 29 Nov 2026 09:46:29 -0800 Subject: [PATCH 4/7] Docs: name the Document members scripts do not expose yet --- docs/target-app-parity.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 725e8f957e..4845543b29 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1130,7 +1130,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Scripts: a text frame's `nextFrame` and `previousFrame` read and set its links to the frames before and after it, `areaText` and `pathText` thread a new frame to a base frame, and `document.stories` lists the stories, each with its frames in thread order and its text across them as one text range with its characters, words and paragraphs, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/TextFrameItem/, https://ai-scripting.docsforadobe.dev/jsobjref/Story/ and https://ai-scripting.docsforadobe.dev/jsobjref/Stories/ describe them; `text.thread.setNeighbor` links or unlinks two frames by id (`docs/mcp.md`). Which links are refused, and how a story is listed and found, are VectorCraft's own rules. `crates/engine/src/tests/script_threads.rs`. - Scripts: `PageItem.tags` reads, adds, renames and deletes an object's tags, name and value pairs that the native file keeps, and `Document.tags` reads, renames and deletes the tags of every page item but adds none (its `add` throws; a script adds a tag through the page item's `tags`), as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Tags/ and https://ai-scripting.docsforadobe.dev/jsobjref/Tag/ describe them, through `object.tags` and the `object.tag.*` commands, at most 64 tags an object (`docs/mcp.md`). `crates/engine/src/tests/script_tags.rs`. - Scripts: the global `app` gives the open documents, new documents from a startup preset and a `DocumentPreset`, the active document, each document's selection and its page items with their names, notes, visibility, lock, opacity, position, size, bounds and stacking order, and moves and copies them into or beside other objects, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Application/, https://ai-scripting.docsforadobe.dev/jsobjref/Documents/, https://ai-scripting.docsforadobe.dev/jsobjref/DocumentPreset/, https://ai-scripting.docsforadobe.dev/jsobjref/Document/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItem/ and https://ai-scripting.docsforadobe.dev/jsobjref/GroupItem/ describe them; each change runs a command inside the run's transaction (`docs/mcp.md`). A script can check a member with `hasOwnProperty`, and can read a collection by name and name `activeDocument`, `documents` and `selection` without `app.` (https://ai-scripting.docsforadobe.dev/scriptingJavascript/objectReferences/). A key such as `1` is an array index and reads that position; in `pageItems` and `documents`, a number that is not an array index, such as `-1` or `1.5`, is looked up by name when the key is the text JavaScript writes for that number. VectorCraft's own rule. `app.executeMenuCommand` runs the menu items Select All, Deselect, Group, Ungroup, Make and Release Clipping Mask, Make and Release Compound Path, and Fit to Artwork Bounds by their menu command names (https://community.adobe.com/questions-652/a-list-of-illustrator-menu-commands-we-can-call-from-javascript-769510, https://gist.github.com/shalakolee/df3246659d4289eb99149b9ed00a00ee). The `parent` of a page item at the top of a layer is a `Layer` with `name`, `typename` and `toString`. A page item's `blendingMode` reads and sets its blend mode with the `BlendModes` values (https://ai-scripting.docsforadobe.dev/jsobjref/scripting-constants/). - `Document.views` lists the document's drawn windows with their bounds, center, zoom and screen mode (https://ai-scripting.docsforadobe.dev/jsobjref/View/). Zoom follows each window's displayed percentage, including display density with Display Print Size at 100% Zoom enabled; bounds retain the physical camera scale. View objects keep their targets when windows are renumbered. View changes run no command, add no undo step, and remain when a script fails. A center outside the canvas after coordinate conversion throws a `RangeError`. `Document.layers`, `Document.activeLayer`, type and the other classes are not there yet. `crates/engine/src/tests/script_dom.rs`. + `Document.views` lists the document's drawn windows with their bounds, center, zoom and screen mode (https://ai-scripting.docsforadobe.dev/jsobjref/View/). Zoom follows each window's displayed percentage, including display density with Display Print Size at 100% Zoom enabled; bounds retain the physical camera scale. View objects keep their targets when windows are renumbered. View changes run no command, add no undo step, and remain when a script fails. A center outside the canvas after coordinate conversion throws a `RangeError`. `Document.layers`, `Document.activeLayer`, `Document.artboards`, `Document.groupItems`, `Document.swatches`, `Document.symbols` and `Document.close` are not there yet. `crates/engine/src/tests/script_dom.rs`. - Scripts: `app.redraw()` (https://ai-scripting.docsforadobe.dev/jsobjref/Application/) returns without changing the documents or adding an undo step; the app goes on drawing the documents as they were before the run until the run ends. VectorCraft's own rule. `crates/engine/src/tests/script_dom.rs`. - Scripts: a document's variables and data sets, the variables its page items are bound to, Lock Variables, and importing and exporting a variable library through a `File`, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Variables/, https://ai-scripting.docsforadobe.dev/jsobjref/Variable/, https://ai-scripting.docsforadobe.dev/jsobjref/Datasets/ and https://ai-scripting.docsforadobe.dev/jsobjref/Dataset/ describe them; `variable.setBinding` binds one object for one slot, and `dataset.update {name}` updates a data set that is not the active one (`docs/mcp.md`). `crates/engine/src/tests/script_variables.rs`. - Scripts: `app.doScript(action, set, dialogs?)` plays an action of the Actions panel inside the run, as the `DoScript` method of the scripting reference https://web.archive.org/web/20170621180804/https://wwwimages.adobe.com/content/dam/Adobe/en/devnet/illustrator/sdk/CC2015_3/Illustrator%20VBScript%20Reference.pdf describes it: its steps join the run's one undo step and keep the script's file limits, and a stop or a step a script may not run, or that plays an action or runs a script, is refused before any step runs (`docs/mcp.md`). `app.loadAction` and `app.unloadAction` are not there yet. `crates/engine/src/tests/script_actions.rs`. From ec4a813fa3c7426ebbcbbebadc0f03b2abb6410e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 02:32:07 -0800 Subject: [PATCH 5/7] Scripts: stale placed items are refused as relative objects; exact image matrix checks - move() and duplicate() resolve a page-item relative object, an add() result included, through item_of, so a PlacedItem object made stale by embed() throws "Stale page item" instead of acting as a target. - Assigning matrix compares each requested coefficient exactly with the value the getter reports. A coefficient left as reported keeps the image's own value, so a change of 5e-10 still moves the image and an untouched axis does not shift. A move alone is applied as an offset. A matrix that a nearly singular image cannot reach within 1e-6 pt at its corners, or that would leave it with no area, throws an error with nothing changed, and a change that rounds away runs no command. - The RasterItem.embedded test calls the getter itself on 1 and on a live raster item. - docs/mcp.md states when assigning matrix runs no command and when it is refused. --- crates/engine/src/script/dom.rs | 10 +++- crates/engine/src/script/dom/images.rs | 47 ++++++++++++++-- crates/engine/src/tests/script_dom_images.rs | 56 +++++++++++++++++++- docs/mcp.md | 5 +- 4 files changed, 109 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/script/dom.rs b/crates/engine/src/script/dom.rs index 1946bab86a..fd0c9746ec 100644 --- a/crates/engine/src/script/dom.rs +++ b/crates/engine/src/script/dom.rs @@ -2635,6 +2635,7 @@ fn destination(h: &Host, item: Item, target: &Data, how: &Data) -> std::result:: let how = placement_of(how)?; let beside = matches!(how, Placement::Above | Placement::Below); let pending = images::pending_as_item(h, target)?.map(|p| p.to_vec()); + let is_pending = pending.is_some(); let handle = pending.or_else(|| handle_of(target, "PageItem")).or_else(|| handle_of(target, "Layer")); let Some(handle) = handle.filter(|parts| parts.len() == 5) else { if handle_of(target, "Document").is_some() { @@ -2642,7 +2643,14 @@ fn destination(h: &Host, item: Item, target: &Data, how: &Data) -> std::result:: } return Err(HostError::Type("the relative object must be a page item or a layer".into())); }; - let (doc, target) = node_of(h, &handle).ok_or_else(|| HostError::Error(STALE_ITEM.into()))?; + let (doc, target) = if is_pending || handle_of(target, "PageItem").is_some() { + // A page item, an `add()` result included, must still be of its class: an embedded + // `PlacedItem`'s old object is stale. + let it = item_of(h, target)?; + (it.doc, it.id) + } else { + node_of(h, &handle).ok_or_else(|| HostError::Error(STALE_ITEM.into()))? + }; if doc.uid != item.doc.uid { return Err(HostError::Error(CROSS_DOCUMENT.into())); } diff --git a/crates/engine/src/script/dom/images.rs b/crates/engine/src/script/dom/images.rs index 2373f47302..8ac02076c8 100644 --- a/crates/engine/src/script/dom/images.rs +++ b/crates/engine/src/script/dom/images.rs @@ -27,8 +27,10 @@ //! transparent palette entry. `RasterItem.file` is `null`, `embedded` is true and takes only //! `true`, and `status` is `RasterLinkState.NODATA`, since a raster item has no linked file. //! - `matrix` maps the image's pixels (row 0 at the top) to script coordinates, as a record of -//! `mValueA` to `mValueTY`; a distorted image has none. Assigning it runs `object.transform`; a -//! matrix with no area or one that puts a corner of the image outside the canvas is refused. +//! `mValueA` to `mValueTY`; a distorted image has none. Assigning it runs `object.transform`, +//! and assigning the matrix it reads runs nothing; a matrix with no area, one that puts a +//! corner of the image outside the canvas, or one a nearly singular image cannot reach exactly +//! is refused. //! `boundingBox` is the pixel rectangle at one point a pixel, in the run's coordinate system. use std::cell::RefCell; @@ -525,13 +527,50 @@ fn set_matrix(h: &Host, a: &[Data], cls: &str) -> Answer { return Err(HostError::Range("the matrix puts the image outside the canvas".into())); } let old = im.xf; - if old.as_coeffs().iter().zip(target.as_coeffs()).all(|(o, t)| (o - t).abs() <= 1e-9) { + // Unchanged means the numbers the `matrix` getter reports, compared exactly, so a small + // change such as `mValueTX` from 0 to 5e-10 still moves the image. A change that the + // conversion to document space rounds away leaves the image's matrix as it is and runs nothing. + // A coefficient the script left as the getter reports keeps the image's own value, so the + // conversion back does not shift an untouched axis. + let olds = old.as_coeffs(); + let [a0, b0, c0, d0, e0, f0] = olds; + let reported = match h.dom.coords.get() { + Coords::Document => [a0, -b0, c0, -d0, e0 - f.left0, f.bottom0 - f0], + Coords::Artboard => [a0, b0, c0, d0, e0 - f.left, f0 - f.top], + }; + let mut wanted = target.as_coeffs(); + for ((w, o), (r, v)) in wanted.iter_mut().zip(olds).zip(reported.iter().zip(m.iter())) { + if r == v { + *w = o; + } + } + if wanted == olds { return Ok(None); } if !area_of(old) { return Err(HostError::Error("the image has no area to transform".into())); } - Ok(Some((target * old.inverse()).as_coeffs())) + let target = Affine::new(wanted); + let [ta, tb, tc, td, te, tf] = wanted; + if [ta, tb, tc, td] == [a0, b0, c0, d0] { + // A move alone: the offset difference, without the error an inverse adds. + return Ok(Some([1.0, 0.0, 0.0, 1.0, te - e0, tf - f0])); + } + // A nearly singular image loses precision through the inverse; refuse a change that would + // not land where the script asked rather than move the image somewhere else. + let delta = target * old.inverse(); + let landed = delta * old; + if landed.as_coeffs() == olds { + return Ok(None); + } + let close = [(0.0, 0.0), (w, 0.0), (0.0, ht), (w, ht)].iter().all(|&(x, y)| { + let (p, q) = (landed * Point::new(x, y), target * Point::new(x, y)); + (p.x - q.x).abs() <= 1e-6 && (p.y - q.y).abs() <= 1e-6 + }); + if !close || !area_of(landed) { + return Err(HostError::Range("the matrix cannot be applied exactly to this image".into())); + } + Ok(Some(delta.as_coeffs())) })?; if let Some(d) = delta { edit_item(h, item, "object.transform", &json!({"ids": [item.id.0], "matrix": d, "strokes": false}))?; diff --git a/crates/engine/src/tests/script_dom_images.rs b/crates/engine/src/tests/script_dom_images.rs index f1f58a3c96..7affe83582 100644 --- a/crates/engine/src/tests/script_dom_images.rs +++ b/crates/engine/src/tests/script_dom_images.rs @@ -368,6 +368,55 @@ fn image_matrix_assignment_transforms_the_image() { let _ = std::fs::remove_dir_all(base); } +#[test] +fn a_tiny_matrix_change_still_transforms_the_image() { + let base = folder("matrix-tiny"); + let g = base.join("main/g.png"); + std::fs::write(&g, gray_png(10, 20)).unwrap(); + let mut s = session(); + let id = place(&mut s, &g, false); + let before = undo_steps(&s); + let tx = |s: &Session| match &s.active().unwrap().doc.node(id).unwrap().kind { + NodeKind::Image(im) => im.xf.as_coeffs()[4], + _ => panic!("not an image"), + }; + let old = tx(&s); + log(&mut s, &base, "var r = app.activeDocument.rasterItems[0], m = r.matrix; m.mValueTX = m.mValueTX + 5e-10; r.matrix = m;"); + assert_eq!(undo_steps(&s), before + 1); + assert!(tx(&s) != old, "the image did not move"); + let _ = std::fs::remove_dir_all(base); +} + +#[test] +fn a_stale_placed_item_is_not_a_relative_object() { + let base = folder("stale-relative"); + let a = base.join("main/a.png"); + std::fs::write(&a, gray_png(4, 4)).unwrap(); + let mut s = session(); + place(&mut s, &a, true); + place(&mut s, &a, true); + place(&mut s, &a, true); + let out = log( + &mut s, + &base, + &format!( + "var d = app.activeDocument, p = d.placedItems[0], q = d.placedItems[1], r = d.placedItems[2], m = [];\ + r.move(q, ElementPlacement.PLACEBEFORE); m.push('live');\ + var n = d.placedItems.add(); n.file = new File('{}'); r.move(n, ElementPlacement.PLACEAFTER); m.push('added');\ + p.embed();\ + try {{ r.move(p, ElementPlacement.PLACEBEFORE); }} catch (e) {{ m.push(e.message); }}\ + try {{ r.duplicate(p, ElementPlacement.PLACEAFTER); }} catch (e) {{ m.push(e.message); }}\ + n.embed();\ + try {{ r.move(n, ElementPlacement.PLACEBEFORE); }} catch (e) {{ m.push(e.message); }}\ + try {{ r.duplicate(n, ElementPlacement.PLACEAFTER); }} catch (e) {{ m.push(e.message); }}\ + vc.log(m);", + js_path(&a) + ), + ); + assert_eq!(out, vec![json!(["live", "added", "Stale page item", "Stale page item", "Stale page item", "Stale page item"])]); + let _ = std::fs::remove_dir_all(base); +} + #[test] fn image_matrix_refuses_bad_values_without_changing_the_image() { let base = folder("matrix-bad"); @@ -489,16 +538,19 @@ fn stale_and_foreign_placed_items_are_refused() { std::fs::write(&a, gray_png(4, 4)).unwrap(); let mut s = session(); let id = place(&mut s, &a, true); + place(&mut s, &a, false); let out = log( &mut s, &base, "var p = app.activeDocument.placedItems[0], m = []; p.remove();\ try { p.relink(null); } catch (e) { m.push(e.message); }\ - try { app.activeDocument.placedItems.add().file; RasterItem.prototype.embedded.call(1); } catch (e) { m.push(e.name); }\ + var g = Object.getOwnPropertyDescriptor(RasterItem.prototype, 'embedded').get;\ + try { g.call(1); } catch (e) { m.push(e.name); }\ + m.push(g.call(app.activeDocument.rasterItems[0]));\ try { PlacedItem.prototype.embed.call(app.activeDocument); } catch (e) { m.push(e.message); }\ vc.log(m);", ); - assert_eq!(out, vec![json!(["Stale page item", "TypeError", "this is not a PlacedItem"])]); + assert_eq!(out, vec![json!(["Stale page item", "TypeError", true, "this is not a PlacedItem"])]); assert!(s.active().unwrap().doc.node(id).is_none()); let _ = std::fs::remove_dir_all(base); } diff --git a/docs/mcp.md b/docs/mcp.md index 16c03f4502..1aaa922659 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -3215,8 +3215,9 @@ through `$`: `null`, `embedded` is `true` and takes only `true`, and `status` is `RasterLinkState.NODATA`. `transparent` is true for an image with an alpha channel or a transparent palette entry. `matrix` is a record of `mValueA` to `mValueTY` that maps the image's pixels, row 0 at the top, to script coordinates, and a distorted image has none. Assigning - `matrix` runs `object.transform`; a value that is not finite, a matrix with no area and one that puts a corner of - the image outside the canvas throw an error with nothing changed. `boundingBox` is the pixel rectangle at one point + `matrix` runs `object.transform`, except that a matrix equal to the one `matrix` reads runs no command; a value + that is not finite, a matrix with no area, one that puts a corner of the image outside the canvas and one that a + nearly singular image cannot reach exactly throw an error with nothing changed. `boundingBox` is the pixel rectangle at one point a pixel. `removeAll()` refuses images as `pageItems.removeAll()` refuses objects, and so throws `cannot delete objects on a locked artboard` and deletes nothing when an image is on one. Assigning `file` or `matrix` checks the item before the value, so a stale item throws `Stale page item` whatever the value. Assigning `matrix` to an `add()` From 6a9ab599c49f364cad7b9f8a7d754969da4e6551 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 03:14:32 -0800 Subject: [PATCH 6/7] Scripts: image lists propagate a page item rebuild error The merge of main brought in fe89d3f8, which makes page_items return a Result so that a rebuilt list counts against the run. The image collection still used the list as a plain Vec, so the engine did not compile (E0308, E0599 in images.rs). It now propagates the error with ?, as the other collections do. --- crates/engine/src/script/dom/images.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine/src/script/dom/images.rs b/crates/engine/src/script/dom/images.rs index 8ac02076c8..525345ffc6 100644 --- a/crates/engine/src/script/dom/images.rs +++ b/crates/engine/src/script/dom/images.rs @@ -166,7 +166,7 @@ fn images(h: &Host, st: &DocState, placed: bool) -> Result>, Host { return Ok(pick(l)); } - let all = page_items(h, st); + let all = page_items(h, st)?; h.charge_call(all.len() as u64)?; let (mut linked, mut embedded) = (Vec::new(), Vec::new()); for id in all.iter() { From ba45b5d5c26d9d139bb3c32378487d8601c53591 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 1 Dec 2026 12:40:23 -0800 Subject: [PATCH 7/7] New Document: Columns shows the laid-out count when none is stored With no stored column or row count, More Settings showed 1 in Columns while file.new lays a grid out as one row of all the artboards. Entering 1 then matched the shown value and was dropped, so the stored 0 stayed. Columns now shows the count file.new uses for the layout, so entering 1 is stored and a step that leaves the count unchanged changes nothing. --- crates/ui-egui/src/dialogs/new_document.rs | 26 ++++++++++++++++++++-- docs/mcp.md | 3 ++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index 4a8bcf6248..0b11d73c5d 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -590,10 +590,17 @@ fn more_settings_rows(ui: &mut egui::Ui, s: &mut DocSettings, lengths: LengthUni /// The columns More Settings shows: for a grid by column made with `file.new`'s `rows`, the columns /// those rows give the current number of artboards, as `file.new` lays them out; otherwise the -/// stored count. At most one for each artboard. +/// stored count, where a stored 0 shows the columns `file.new` lays out for the layout. At most +/// one for each artboard. fn shown_columns(s: &DocSettings) -> u32 { let n = s.artboards.max(1); - if s.layout == ArtboardLayout::GridByColumn && s.rows > 0 { u32::try_from(s.grid_columns()).unwrap_or(n) } else { s.columns.max(1).min(n) } + if s.layout == ArtboardLayout::GridByColumn && s.rows > 0 { + u32::try_from(s.grid_columns()).unwrap_or(n) + } else if s.columns == 0 { + u32::try_from(s.grid_columns()).unwrap_or(n).clamp(1, n) + } else { + s.columns.min(n) + } } /// Chooses a layout in More Settings. Another layout replaces a preset's rows and keeps the column @@ -1281,6 +1288,21 @@ mod tests { assert_eq!(s.grid_columns(), 2); } + /// A stored column count of 0 shows the one row of all the artboards that `file.new` lays out, so + /// entering 1 is stored and the same count as the row changes nothing. + #[test] + fn a_column_count_without_rows_is_stored() { + let mut s = DocSettings { artboards: 4, layout: ArtboardLayout::GridByRow, columns: 0, rows: 0, ..DocSettings::default() }; + assert_eq!(shown_columns(&s), u32::try_from(s.grid_columns()).unwrap_or(0)); + set_columns(&mut s, 4); + assert_eq!((s.columns, s.rows), (0, 0), "4 is what the row shows"); + set_columns(&mut s, 1); + assert_eq!((s.columns, s.rows), (1, 0)); + assert_eq!(s.grid_columns(), 1); + let column = DocSettings { artboards: 4, layout: ArtboardLayout::Column, columns: 0, rows: 0, ..DocSettings::default() }; + assert_eq!(shown_columns(&column), 1, "the Column layout is one column"); + } + /// The preset keeps the artboard layout, spacing and columns More Settings set (#4893); an empty /// name is refused. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index a39a89360e..abaa351219 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -10652,7 +10652,8 @@ and goes back to Document Setup, whose OK runs `document.setup`; its Cancel goes rows, spacing, rightToLeft}` (`rows`, 1 to 1000 and rounded to a whole number, gives a `gridByColumn` layout that many rows, at most one for each artboard, in place of `columns`, and is an error with another layout; a preset keeps the rows, and `file.newPresets` lists them as set even when there are fewer artboards, until `columns` without `rows`, or another layout, is given; New Document's Columns shows the columns -the rows give the current number of artboards, and New Document drops the rows when Columns or the layout changes), +the rows give the current number of artboards, and New Document drops the rows when Columns or the layout changes; +with neither `columns` nor `rows` set, Columns shows the columns `file.new` lays out: one row of all the artboards in a grid), `bleed`, `backgroundContents`, `colorMode`, `rasterEffectsPpi` (1 to 2,400; a saved preset's value outside that range is read as the nearer end), `previewMode` and `alignNewObjectsToPixelGrid` (see [Align New Objects to Pixel Grid](#align-new-objects-to-pixel-grid)).