Register native PDF navigation and raw objects in write order

This commit is contained in:
gloamxun committed 2026-11-27 22:19:15 +08:00
1 parent 70ebacb056
commit e95d1264da
9 files changed
+350 -48

No files matched your search

@@ -269,12 +269,32 @@ impl Executor {
let before = self.statistics_before_shipout(&shipout.box_node, files)?;
self.shipped_pages += 1;
let page_resources = shipout.pdf_objects.map(|objects| objects.resources);
let links: Vec<_> = shipout.pdf_links.annotations.iter().filter_map(|annotation| {
use crate::pdf_device::{catalog::CatalogAction, links::AnnotationAction};
let number = annotation.object_number?;
let action = match &annotation.action {
AnnotationAction::Catalog(action @ CatalogAction::GoTo { file: None, .. }) => Some(action.clone()),
_ => None,
};
Some((number, action))
}).collect();
let destinations: Vec<_> = shipout.pdf_links.destinations.iter()
.filter_map(|destination| destination.object_number).collect();
self.events.push(Event::Shipout(Box::new(shipout)));
if probed_page && let Some(probe) = self.pdf_space_probe.as_mut() {
Arc::make_mut(probe).observed_events = self.events.len();
}
self.write_shipout_forms(forms, files)?;
if let Some(resources) = page_resources {
for (number, action) in links {
self.pack_pdf_object(number)?;
if let Some(action) = action {
self.write_pdf_link_action(&action)?;
}
}
for number in destinations {
self.pack_pdf_object(number)?;
}
self.pack_pdf_object(resources)?;
}
self.statistics_after_shipout(before, files)?;
@@ -435,6 +455,7 @@ impl Executor {
if let Some(effects) = &leader_effects {
outputs = effects.outputs.iter().collect();
}
let mut navigation_numbers = (Vec::new(), Vec::new());
let mut link_depth = self.pdf_link_stack.len();
let has_link_material = link_depth != 0 || outputs.iter().any(|node| node.is_pdf_link());
let mut output_positions = if let Some(effects) = &leader_effects {
@@ -655,11 +676,19 @@ impl Executor {
LinkNode::Start(_) if link_depth == 10 => {
return self.fail("PDF link stack capacity exceeded");
}
LinkNode::Start(_) => link_depth += 1,
LinkNode::Start(layout) => {
link_depth += 1;
if !unicode_pages && !for_form {
navigation_numbers.0.push(self.register_pdf_link(layout.object_number)?);
}
}
LinkNode::End if link_depth == 0 => {
return self.fail("\\pdfendlink used without \\pdfstartlink");
}
LinkNode::End => link_depth -= 1,
LinkNode::Destination { destination, structure, .. } if !unicode_pages && !for_form => {
navigation_numbers.1.push(self.register_pdf_destination(destination, structure.is_some())?);
}
LinkNode::Running(_) | LinkNode::Destination { .. } => {}
}
} else {
@@ -706,7 +735,7 @@ impl Executor {
return self.fail("PDF page links and destinations require a page shipout");
}
let mut links = self.ship_pdf_link_material(
b, device, &shipout.pdf_graphics_steps, files,
b, device, &shipout.pdf_graphics_steps, navigation_numbers, files,
)?;
links.xdv_destinations = std::mem::take(&mut shipout.pdf_links.xdv_destinations);
shipout.pdf_links = links;