Ship XDV annotations from measured page ranges

This commit is contained in:
gloamxun committed 2026-11-25 21:12:44 +08:00
1 parent 515dbe6181
commit 20986b2fd5
16 files changed
+873 -54

No files matched your search

@@ -660,3 +660,62 @@ fn xdv_catalog_and_outlines_resolve_live_pages_and_retain_referenced_names() {
assert_eq!(remapped.as_str().unwrap(), names[0].as_str().unwrap());
assert_eq!(names[1].as_array().unwrap()[0].as_reference().unwrap(), page_ids[&2]);
}
#[test]
fn xdv_root_annotation_keeps_its_extent_and_destination_across_shipouts() {
use lopdf::{Document, Object};
use texrra_tex_core::pdf::shipout_lists_to_native_pdf_document;
let state = State::initex().with_etex().with_input_profile(InputProfile::XeTeX);
let result = Executor::new(state, Limits::default())
.with_native_pages()
.run(
source(
r"\catcode123=1 \catcode125=2
\shipout\hbox{\special{pdf:bann<</Subtype/Link/Dest(topic)>>}
\special{pdf:xann width 10pt height 7pt depth 1pt}
\vrule width30pt height12pt depth0pt}
\shipout\hbox{\kern20pt
\special{pdf:extendann width 11pt height 8pt depth 2pt}
\special{pdf:eann}
\special{pdf:outline 1<</Title (Chapter)/Dest(chapter)>>}
\special{pdf:dest (topic) [@thispage/Fit]}
\special{pdf:dest (chapter) [@prevpage/Fit]}
\vrule width10pt height8pt depth0pt}
\end",
),
&mut TestDevice,
)
.unwrap();
let pages = result.shipout_display_lists().unwrap();
let output =
shipout_lists_to_native_pdf_document(&pages, result.state.pdf_final_options()).unwrap();
let pdf = Document::load_mem(&output.bytes).unwrap();
let page_ids = pdf.get_pages();
let first = pdf.get_object(page_ids[&1]).unwrap().as_dict().unwrap();
assert!(!first.has(b"Annots"));
let second = pdf.get_object(page_ids[&2]).unwrap().as_dict().unwrap();
let annotations = second.get(b"Annots").unwrap().as_array().unwrap();
assert_eq!(annotations.len(), 1);
let annotation = pdf
.get_object(annotations[0].as_reference().unwrap())
.unwrap()
.as_dict()
.unwrap();
assert_eq!(annotation.get(b"Dest").unwrap().as_str().unwrap(), b"0");
let rectangle = annotation.get(b"Rect").unwrap().as_array().unwrap();
let coordinate = |index| match &rectangle[index] {
Object::Integer(value) => *value as f64,
Object::Real(value) => *value,
_ => panic!("expected physical annotation coordinate"),
};
assert_eq!(coordinate(0), 72.0);
assert_eq!(coordinate(2), 102.884);
let names = pdf.catalog().unwrap().get(b"Names").unwrap().as_dict().unwrap();
let names = pdf.get_object(names.get(b"Dests").unwrap().as_reference().unwrap())
.unwrap().as_dict().unwrap().get(b"Names").unwrap().as_array().unwrap();
assert_eq!(names[0].as_str().unwrap(), b"0");
assert_eq!(names[1].as_array().unwrap()[0].as_reference().unwrap(), page_ids[&2]);
assert_eq!(names[2].as_str().unwrap(), b"1");
assert_eq!(names[3].as_array().unwrap()[0].as_reference().unwrap(), page_ids[&1]);
}