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

@@ -2146,6 +2146,14 @@ impl Executor {
self.reads.insert(Dependency::PdfRandomState);
Ok(self.state.random_seed())
}
Meaning::Primitive(Primitive::Pdflastlink) => {
self.reads.insert(Dependency::PdfObjects);
Ok(self
.state
.pdf_objects
.as_deref()
.map_or(0, |objects| objects.last_link()))
}
Meaning::Primitive(Primitive::Pdflastobj) => {
self.reads.insert(Dependency::PdfObjects);
Ok(self.state.pdf_objects.as_deref().map_or(0, |objects| objects.last()))
@@ -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
@@ -8,8 +8,8 @@ use std::{
sync::{Arc, Mutex, OnceLock, Weak},
};
const SCHEMA: u32 = 39;
const COMPATIBLE_SCHEMAS: [u32; 11] = [27, 28, 31, 32, 33, 34, 35, 36, 37, 38, SCHEMA];
const SCHEMA: u32 = 40;
const COMPATIBLE_SCHEMAS: [u32; 12] = [27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, SCHEMA];
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
#[derive(serde::Serialize, serde::Deserialize)]
@@ -331,6 +331,7 @@ pub enum Primitive {
Pdfliteral,
Leftmarginkern,
Rightmarginkern,
Pdflastlink,
}
impl Primitive {
@@ -969,6 +970,7 @@ impl Default for State {
("pdfobj", Pdfobj),
("pdfrefobj", Pdfrefobj),
("pdflastobj", Pdflastobj),
("pdflastlink", Pdflastlink),
("pdfrandomseed", Pdfrandomseed),
("pdfsetrandomseed", Pdfsetrandomseed),
("pdfuniformdeviate", Pdfuniformdeviate),
@@ -1396,7 +1398,13 @@ impl State {
self.output_mode_set = None;
self.pdf_file_options = None;
self.pdf_catalog = None;
self.pdf_objects = None;
if !self
.pdf_objects
.as_deref_mut()
.is_some_and(crate::pdf_device::page_resources::PdfObjects::retain_format_links)
{
self.pdf_objects = None;
}
self.pdf_info.clear();
self
}