Resolve native PDF structure destinations and local actions
This commit is contained in:
1 parent
58bcfca7b7
commit
22154b53a6
11 files changed
+284
-78
No files matched your search
@@ -900,7 +900,12 @@ impl NativeBox {
|
||||
budget.leader_depth += 1;
|
||||
let result = self.walk_at(x, y, level, links, budget, &mut |x, y, paint| {
|
||||
if !matches!(paint, BoxPaint::Output(o) if matches!(o.operation,
|
||||
OutputOperation::Open { .. } | OutputOperation::Write { .. } | OutputOperation::Close { .. })) {
|
||||
OutputOperation::Open { .. } | OutputOperation::Write { .. } | OutputOperation::Close { .. }))
|
||||
&& !matches!(paint, BoxPaint::PdfLink(node, _) if matches!(
|
||||
node.operation,
|
||||
OutputOperation::PdfLink(crate::pdf_device::links::LinkNode::Destination { .. })
|
||||
))
|
||||
{
|
||||
emit(x, y, paint);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -618,6 +618,9 @@ impl Printer<'_> {
|
||||
LinkNode::Running(true) => "pdfrunninglinkon",
|
||||
LinkNode::Destination { .. } => "pdfdest",
|
||||
});
|
||||
if let LinkNode::Destination { structure: Some(object), .. } = node {
|
||||
self.literal(&format!(" struct{object}"));
|
||||
}
|
||||
}
|
||||
OutputOperation::PdfLiteral { mode, shipout, tokens } => {
|
||||
use crate::pdf_device::PdfLiteralMode;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use crate::pdf_device::{
|
||||
catalog::{CatalogAction, CatalogTarget, PdfOutline},
|
||||
catalog::{CatalogAction, CatalogTarget, PdfOutline, StructureTarget},
|
||||
links::DestinationId,
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_catalog_action(
|
||||
pub(super) fn scan_catalog_action(
|
||||
&mut self,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<CatalogAction, Error> {
|
||||
@@ -95,10 +95,21 @@ impl Executor {
|
||||
None
|
||||
};
|
||||
let structure = if self.keyword("struct", files)? {
|
||||
if !goto || file.is_none() {
|
||||
return self.fail("current PDF structure actions require a remote GoTo");
|
||||
if !goto {
|
||||
return self.fail("only PDF GoTo actions can target a structure");
|
||||
}
|
||||
Some(self.scan_pdf_bytes(files)?)
|
||||
Some(if file.is_some() {
|
||||
StructureTarget::Remote(self.scan_pdf_bytes(files)?)
|
||||
} else if self.keyword("name", files)? {
|
||||
let name = self.scan_pdf_tokens(files)?;
|
||||
StructureTarget::Local(DestinationId::Name(self.token_list_text(&name)))
|
||||
} else if self.keyword("num", files)? {
|
||||
StructureTarget::Local(DestinationId::Number(
|
||||
self.positive_pdf_number("structure destination number", files)?,
|
||||
))
|
||||
} else {
|
||||
return self.fail("PDF structure destination identifier type missing");
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@@ -150,10 +150,8 @@ impl Executor {
|
||||
};
|
||||
let action = if self.keyword("user", files)? {
|
||||
LinkAction::User(self.scan_pdf_tokens(files)?)
|
||||
} else if self.keyword("goto", files)? && self.keyword("name", files)? {
|
||||
LinkAction::GotoName(self.scan_pdf_tokens(files)?)
|
||||
} else {
|
||||
return self.fail("expected a user or named goto PDF link action");
|
||||
LinkAction::Catalog(self.scan_catalog_action(files)?)
|
||||
};
|
||||
self.state
|
||||
.pdf_objects
|
||||
@@ -174,6 +172,11 @@ impl Executor {
|
||||
LinkNode::Running(command == Primitive::Pdfrunninglinkon)
|
||||
}
|
||||
Primitive::Pdfdest => {
|
||||
let structure = if self.keyword("struct", files)? {
|
||||
Some(self.positive_pdf_number("structure object number", files)? as u32)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let destination = if self.keyword("name", files)? {
|
||||
DestinationId::Name(self.scan_pdf_tokens(files)?)
|
||||
} else if self.keyword("num", files)? {
|
||||
@@ -205,7 +208,7 @@ impl Executor {
|
||||
}
|
||||
view.ok_or_else(|| self.error("expected PDF destination view", span))?
|
||||
};
|
||||
LinkNode::Destination { destination, view }
|
||||
LinkNode::Destination { destination, view, structure }
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
@@ -274,6 +277,7 @@ impl Executor {
|
||||
let action = match &layout.action {
|
||||
LinkAction::User(tokens) => AnnotationAction::User(self.token_list_text(tokens)),
|
||||
LinkAction::GotoName(tokens) => AnnotationAction::GotoName(self.token_list_text(tokens)),
|
||||
LinkAction::Catalog(action) => AnnotationAction::Catalog(action.clone()),
|
||||
};
|
||||
let mut start = ActiveLink { layout: layout.clone(), attributes,
|
||||
action, level: row.level, segment: None };
|
||||
@@ -299,13 +303,14 @@ impl Executor {
|
||||
link.end_segment(&mut output, x, margin);
|
||||
}
|
||||
LinkNode::Running(enabled) => self.pdf_running_links = *enabled,
|
||||
LinkNode::Destination { destination, view } => {
|
||||
LinkNode::Destination { destination, view, structure } => {
|
||||
let destination = match destination {
|
||||
DestinationId::Name(tokens) => DestinationId::Name(self.token_list_text(tokens)),
|
||||
DestinationId::Number(number) => DestinationId::Number(*number),
|
||||
};
|
||||
output.destinations.push(PageDestination {
|
||||
destination, point: map_point(transform.0, x, y), view: *view,
|
||||
structure: *structure,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 45;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 14] = [27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, SCHEMA];
|
||||
const SCHEMA: u32 = 46;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 15] = [
|
||||
27, 28, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 44, 45, SCHEMA,
|
||||
];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
|
||||
Reference in new issue
Block a user