Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Merge upstream main 932bf9c6 into pr/attachments

Osvaldo Duranf24a26b95179
diff --cc ATTRIBUTION.toml
index 90b821c1f,db3dd6124..14609784a
--- a/ATTRIBUTION.toml
+++ b/ATTRIBUTION.toml
@@@ -7,7 -7,7 +7,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Greek UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "25fc94c915d23bf12495ad3ce97fce9065e9a7349c6b7f455b16d2a9524b8754"
-sha256 = "6eee0b34db6529f26235bfc07fa1fdb9030b8e7b0b10ede271ca9242cb491919"
++sha256 = "da86ae2d0c8ed2c976f9faa6a6e4f21b18fc76e5ab3638fc7bc6f69d1893b404"
# ATTRIBUTION.toml: one entry per asset (AGENTS.md §1). The source of truth for provenance and licences.
# ATTRIBUTION.md is generated from this file: `cargo xtask assets --write`. Checked by `cargo xtask assets` (part of `xtask ci`).
@@@ -30,7 -30,7 +30,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Simplified Chinese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "e24d49b04ff0248489cf7345b2c13bf6b07a1dd5b5dddbcde5584511ad5165de"
-sha256 = "9870c0fb9f7198155be16adee7f45d36cb9a254af90b545a3ce5b04cbbbf24d4"
++sha256 = "45f2c18b50a2f7879a3aa81112107642f4b396340503d61cad703747d6189a0d"
[[asset]]
path = "crates/ui-egui/src/i18n/zh-hant.tsv"
@@@ -41,7 -41,7 +41,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Traditional Chinese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "09bcc5e86c217f4354354db41c8e0a8d631ae874571edeabbcc366b61f404b57"
-sha256 = "fc31e40877ce115cfb7033c57dd6acabcae3725b249364387e3fe23e04d94e5e"
++sha256 = "be39c1b72ee171eef693759d882cf711929fa3dcddb87bd15830e19dc575b841"
[[asset]]
path = "crates/ui-egui/src/i18n/cs.tsv"
@@@ -52,7 -52,7 +52,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Czech UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "4a5c035e920ce52df20f1bcdee57b5d66fa3ffed0dae6d368d9f6f3b90cae790"
-sha256 = "5de19834f293efaea68cb6b7f51a71d320391f53345f56cfebcd73dab828b665"
++sha256 = "3dd24819053808bd1ccfeeceef2ae70aedfe3bbb571c0d936928aa81f5955202"
[[asset]]
path = "crates/ui-egui/src/i18n/pt-br.tsv"
@@@ -63,7 -63,7 +63,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Brazilian Portuguese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "201342519f0e715a88779e342026f695dd7e3960621ab8cab3689966b4221684"
-sha256 = "cef0d22341d0722f029c6543fc846fce164331b7ad8f693a6754b7567b9d9e95"
++sha256 = "13d767888304b286163a2b7672584ce92b4119fbb22955258e6467485b29c7b5"
[[asset]]
path = "crates/ui-egui/src/i18n/es.tsv"
@@@ -74,7 -74,7 +74,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Spanish UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "4124a45304f320c0a693d8fb8730177f033156b87bf9763ddcbdd010fd4ee0dd"
-sha256 = "c0ca7761cbabd8096bc9af54cdf6b88b3ae0cd8210003db8b3356e2706e44fc8"
++sha256 = "f173c035f6e2a723d69b6bfa9b2b00cbfc653bed830f93d28b309e0dfebd7bb9"
[[asset]]
path = "crates/ui-egui/src/i18n/fr.tsv"
@@@ -85,7 -85,7 +85,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "French UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "75c1975894c457f159380754dfdf2fde9a0a411d0faa766322ad62f3ad5dd6b3"
-sha256 = "a8afd51c3296f44b0446d6b06492b1348444b3e3c448a326ad213d18ce7af714"
++sha256 = "7aa0cb381b2d382b012c6fbc661a9f5cd0e2a253b4399296a39132c9ab767370"
[[asset]]
path = "crates/ui-egui/src/i18n/de.tsv"
@@@ -96,7 -96,7 +96,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "German UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "092508b34e6f87f48968aca6d158c0ba809c5250e43868e0ae1701c43351cf47"
-sha256 = "7676a2dfaa7d66e2e9ef608d2d9de7f863557dcecbef6d94bafa981097405e6d"
++sha256 = "4da28646b2e1136951d1a8dd16a09b76ac29175245942a01937666ee7e42f7cc"
[[asset]]
path = "crates/ui-egui/src/i18n/te.tsv"
@@@ -107,7 -107,7 +107,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Telugu UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "513627b2fb47af26350bb060b4c95d1072a0a841fc1aa3a386294a059a7790f7"
-sha256 = "9a22996c0308ea5b20ec5e328504cd83cbb560147763faaf0e6987f974844c29"
++sha256 = "52ca6321dc2161791ee0ce4e0abfaaf43423704671c282b8aad57d3dc44c6fa9"
[[asset]]
path = "crates/ui-egui/src/i18n/it.tsv"
@@@ -118,7 -118,7 +118,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Italian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "20269acc8ad2ab87954f7f9a07e2d8efbb45d9f88d9698143bb2c7f6dd4d0071"
-sha256 = "eacc972d65a2d951e94e1a8cf944638e8328f73f6c05759de6059a425f159cd7"
++sha256 = "2b30e6b8b5458a37d7cbb639c6821b65ea1a1fadc745766736104aba835af8e0"
[[asset]]
path = "crates/ui-egui/src/i18n/pl.tsv"
@@@ -129,7 -129,7 +129,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Polish UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "7f6e40c06f1a73ca66dab2999a6130be769a5a6f5e4428bbb7ae90a51cd0846d"
-sha256 = "dfa4aa540cc7d61fa22a27a949e6eec0f78dcc5b883d0e4e004d695e460b95aa"
++sha256 = "afefb3776c225e8a74d593cfaac8310c6828f429253e10464afc1230de809b4a"
[[asset]]
path = "crates/ui-egui/src/i18n/ru.tsv"
@@@ -140,7 -140,7 +140,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Russian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "f6cd9b7571a91a64dad5a1505c6f92996f15325ecb8c2660842adbdf2d682f65"
-sha256 = "27e02e7bb3d378bceca76988a9dceaa68d974f57cbee962954deca6184cf62aa"
++sha256 = "d165d80b38ac764d9c836684c93debac742ab9044e546b1a516e35a7c86cab67"
[[asset]]
path = "crates/ui-egui/src/i18n/hu.tsv"
@@@ -151,7 -151,7 +151,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Hungarian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "61c6ee348f9e677197c4088e7969ef395a1a136c37beb5461bee979a9da3cfbe"
-sha256 = "9675edd36c5ae54d9893fd10c4325aab664941bf714c08fbfeef9134fa42056c"
++sha256 = "8e0aef0dc46f436576494f57c9a6bdc36d342644eb8e494f0f6856a9b5d6f73b"
[[asset]]
path = "crates/ui-egui/src/i18n/bg.tsv"
@@@ -162,7 -162,7 +162,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Bulgarian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "bf923e2d70670f3a64bf22ee682686aec7bf369a464568fdc7b2c987a8c86098"
-sha256 = "ce18fc96f8516aa917e4a8bcfd290edec13a9800b3d1ee102e4b2a71b8467d2b"
++sha256 = "9418b5b093eb7e6a9b40a911a88ea81b3505bd9c889d9cf9f62efa5ee7d5b593"
[[asset]]
path = "crates/ui-egui/src/i18n/kk.tsv"
@@@ -173,7 -173,7 +173,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Kazakh UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "0735d4c9c28e717bd63b6a360dd371eec74ffe03384a1319c93770059c1b89cd"
-sha256 = "286a1e2e051748eb4bcee3906918dc78d0704f8a37bde22dc50d3376d5e75017"
++sha256 = "b81f5326237bcad2d0fce4059510f965b1f79e48d06e0ca876190db9af8dd6e5"
[[asset]]
path = "crates/ui-egui/src/i18n/ja.tsv"
@@@ -184,7 -184,7 +184,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Japanese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "422b5ebf083a818b9be6bcad42d9c6c5a3c9a86fa18cdcdda84affe422b2b27a"
-sha256 = "77593b7497c67f4a79cc31fa43fdd6eae11601dd87c079a8e666b25cdd9117ba"
++sha256 = "aa9be42c9f774c8e3f05ef348bb99835d0759c55c691c9dca70b9429608a87b8"
[[asset]]
path = "crates/ui-egui/src/i18n/uk.tsv"
@@@ -195,7 -195,7 +195,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Ukrainian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "bb01672cf2f673a75a75d33e3ad67dca837d8f1ba072993504737e3446cc4e43"
-sha256 = "d7d93a03f22ab380696f69b20b12104bf30e78c4440b683df63594af716894e2"
++sha256 = "a500169e8b601a652908c18cec34edf1bbc6c963a9aff8b426483881a08b54d5"
[[asset]]
path = "crates/ui-egui/src/i18n/ar.tsv"
@@@ -206,7 -206,7 +206,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Arabic UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "648e4b9534157ae0f84906ed169fe390d52cfdd3cf276643e0bf6db783937732"
-sha256 = "889a0d0a9ea53ca0a818c2ba672c053c232d2cca140f8d63127353e6f36505fe"
++sha256 = "bd0f0638e85a3469eebf7063301457742b1b2ff525bec1562c5e79b3bc92d06e"
[[asset]]
path = "crates/ui-egui/src/i18n/tr.tsv"
@@@ -217,7 -217,7 +217,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Turkish UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "b698bf8de8264764a0205c879cc8273aa2878e89b00c52664f2d500ab8d32a93"
-sha256 = "bae8b21651ae2a69c71c91b69ba79727254dbfb078c1be312a13383332934927"
++sha256 = "cd44a7e7420c06ed41100a5eee6c9fbb21f77c29d51b928875bc02975aa061a1"
[[asset]]
path = "crates/ui-egui/src/i18n/lt.tsv"
@@@ -228,7 -228,7 +228,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Lithuanian UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "ae80faf0682dcdf64d6f2b5b4411fbd47475a0a969d9eaebcc5fd2c8bdb3a876"
-sha256 = "7fa70f68a9fa24d0b1cac05fe3aaabaeaca9750c57416124bd317a4eda806d5a"
++sha256 = "f94f7287af0811c05c83c45e0b7871eff4fe9dd72cf045eb976a5ba0a23458a9"
[[asset]]
@@@ -3352,7 -3352,7 +3352,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Vietnamese UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "43af5371ca4b32341221296cb338d78754993b59f57648b59a29da190655c316"
-sha256 = "95b5fc6d10f7bc8371688772741870448de716fa2dd9af62fdfe4e009d269b45"
++sha256 = "a22c1ed30e5302294c68cfefc0722a1d100bd394019f68b4cae878e28217be3d"
[[asset]]
path = "crates/ui-egui/src/i18n/sl.tsv"
@@@ -3363,7 -3363,7 +3363,7 @@@ licence = "MIT OR Apache-2.0
licence_file = "LICENSE-MIT"
kind = "translation"
usage = "Slovene UI strings, compiled in by crates/ui-egui/src/i18n/mod.rs"
- sha256 = "fa2ba35b15455d97b771d4ce7a61d9dd8eb6e6ffed7aa5ada6bdc2a026fd3512"
-sha256 = "3ac2b113045b7e399dd6d9ddb7773e5b0874c8b43c2ba4cca5854598a2a7ba92"
++sha256 = "0075d7d9435776e4b51179615757f5cbb604f51489ed49db922c54e9249007c1"
[[asset]]
diff --cc crates/engine/src/lib.rs
index 87f288dd9,8f39248ab..255077ce8
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@@ -2391,12 -2408,11 +2426,15 @@@ fn run_edit(doc: &mut pdfcraft_cos::Doc
Edit::EraseInk { page, index, path, radius } => {
pdfcraft_annot::erase_ink(doc, *page, *index, path, *radius, &cx.meta())?;
}
+ Edit::AddAttachment { name, bytes, description, mime } => {
+ pdfcraft_organize::add_attachment(doc, name, bytes, description.as_deref(), mime.as_deref(), cx.date.as_deref())?;
+ }
+ Edit::DeleteAttachment { key } => pdfcraft_organize::delete_attachment(doc, key)?,
Edit::ReplaceText { page, quads, text, author, strike, caret } => {
- pdfcraft_annot::add_text_replacement(doc, *page, quads, text, author, strike, caret, &cx.meta())?;
+ // One `/NM` each: the caret replies to the strikeout, and XFDF names that reply by
+ // the strikeout's `/NM` (#2666).
+ let (strike_meta, caret_meta) = (cx.meta(), cx.meta());
+ pdfcraft_annot::add_text_replacement(doc, *page, quads, text, author, strike, caret, &strike_meta, &caret_meta)?;
}
Edit::MarkAnnotation { page, index, marked, author } => {
pdfcraft_annot::set_marked(doc, *page, *index, *marked, author, &cx.meta())?;
diff --cc crates/organize/src/tests.rs
index 9b36f229d,9bd3eb396..fa3a78af4
--- a/crates/organize/src/tests.rs
+++ b/crates/organize/src/tests.rs
@@@ -2658,83 -2790,34 +2790,115 @@@ fn a_chain_of_objects_too_deep_to_copy_
assert!(run.is_ok(), "the copy must not overflow the stack");
}
+/// What Edit ▸ Attach file added survives Combine files (upstream's writer), names
+/// with accents included, and the combined document takes more attachments and deletions.
+#[test]
+fn attachments_added_in_the_app_survive_combine_and_more_can_be_attached() {
+ let embedded = |doc: &Document, key: &str| -> (Vec<u8>, Option<String>) {
+ let names = doc.resolve(catalog(doc).get(b"Names").unwrap()).as_dict().cloned().unwrap();
+ let tree = doc.resolve(names.get(b"EmbeddedFiles").unwrap()).as_dict().cloned().unwrap();
+ let pairs = tree.get(b"Names").and_then(|n| n.as_array()).cloned().unwrap();
+ let at = pairs.chunks(2).position(|p| p[0].as_string().unwrap().to_text() == key).unwrap_or_else(|| panic!("no attachment {key}"));
+ let spec = doc.resolve(&pairs[at * 2 + 1]).as_dict().cloned().unwrap();
+ let desc = spec.get(b"Desc").and_then(Object::as_string).map(|s| s.to_text());
+ let ef = spec.get(b"EF").and_then(Object::as_dict).unwrap().get(b"F").cloned().unwrap();
+ let Object::Stream(stream) = doc.resolve(&ef).as_ref().clone() else { panic!("the embedded file is a stream") };
+ (stream.decoded().unwrap(), desc)
+ };
+ let mut a = Document::open(Arc::new(fixture())).unwrap();
+ add_attachment(&mut a, "invoice.csv", b"a,b", Some("March"), Some("text/csv"), None).unwrap();
+ add_attachment(&mut a, "año.txt", b"uno", None, None, None).unwrap();
+ let mut b = Document::open(Arc::new(fixture())).unwrap();
+ add_attachment(&mut b, "invoice.csv", b"x,y", None, None, None).unwrap();
+ add_attachment(&mut b, "año.txt", b"dos", None, None, None).unwrap();
+ let a = save_and_reopen(&a);
+ let b = save_and_reopen(&b);
+ let mut out = full_roundtrip(&combine(&[("A", &a), ("B", &b)]).unwrap());
+ // Both files' attachments, the second copies numbered as text (not bytes glued onto UTF-16).
+ assert_eq!(attachment_keys(&out), ["invoice.csv", "invoice.csv (2)", "año.txt", "año.txt (2)"]);
+ assert_eq!(embedded(&out, "invoice.csv"), (b"a,b".to_vec(), Some("March".into())));
+ assert_eq!(embedded(&out, "invoice.csv (2)"), (b"x,y".to_vec(), None));
+ assert_eq!(embedded(&out, "año.txt (2)").0, b"dos");
+ // The combined document goes on taking attachments, and losing them, like any other.
+ assert_eq!(add_attachment(&mut out, "invoice.csv", b"z", None, None, None).unwrap(), "invoice.csv (3)");
+ delete_attachment(&mut out, "invoice.csv (2)").unwrap();
+ let out = full_roundtrip(&out);
+ assert_eq!(attachment_keys(&out), ["invoice.csv", "invoice.csv (3)", "año.txt", "año.txt (2)"]);
+ assert_eq!(embedded(&out, "invoice.csv (3)").0, b"z");
+}
+
+#[test]
+fn attachments_are_added_listed_and_deleted() {
+ let mut doc = Document::open(Arc::new(fixture())).unwrap();
+ assert!(attachment_keys(&doc).is_empty());
+ // A path loses its folder; the key is the file name.
+ let key = add_attachment(&mut doc, "/Users/eva/Desktop/invoice.csv", b"a,b\n1,2\n", Some("March"), Some("text/csv"), Some("D:20261012120000Z"))
+ .unwrap();
+ assert_eq!(key, "invoice.csv");
+ // The same name again is kept apart.
+ assert_eq!(add_attachment(&mut doc, "invoice.csv", b"x", None, None, None).unwrap(), "invoice.csv (2)");
+ assert_eq!(add_attachment(&mut doc, " ", b"x", None, None, None), Err(OrganizeError::Invalid("the attachment needs a file name".into())));
+ let doc = save_and_reopen(&doc);
+ assert_eq!(attachment_keys(&doc), ["invoice.csv", "invoice.csv (2)"]);
+ // What was written: a Filespec with the embedded stream, its size and type, and the description.
+ let root = doc.root().unwrap();
+ let names = doc.get(root).as_dict().unwrap().get(b"Names").cloned().unwrap();
+ let tree = doc.resolve(&names).as_dict().unwrap().get(b"EmbeddedFiles").cloned().unwrap();
+ let tree = doc.resolve(&tree);
+ let pairs = tree.as_dict().unwrap().get(b"Names").cloned().unwrap();
+ let pairs = doc.resolve(&pairs).as_array().cloned().unwrap();
+ assert_eq!(pairs.len(), 4);
+ let spec = doc.resolve(&pairs[1]);
+ let spec = spec.as_dict().unwrap();
+ assert_eq!(spec.get(b"Type"), Some(&Object::name("Filespec")));
+ assert_eq!(spec.get(b"UF").and_then(Object::as_string).map(PdfString::to_text).as_deref(), Some("invoice.csv"));
+ assert_eq!(spec.get(b"Desc").and_then(Object::as_string).map(PdfString::to_text).as_deref(), Some("March"));
+ let ef = spec.get(b"EF").and_then(Object::as_dict).unwrap().get(b"F").cloned().unwrap();
+ let ef = doc.resolve(&ef);
+ let Object::Stream(stream) = ef.as_ref() else { panic!("the embedded file is a stream") };
+ assert_eq!(stream.dict.get(b"Subtype"), Some(&Object::Name(b"text/csv".to_vec())));
+ let params = stream.dict.get(b"Params").and_then(Object::as_dict).unwrap();
+ assert_eq!(params.get(b"Size"), Some(&Object::Int(8)));
+ assert_eq!(stream.decoded().unwrap(), b"a,b\n1,2\n");
+ // Deleting: the one named goes, the other stays; the last one takes the tree with it.
+ let mut doc = doc;
+ delete_attachment(&mut doc, "invoice.csv").unwrap();
+ assert_eq!(attachment_keys(&doc), ["invoice.csv (2)"]);
+ assert_eq!(delete_attachment(&mut doc, "invoice.csv"), Err(OrganizeError::Invalid("there is no attachment named invoice.csv".into())));
+ delete_attachment(&mut doc, "invoice.csv (2)").unwrap();
+ let doc = save_and_reopen(&doc);
+ assert!(attachment_keys(&doc).is_empty());
+ assert!(doc.get(doc.root().unwrap()).as_dict().unwrap().get(b"Names").is_none());
+}
++
+ #[test]
+ fn rotate_repeated_indices_accumulate_from_the_current_page_value() {
+ for level in 0..3 {
+ for indices in [vec![0, 0], vec![0, 1, 0]] {
+ let mut doc = open(fixture());
+ let rotation = doc.add(Object::Int(90));
+ let page = pages(&doc).unwrap()[0].obj;
+ let target = match level {
+ 0 => page,
+ 1 => doc.get(page).as_dict().unwrap().reference(b"Parent").unwrap(),
+ _ => pages_root(&doc).unwrap(),
+ };
+ doc.update_dict(target, |d| d.set(b"Rotate".to_vec(), Object::Ref(rotation))).unwrap();
+ let mut doc = open(write_full(&doc, &SaveOptions::default()).unwrap());
+ let rotation = walk(&doc).unwrap()[0].1.reference(b"Rotate").unwrap();
+ let original_labels = labels(&doc);
+ rotate_pages(&mut doc, &indices, 90).unwrap();
+ assert_eq!(page_rotation(&doc, 0).unwrap(), 270, "level {level}, indices {indices:?}");
+ assert_eq!(*doc.get(rotation), Object::Int(90), "shared source angle is unchanged");
+ for saved in [write_incremental(&doc, &SaveOptions::default()).unwrap(), write_full(&doc, &SaveOptions::default()).unwrap()] {
+ let reopened = open(saved.clone());
+ assert_eq!(page_rotation(&reopened, 0).unwrap(), 270);
+ assert_eq!(page_rotation(&reopened, 1).unwrap(), if indices.len() == 3 { 180 } else { 90 });
+ assert_eq!(page_rotation(&reopened, 2).unwrap(), 90);
+ assert_eq!(labels(&reopened), original_labels);
+ let independent = hayro_syntax::Pdf::new(saved).unwrap();
+ assert_eq!(independent.pages()[0].render_dimensions(), (400.0, 300.0));
+ }
+ }
+ }
+ }