mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-04 21:13:13 -05:00
fix(edit): list Form artwork whose BBox names other corners
Fixes #8903. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
a3d4c3c38e
commit
d645cfbd8a
2 files changed
+20
-1
No files matched your search
@@ -1121,7 +1121,8 @@ pub fn page_images(doc: &Document, page: usize) -> Result<Vec<PageImage>, 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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user