Resolve XDV named destinations at PDF shipout

This commit is contained in:
gloamxun committed 2026-11-25 19:47:17 +08:00
1 parent dd695a8945
commit cc147e93d8
12 files changed
+456 -9

No files matched your search

@@ -492,3 +492,59 @@ fn xdv_docinfo_merges_shipped_dictionaries_into_pdf_info() {
}
assert!(output.diagnostics.iter().any(|text| text.contains("Author")));
}
#[test]
fn xdv_destinations_use_shipped_page_ids_and_pdf_string_keys() {
use lopdf::Document;
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
\setbox0=\hbox{\special{pdf:dest (discarded) [@thispage /Fit]}}
\shipout\hbox{\special{dvipdfmx:config C 0x0010}
\special{pdf:minorversion=7}
\special{pdf:dest (A) [@nextpage/Fit]}
\special{pdf:dest <4100> [@thispage/FitB]}
\special{pdf:dest (AB) [@thispage /XYZ null 17.125 1.5]}
\vrule width5pt height3pt depth0pt}
\shipout\hbox{\special{pdf:minorversion 4}
\special{pdf:destination (A) [@prevpage /Fit]}
\vrule width5pt height3pt depth0pt}
\end",
),
&mut TestDevice,
)
.unwrap();
let pages: Vec<_> = result
.events
.iter()
.filter_map(|event| match event {
Event::Shipout(page) => Some(page.display_list().unwrap()),
_ => None,
})
.collect();
let output =
shipout_lists_to_native_pdf_document(&pages, result.state.pdf_final_options()).unwrap();
let pdf = Document::load_mem(&output.bytes).unwrap();
assert_eq!(pdf.version, "1.7");
let names = pdf.catalog().unwrap().get(b"Names").unwrap().as_dict().unwrap();
let id = names.get(b"Dests").unwrap().as_reference().unwrap();
let destinations = pdf.get_object(id).unwrap().as_dict().unwrap()
.get(b"Names").unwrap().as_array().unwrap();
let keys: Vec<_> = destinations.iter().step_by(2).map(|item| item.as_str().unwrap()).collect();
assert_eq!(keys, [b"A".as_slice(), b"A\0", b"AB"]);
let page_ids = pdf.get_pages();
assert_eq!(destinations[1].as_array().unwrap()[0].as_reference().unwrap(), page_ids[&2]);
assert_eq!(destinations[3].as_array().unwrap()[0].as_reference().unwrap(), page_ids[&1]);
let xyz = destinations[5].as_array().unwrap();
assert!(xyz[2].is_null());
assert_eq!(xyz[3].as_f64().unwrap(), 17.125);
assert_eq!(xyz[4].as_f64().unwrap(), 1.5);
assert!(output.diagnostics.iter().any(|text| text.contains("Object @A already defined")));
}