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
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user