Keep native PDF navigation transforms across page output
This commit is contained in:
1 parent
0e71c15b01
commit
cb8ed90df2
6 files changed
+155
-46
No files matched your search
@@ -697,3 +697,56 @@ fn duplicate_destinations_are_discarded_after_the_first_definition() {
|
||||
assert_eq!(pages[1].pdf_links.destinations.len(), 1);
|
||||
assert!(export_native(&execution).diagnostics.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pdf_navigation_uses_the_logical_matrix_across_shipouts() {
|
||||
let (reference, native, diagnostics) = pair(
|
||||
r"\pdfdecimaldigits=4 \pdfpagewidth=200pt \pdfpageheight=200pt
|
||||
\pdfdestmargin=1.25pt \pdflinkmargin=1.25pt
|
||||
\shipout\hbox{\pdfsave\pdfsetmatrix{0 1 -1 0}
|
||||
\kern6pt\pdfdest name{outer} fitr width6pt height9pt depth3pt
|
||||
\pdfsave\pdfsetmatrix{2 .5 -.25 1}
|
||||
\kern4pt\pdfdest name{inner} fitr width5pt height7pt depth1pt\kern-4pt
|
||||
\pdfrestore\kern-6pt
|
||||
\pdfrestore\kern4pt\pdfdest name{restored} fitr width6pt height9pt depth3pt
|
||||
\vrule width10pt height6pt}
|
||||
\shipout\hbox{\pdfsave\pdfsetmatrix{2 -.5 .25 1}
|
||||
\kern5pt\pdfrestore
|
||||
\pdfdest name{after-shift} fitr width6pt height9pt depth3pt
|
||||
\pdfstartlink width6pt height9pt depth3pt goto name{inner}\kern6pt\pdfendlink
|
||||
\vrule width10pt height6pt}
|
||||
\shipout\hbox{\vrule width10pt height6pt\pdfsetmatrix{0 1 -1 0}}
|
||||
\pdfpageheight=230pt
|
||||
\shipout\hbox{\kern10pt\pdfdest name{next-page} fitr width6pt height9pt depth3pt
|
||||
\pdfstartlink width6pt height9pt depth3pt goto name{inner}\kern6pt\pdfendlink
|
||||
\vrule width10pt height6pt}",
|
||||
);
|
||||
assert!(diagnostics.is_empty(), "{diagnostics:?}");
|
||||
let navigation = |doc: &Document| {
|
||||
let pages = doc.get_pages();
|
||||
let names = get(doc, doc.catalog().unwrap(), b"Names").as_dict().unwrap();
|
||||
let dests = get(doc, names, b"Dests").as_dict().unwrap();
|
||||
let targets = get(doc, dests, b"Names").as_array().unwrap();
|
||||
let resolve = |object: &Object| doc.get_object(object.as_reference().unwrap()).unwrap();
|
||||
let targets: Vec<_> = targets.chunks_exact(2).map(|target| {
|
||||
let dictionary = resolve(&target[1]).as_dict().unwrap();
|
||||
let view = get(doc, dictionary, b"D").as_array().unwrap();
|
||||
let page = view[0].as_reference().unwrap();
|
||||
let page_number = pages.iter().find(|(_, id)| **id == page).unwrap().0;
|
||||
let view = view[1..].iter().map(comparable).collect::<Vec<_>>();
|
||||
(target[0].as_str().unwrap().to_vec(), *page_number, view)
|
||||
}).collect();
|
||||
let rects: Vec<_> = pages.values().filter_map(|id| {
|
||||
let page = doc.get_dictionary(*id).unwrap();
|
||||
let annotations = page.get(b"Annots").ok()?.as_array().unwrap();
|
||||
assert_eq!(annotations.len(), 1);
|
||||
let link = resolve(&annotations[0]).as_dict().unwrap();
|
||||
Some(comparable(get(doc, link, b"Rect")))
|
||||
}).collect();
|
||||
(targets, rects)
|
||||
};
|
||||
let expected = navigation(&reference);
|
||||
assert_eq!(expected.0.len(), 5);
|
||||
assert_eq!(expected.1.len(), 2);
|
||||
assert_eq!(navigation(&native), expected);
|
||||
}
|
||||
Reference in new issue
Block a user