Resolve native PDF structure destinations and local actions
This commit is contained in:
1 parent
58bcfca7b7
commit
22154b53a6
11 files changed
+284
-78
No files matched your search
@@ -124,3 +124,59 @@ fn real_pdf_link_fragments_and_named_destination_match_pdftex() {
|
||||
assert_eq!(describe(&compile(&root, source, true)), expected);
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_structure_action_references_the_shipped_structure_and_later_page() {
|
||||
let root = std::env::temp_dir().join(format!("texrra-pdf-structure-{}", std::process::id()));
|
||||
let source = r"\catcode123=1 \catcode125=2
|
||||
\def\space{ }
|
||||
\pdfoutput=1 \pdfmajorversion=2 \pdfminorversion=0
|
||||
\pdfcompresslevel=0 \pdfobjcompresslevel=0
|
||||
\pdfobj reserveobjnum \count10=\pdflastobj
|
||||
\pdfobj reserveobjnum \count11=\pdflastobj
|
||||
\edef\ROOT{\number\count10} \edef\CHILD{\number\count11}
|
||||
\immediate\pdfobj useobjnum\count11{<< /Type /StructElem /S /Sect /P \ROOT\space 0 R >>}
|
||||
\immediate\pdfobj useobjnum\count10{<< /Type /StructTreeRoot /K [\CHILD\space 0 R] >>}
|
||||
\pdfcatalog{/StructTreeRoot \ROOT\space 0 R} openaction goto struct name{anchor} page 2 {/Fit}
|
||||
\shipout\hbox{\pdfstartlink goto struct name{anchor} name{anchor}
|
||||
\vrule width10pt height6pt \pdfendlink}
|
||||
\shipout\hbox{\pdfdest name{anchor} xyz
|
||||
\pdfdest struct \count11 name{anchor} fit \vrule width10pt height6pt}
|
||||
\end";
|
||||
let doc = compile(&root, source, true);
|
||||
let catalog = doc.catalog().unwrap();
|
||||
let pages = doc.get_pages();
|
||||
let page = doc.get_object(pages[&1]).unwrap().as_dict().unwrap();
|
||||
let annotations = resolve(&doc, page.get(b"Annots").unwrap())
|
||||
.as_array()
|
||||
.unwrap();
|
||||
let link = resolve(&doc, &annotations[0]).as_dict().unwrap();
|
||||
let action = resolve(&doc, link.get(b"A").unwrap()).as_dict().unwrap();
|
||||
let opener = resolve(&doc, catalog.get(b"OpenAction").unwrap())
|
||||
.as_dict()
|
||||
.unwrap();
|
||||
let page_destination = opener.get(b"D").unwrap().as_array().unwrap();
|
||||
assert_eq!(page_destination[0].as_reference().unwrap(), pages[&2]);
|
||||
|
||||
let structure_destination = opener.get(b"SD").unwrap();
|
||||
assert_eq!(
|
||||
action.get(b"SD").unwrap().as_reference().unwrap(),
|
||||
structure_destination.as_reference().unwrap()
|
||||
);
|
||||
let destination = resolve(&doc, structure_destination).as_array().unwrap();
|
||||
let structure = resolve(&doc, &destination[0]).as_dict().unwrap();
|
||||
assert_eq!(
|
||||
structure.get(b"Type").unwrap().as_name().unwrap(),
|
||||
b"StructElem"
|
||||
);
|
||||
assert_eq!(
|
||||
structure.get(b"P").unwrap().as_reference().unwrap(),
|
||||
catalog
|
||||
.get(b"StructTreeRoot")
|
||||
.unwrap()
|
||||
.as_reference()
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(destination[1].as_name().unwrap(), b"Fit");
|
||||
fs::remove_dir_all(root).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user