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()