Bind native last-link numbers to shipped PDF annotations

This commit is contained in:
gloamxun committed 2026-11-21 02:31:43 +08:00
1 parent 7f74251c8a
commit 60d7411dfe
12 files changed
+227 -19

No files matched your search

@@ -76,6 +76,7 @@ impl ActiveLink {
transformed: transform.1,
});
output.annotations.push(LinkAnnotation {
object_number: None,
rect: link_rect(rect, transform.0, margin),
attributes: self.attributes.clone(),
action: self.action.clone(),
@@ -119,6 +120,13 @@ impl Executor {
}
let operation = match command {
Primitive::Pdfstartlink => {
self.reads.insert(Dependency::PdfObjects);
let object_number = self
.state
.pdf_objects
.get_or_insert_with(Default::default)
.reserve_link(self.limits.tokens)
.map_err(|error| self.error(error, self.current))?;
let (mut width, mut height, mut depth) = (None, None, None);
loop {
let target = if self.keyword("width", files)? {
@@ -144,7 +152,13 @@ impl Executor {
} else {
return self.fail("expected a user or named goto PDF link action");
};
self.state
.pdf_objects
.as_mut()
.expect("allocated PDF link object")
.record_last_link(object_number);
LinkNode::Start(LinkStart {
object_number: Some(object_number),
width,
height,
depth,
@@ -258,6 +272,9 @@ impl Executor {
let mut start = ActiveLink { layout: layout.clone(), attributes,
action, level: row.level, segment: None };
start.start_segment(&mut output, row, [x, y], transform, margin);
// The scan-time object number belongs only to the
// initial annotation, never to a continuation row.
output.annotations.last_mut().unwrap().object_number = layout.object_number;
active.push(start);
}
LinkNode::End => {
@@ -209,6 +209,7 @@ impl Executor {
| Primitive::Inputlineno
| Primitive::Pdfrandomseed
| Primitive::Pdflastobj
| Primitive::Pdflastlink
| Primitive::Pdflastximage
| Primitive::Pdflastximagepages
| Primitive::Pdflastximagecolordepth