Capture and reuse XeLaTeX PDF form contents

This commit is contained in:
gloamxun committed 2026-11-28 19:29:07 +08:00
1 parent 009fde04f7
commit c0e2346b05
16 files changed
+706 -53

No files matched your search

@@ -56,8 +56,9 @@ impl Executor {
position: crate::pdf_device::xdv_object::Position,
graphics_step: usize,
links: &mut crate::pdf_device::links::PageLinks,
origin: Option<TokenOrigin>,
files: &mut impl SourceProvider,
) -> Result<(), Error> {
) -> Result<Option<PdfGraphics>, Error> {
let Some((kind, operands)) = xdv_navigation_operand(&special.bytes) else {
return self.fail("missing shipped XDV navigation operands");
};
@@ -66,10 +67,18 @@ impl Executor {
operands, position.page, position.coordinates,
).map_err(|error| self.error(error, special.span))?;
links.xdv_destinations.push(destination);
return Ok(());
return Ok(None);
}
self.reads.insert(Dependency::PdfCatalogState);
let warnings = if matches!(kind, b"docview" | b"outline" | b"pageresources") {
let mut graphics = None;
let warnings = if matches!(kind, b"bxobj" | b"exobj" | b"uxobj") {
let source = origin.unwrap_or(TokenOrigin { span: special.span, invocation: None });
let navigation = Arc::make_mut(self.state.xdv_navigation.get_or_insert_with(Default::default));
let (operation, warnings) = navigation.form_special(kind, operands, position, source, self.limits.tokens)
.map_err(|error| self.error(error, special.span))?;
graphics = Some(operation);
Ok(warnings)
} else if matches!(kind, b"docview" | b"outline" | b"pageresources") {
let navigation = Arc::make_mut(self.state.xdv_navigation.get_or_insert_with(Default::default));
if kind == b"docview" {
navigation.merge_catalog(operands, position, self.limits.tokens)
@@ -100,7 +109,7 @@ impl Executor {
files.observe_diagnostic(WriteDestination::TerminalAndLog, &warning)
.map_err(|error| self.error(error, special.span))?;
}
Ok(())
Ok(graphics)
}
pub(super) fn xdv_setup_special(
@@ -357,6 +366,9 @@ pub(super) fn xdv_navigation_operand(data: &[u8]) -> Option<(&'static [u8], &[u8
(b"docview", b"docview"), (b"outline", b"outline"), (b"out", b"outline"),
(b"obj", b"obj"), (b"object", b"obj"), (b"put", b"put"), (b"close", b"close"),
(b"stream", b"stream"), (b"fstream", b"fstream"), (b"pageresources", b"pageresources"),
(b"bxobj", b"bxobj"), (b"bform", b"bxobj"), (b"beginxobj", b"bxobj"),
(b"exobj", b"exobj"), (b"eform", b"exobj"), (b"endxobj", b"exobj"),
(b"uxobj", b"uxobj"), (b"usexobj", b"uxobj"),
] {
if let Some(operands) = xdv_operand(body, name) {
return Some((kind, operands));