From 70d92a052bbc19ff60fa31578ad37275d499e5ee Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 24 Oct 2026 06:21:39 +0000 Subject: [PATCH] Integration: #2289 keep Contents, BM, Lang and AF on the split widget --- crates/organize/src/import.rs | 4 ++++ crates/organize/src/tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/crates/organize/src/import.rs b/crates/organize/src/import.rs index 15087a0c5f..3e56c0d53d 100644 --- a/crates/organize/src/import.rs +++ b/crates/organize/src/import.rs @@ -59,6 +59,10 @@ const WIDGET_KEYS: &[&[u8]] = &[ b"OC", b"Tabs", b"A", + b"Contents", + b"BM", + b"Lang", + b"AF", ]; struct Copier<'a> { diff --git a/crates/organize/src/tests.rs b/crates/organize/src/tests.rs index a9364e83ff..85c3199150 100644 --- a/crates/organize/src/tests.rs +++ b/crates/organize/src/tests.rs @@ -1014,6 +1014,30 @@ fn splitting_a_combined_widget_keeps_annotation_actions_and_field_triggers() { } } +#[test] +fn splitting_a_combined_widget_keeps_its_annotation_only_keys() { + let mut src = doc_a(); + let list = page_dict(&src, 1).get(b"Annots").and_then(|a| a.as_array()).cloned().unwrap(); + let widget = + list.iter().filter_map(Object::as_ref).find(|r| src.get(*r).as_dict().is_some_and(|d| d.name(b"Subtype") == Some(b"Widget"))).unwrap(); + src.update_dict(widget, |d| { + d.set(b"Contents".to_vec(), Object::String(PdfString::text("alt text"))); + d.set(b"BM".to_vec(), Object::name("Multiply")); + d.set(b"Lang".to_vec(), Object::String(PdfString::text("en-US"))); + d.set(b"AF".to_vec(), Object::Array(Vec::new())); + }) + .unwrap(); + let out = full_roundtrip(&extract_pages(&src, &[1, 1]).unwrap()); + for i in 0..2 { + let w = annots(&out, i).into_iter().find(|d| d.name(b"Subtype") == Some(b"Widget")).unwrap(); + let parent = out.get(w.reference(b"Parent").unwrap()).as_dict().unwrap().clone(); + for key in [b"Contents".as_slice(), b"BM", b"Lang", b"AF"] { + assert!(w.contains(key), "the widget keeps {key:?}"); + assert!(!parent.contains(key), "the parent field does not take {key:?}"); + } + } +} + #[test] fn repeated_page_gets_independent_annotations() { // A1 has a link, A2 a link and a form field, A3 a note with a popup; each is listed twice.