PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge PR #4041: fix: Issue #4020, Extract keeps the bookmarks of the pages it copies
aiongga954a96cb510
diff --cc crates/organize/src/tests.rsindex 85c319915,f79a4e95f..62fcb817c--- a/crates/organize/src/tests.rs+++ b/crates/organize/src/tests.rs@@@ -1076,12 -978,31 +1076,34 @@@ fn form_fields_come_along_and_are_regisassert_eq!(fields.len(), 1);let field = out.resolve(&fields[0]).as_dict().cloned().unwrap();assert_eq!(field.get(b"V").and_then(|v| v.as_string()).map(|s| s.to_text()).as_deref(), Some("Ada"));- assert_eq!(field.reference(b"P"), Some(pages(&out).unwrap()[0].obj));+ // The widget child, not the field, names the page (#1810).+ let kid =+ field.get(b"Kids").map(|k| out.resolve(k)).and_then(|k| k.as_array().cloned()).and_then(|k| k.first().and_then(|k| k.as_ref())).unwrap();+ assert_eq!(out.get(kid).as_dict().unwrap().reference(b"P"), Some(pages(&out).unwrap()[0].obj));}+ /// #4020: Extract keeps the bookmarks that go to the pages it copies, mapped to the copies. One whose+ /// page was left out goes, unless a bookmark under it stays.+ #[test]+ fn extract_keeps_the_bookmarks_of_the_pages_it_copies() {+ let mut src = doc_a();+ crate::add_bookmark(&mut src, &[], 0, "One", 0).unwrap();+ crate::add_bookmark(&mut src, &[], 1, "Two", 1).unwrap();+ crate::add_bookmark(&mut src, &[1], 0, "Two.a", 2).unwrap();+ crate::add_bookmark(&mut src, &[], 2, "Three", 2).unwrap();+ let marks = |d: &Document| -> Vec<(String, usize, Option<usize>)> { bookmarks(d).into_iter().map(|b| (b.title, b.path.len(), b.page)).collect() };+ let s = |t: &str| t.to_string();++ let all = full_roundtrip(&extract_pages(&src, &[0, 1, 2]).unwrap());+ assert_eq!(marks(&all), [(s("One"), 1, Some(0)), (s("Two"), 1, Some(1)), (s("Two.a"), 2, Some(2)), (s("Three"), 1, Some(2))]);++ let last = full_roundtrip(&extract_pages(&src, &[2]).unwrap());+ assert_eq!(marks(&last), [(s("Two"), 1, None), (s("Two.a"), 2, Some(0)), (s("Three"), 1, Some(0))], "One's page was left out");++ let none = full_roundtrip(&extract_pages(&doc_a(), &[0]).unwrap());+ assert!(!none.get(none.root().unwrap()).as_dict().unwrap().contains(b"Outlines"), "no bookmarks, no outline");+ }+#[test]fn popup_cycles_copy_once_and_structure_links_are_removed() {let out = full_roundtrip(&extract_pages(&doc_a(), &[2]).unwrap());