Scripts: controlBounds, placedItems and rasterItems follow main's empty-object and topmost-first rules

On main, a page item's bounds are an Option, and an object with nothing in it
reads its bounds as zeros. controlBounds now does the same: it joins the
visible bounds with the handle bounds when either exists, and reads zeros
when neither does.

Main lists pageItems topmost first. placedItems and rasterItems take their
order from pageItems, so they list the images topmost first too; docs/mcp.md
says so, and the tests that read the newest object or the bottom one by index
read it at its new position.

The plug-in test main added that builds a ScriptGate by hand now sets the
held field this branch added to it.
This commit is contained in:
dotCooCoo committed 2026-11-27 23:11:19 -08:00
1 parent 629c5cc038
commit d6bb6429f4
6 files changed
+16 -9

No files matched your search

+6 -2
View File
@@ -1811,12 +1811,16 @@ fn item_visible(h: &Host, a: &[Data]) -> Answer {
bounds(h, a, true)
}
/// `controlBounds`: the visible bounds and the Bézier handles of the item's paths.
/// `controlBounds`: the visible bounds and the Bézier handles of the item's paths, zeros for an
/// object with nothing in it.
fn item_control(h: &Host, a: &[Data]) -> Answer {
let item = this_item(h, a)?;
let (r, f) = item_rect(h, item, true)?;
let handles = with_doc(h, item.doc, |_, st| st.doc.node(item.id).and_then(handle_bounds));
Ok(f.bounds(h.dom.coords.get(), handles.map_or(r, |b| r.union(b))))
match r.into_iter().chain(handles).reduce(|a, b| a.union(b)) {
Some(r) => Ok(f.bounds(h.dom.coords.get(), r)),
None => Ok(Data::Array(vec![num(0.0), num(0.0), num(0.0), num(0.0)])),
}
}
/// The bounds of the anchors and handles of `n`'s paths: a path's own, and those of the shown
+2 -1
View File
@@ -127,7 +127,8 @@ fn pending_handle(d: &Data) -> Option<[f64; 3]> {
}
}
/// 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 as [`page_items`]
/// lists them.
fn images(h: &Host, st: &DocState, placed: bool) -> Result<Rc<Vec<NodeId>>, HostError> {
let pick = |l: &Lists| if placed { l.2.clone() } else { l.3.clone() };
if let Some(l) = &*h.dom.images.lists.borrow()
+1
View File
@@ -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,
};
+1 -1
View File
@@ -140,7 +140,7 @@ fn page_item_control_bounds_take_in_the_handles() {
let (mut s, _, _) = doc();
let anchors = json!([{"x": 0, "y": 100, "out": [0, 0]}, {"x": 100, "y": 100, "in": [100, 0]}]);
s.execute("path.create", &json!({"anchors": anchors})).unwrap();
let out = log(&mut s, "var p = app.activeDocument.pageItems, i = p[p.length - 1]; vc.log(i.visibleBounds); vc.log(i.controlBounds);");
let out = log(&mut s, "var i = app.activeDocument.pageItems[0]; vc.log(i.visibleBounds); vc.log(i.controlBounds);");
let b = |v: &Value| -> Vec<f64> { v.as_array().unwrap().iter().map(|n| n.as_f64().unwrap()).collect() };
let (visible, control) = (b(&out[0]), b(&out[1]));
assert!(visible[1] < 290.0, "the curve stays well under its handles: {visible:?}");
+5 -4
View File
@@ -326,9 +326,10 @@ fn raster_metadata_uses_encoded_header_not_rgb_fallback() {
&base,
"var r = app.activeDocument.rasterItems, t = [];\
for (var i = 0; i < r.length; i++) t.push([r[i].imageColorSpace, r[i].channels, r[i].bitsPerChannel, r[i].transparent, r[i].colorizedGrayscale]);\
vc.log(t); vc.log(r[0].boundingBox); vc.log(r[1].imageColorSpace === ImageColorSpace.RGB); var m = r[1].matrix; vc.log([m.typename, m.mValueA, m.mValueD]);",
vc.log(t); vc.log(r[1].boundingBox); vc.log(r[0].imageColorSpace === ImageColorSpace.RGB); var m = r[0].matrix; vc.log([m.typename, m.mValueA, m.mValueD]);",
);
assert_eq!(out[0], json!([["ImageColorSpace.Grayscale", 1, 8, false, false], ["ImageColorSpace.RGB", 4, 8, true, false]]));
// The collection lists the images topmost first, as `pageItems` does: the color image placed last comes first.
assert_eq!(out[0], json!([["ImageColorSpace.RGB", 4, 8, true, false], ["ImageColorSpace.Grayscale", 1, 8, false, false]]));
assert_eq!(out[1], json!([0, 4, 6, 0]));
assert_eq!(out[2], json!(true));
let m = out[3].as_array().unwrap();
@@ -577,9 +578,9 @@ fn a_stale_placed_item_is_refused_as_the_relative_object_of_move() {
"var d = app.activeDocument, p = d.placedItems[0], x = null, m = '';\
for (var i = 0; i < d.pageItems.length; i++) { if (d.pageItems[i].typename == 'PathItem') x = d.pageItems[i]; }\
p.embed(); try { x.move(p, ElementPlacement.PLACEAFTER); } catch (e) { m = e.message; } vc.log(m);\
x.move(d.rasterItems[0], ElementPlacement.PLACEAFTER); vc.log(d.pageItems[0].typename);",
x.move(d.rasterItems[0], ElementPlacement.PLACEAFTER); vc.log([d.pageItems[0].typename, d.pageItems[1].typename]);",
);
assert_eq!(out, vec![json!("Stale page item"), json!("PathItem")]);
assert_eq!(out, vec![json!("Stale page item"), json!(["RasterItem", "PathItem"])]);
assert!(s.active().unwrap().doc.node(NodeId(rect)).is_some());
let _ = std::fs::remove_dir_all(base);
}
+1 -1
View File
@@ -2938,7 +2938,7 @@ 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()`