Discard duplicate destinations during native PDF execution

This commit is contained in:
gloamxun committed 2026-11-28 14:45:52 +08:00
1 parent ba548ef05d
commit 0e71c15b01
9 files changed
+152 -7

No files matched your search

@@ -662,3 +662,38 @@ fn outline_and_open_action_share_a_missing_numeric_destination() {
}
assert_eq!(messages.iter().filter(|text| text.contains("num23")).count(), 1);
}
#[test]
fn duplicate_destinations_are_discarded_after_the_first_definition() {
use texrra_tex_core::execution::Event;
let source = format!(
r"{SETUP}
\setbox0=\hbox{{\kern5pt\pdfdest name{{same}} xyz\kern3pt\pdfdest name{{same}} fit}}
\setbox1=\hbox{{\kern3pt\pdfdest num7 xyz\kern4pt\pdfdest num7 fith}}
\shipout\vbox{{\box0\box1}}
\setbox0=\hbox{{\kern1pt\pdfdest name{{same}} fit
\ifnum\lastnodetype=12 \else\errmessage{{duplicate named node retained}}\fi}}
{{\pdfsuppresswarningdupdest=1
\setbox1=\hbox{{\kern1pt\pdfdest num7 fit
\ifnum\lastnodetype=12 \else\errmessage{{duplicate numbered node retained}}\fi}}}}
\shipout\hbox{{\pdfdest name{{new}} fit\pdfdest name{{new}} xyz}}
\end"
);
let execution = run_native(&source).unwrap();
let warnings = execution.events.iter().filter_map(|event| match event {
Event::Message { text, .. } if text.contains("duplicate ignored") => Some(text.as_str()),
_ => None,
}).collect::<Vec<_>>();
assert_eq!(
warnings,
["name{same}", "num7", "name{same}", "name{new}"].map(|id| format!(
"pdfTeX warning (ext4): destination with the same identifier ({id}) has been already used, duplicate ignored"
))
);
let pages = execution.shipout_display_lists().unwrap();
assert_eq!(pages[0].pdf_links.destinations.len(), 2);
assert_eq!(pages[1].pdf_links.destinations.len(), 1);
assert!(export_native(&execution).diagnostics.is_empty());
}