Build native PDF article threads and bead rings

This commit is contained in:
gloamxun committed 2026-11-28 16:03:37 +08:00
1 parent de4bd1fa76
commit 4fb0f2c89b
15 files changed
+528 -28

No files matched your search

@@ -289,13 +289,15 @@ impl Executor {
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()),
AnnotationAction::Catalog(action @ (CatalogAction::GoTo { file: None, .. }
| CatalogAction::Thread { 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();
let beads: Vec<_> = shipout.pdf_links.thread_beads.iter().map(|bead| bead.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();
@@ -311,6 +313,13 @@ impl Executor {
for number in destinations {
self.pack_pdf_object(number)?;
}
for bead in beads {
self.reads.insert(Dependency::PdfObjects);
let rectangle = self.state.pdf_objects.as_deref_mut().expect("registered thread bead")
.new_bead_rectangle(bead, self.limits.tokens)
.map_err(|error| self.error(error, self.current))?;
self.pack_pdf_object(rectangle)?;
}
self.pack_pdf_object(resources)?;
}
self.statistics_after_shipout(before, files)?;
@@ -491,10 +500,17 @@ impl Executor {
let output_count = outputs.len();
let has_link_material = !self.pdf_link_stack.is_empty() || outputs.iter().any(|node| node.is_pdf_link());
let mut pdf_link_shipout = (!for_form && device.pdf.is_some()
&& (has_link_material || outputs.iter().any(|node| {
&& (has_link_material || self.pdf_active_thread.is_some() || outputs.iter().any(|node| {
matches!(node.operation, OutputOperation::PdfSetMatrix(_))
})))
.then(|| self.begin_pdf_link_shipout(b, device));
.then(|| {
let thread_rows = self.pdf_active_thread.is_some() || outputs.iter().any(|node| {
matches!(node.operation, OutputOperation::PdfLink(
crate::pdf_device::links::LinkNode::Thread { running: true, .. }
))
});
self.begin_pdf_link_shipout(b, device, thread_rows)
});
let mut output_positions = if let Some(effects) = &leader_effects {
effects.output_positions.clone().into_iter()
} else if outputs.iter().any(|node| node.needs_shipout_position()) {
@@ -749,6 +765,13 @@ impl Executor {
{
return Err(self.error("annotations cannot be inside an XForm", node.span));
}
if let Some(node) = first
&& matches!(node.operation, OutputOperation::PdfLink(
crate::pdf_device::links::LinkNode::Thread { .. }
))
{
return Err(self.error("threads cannot be inside an XForm", node.span));
}
return self.fail("PDF page links and destinations require a page shipout");
}
for usage in font_uses {