From d645cfbd8a132d693dec9eb8bc3e918fac9a0fec Mon Sep 17 00:00:00 2001 From: quincy-jc <184324679+quincy-jc@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:05:26 +1100 Subject: [PATCH] fix(edit): list Form artwork whose BBox names other corners Fixes #8903. Co-Authored-By: Claude Opus 5.5 --- crates/edit/src/images.rs | 3 ++- crates/edit/src/tests.rs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/edit/src/images.rs b/crates/edit/src/images.rs index ad6c18e979..74980af08e 100644 --- a/crates/edit/src/images.rs +++ b/crates/edit/src/images.rs @@ -1121,7 +1121,8 @@ pub fn page_images(doc: &Document, page: usize) -> Result, EditEr for (n, v) in b.iter_mut().zip(a) { *n = v.as_f64()?; } - Some(b) + // Any two opposite corners name the box (ISO 32000-2 §7.9.5). + Some([b[0].min(b[2]), b[1].min(b[3]), b[0].max(b[2]), b[1].max(b[3])]) }) }) else { continue; diff --git a/crates/edit/src/tests.rs b/crates/edit/src/tests.rs index b896481769..be91f816d9 100644 --- a/crates/edit/src/tests.rs +++ b/crates/edit/src/tests.rs @@ -6748,6 +6748,24 @@ fn page_with_form(dict: &[(&str, Object)], content: &[u8], prefix: &str, page_st (reopen(&doc), artwork) } +/// #8903: a Form's `/BBox` may name any two opposite corners (ISO 32000-2 §7.9.5), so artwork +/// whose box is written top first, or right to left, is listed where its box puts it. +#[test] +fn form_artwork_is_listed_whichever_corners_its_box_names() { + let content = b"0 0 1 rg 0 0 100 50 re f"; + let (doc, _) = page_with_form(&[], content, "", None); + let expected = images::page_images(&doc, 0).unwrap(); + assert_eq!(expected.len(), 2); + for corners in [[0, 50, 100, 0], [100, 0, 0, 50], [100, 50, 0, 0]] { + let (doc, _) = page_with_form(&[("BBox", Object::Array(corners.map(Object::Int).to_vec()))], content, "", None); + let listed = images::page_images(&doc, 0).unwrap(); + assert_eq!(listed.len(), expected.len(), "{corners:?}: both placements are listed"); + for (got, want) in listed.iter().zip(&expected) { + assert!(got.is_form && close(got.rect, want.rect), "{corners:?}: {:?} where {:?} was expected", got.rect, want.rect); + } + } +} + /// #2964 / #3005: Ungroup draws a form's content in place of one of its `Do`s, so its text is the /// page's own and edits like any other. Its fonts are merged under fresh names where the page's /// clash, the form object and the other placement stay as they were, and a page sharing the