Honor XeTeX page setup during native shipout
This commit is contained in:
1 parent
9da2ee41cd
commit
d944552188
7 files changed
+281
-42
No files matched your search
@@ -49,23 +49,44 @@ impl Executor {
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn xdv_page_special(
|
||||
pub(super) fn ship_xdv_navigation(
|
||||
&mut self,
|
||||
special: &ShipoutSpecial,
|
||||
position: crate::pdf_device::xdv_object::Position,
|
||||
graphics_step: usize,
|
||||
links: &mut crate::pdf_device::links::PageLinks,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<(), Error> {
|
||||
let Some((kind, operands)) = xdv_navigation_operand(&special.bytes) else {
|
||||
return self.fail("missing shipped XDV navigation operands");
|
||||
};
|
||||
if kind == b"dest" {
|
||||
let destination = crate::pdf_device::xdv_destination::Destination::parse(
|
||||
operands, position.page, position.coordinates,
|
||||
).map_err(|error| self.error(error, special.span))?;
|
||||
links.xdv_destinations.push(destination);
|
||||
return Ok(());
|
||||
}
|
||||
self.reads.insert(Dependency::PdfCatalogState);
|
||||
let navigation = Arc::make_mut(self.state.xdv_navigation.get_or_insert_with(Default::default));
|
||||
let warnings = if kind == b"docview" {
|
||||
navigation.merge_catalog(operands, position, self.limits.tokens)
|
||||
} else {
|
||||
navigation.add_outline(operands, position, (position.page, graphics_step, 1), self.limits.tokens)
|
||||
}.map_err(|error| self.error(error, special.span))?;
|
||||
for warning in warnings {
|
||||
files.observe_diagnostic(WriteDestination::TerminalAndLog, &warning)
|
||||
.map_err(|error| self.error(error, special.span))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn xdv_setup_special(
|
||||
&mut self,
|
||||
special: &ShipoutSpecial,
|
||||
) -> Result<bool, Error> {
|
||||
use crate::pdf_device::xdv_destination::Destination;
|
||||
let data = special.bytes.trim_ascii_start();
|
||||
if let Some(body) = data.strip_prefix(b"pdf:").map(<[u8]>::trim_ascii_start) {
|
||||
if let Some(operands) = xdv_operand(body, b"dest").or_else(|| xdv_operand(body, b"destination")) {
|
||||
let destination = Destination::parse(operands, position.page, position.coordinates)
|
||||
.map_err(|error| self.error(error, special.span))?;
|
||||
links.xdv_destinations.push(destination);
|
||||
return Ok(true);
|
||||
}
|
||||
if let Some(body) = xdv_pdf_body(data) {
|
||||
for (name, major) in [(b"majorversion".as_slice(), true), (b"minorversion", false)] {
|
||||
if let Some(operands) = xdv_operand(body, name) {
|
||||
if self.shipped_pages == 0 {
|
||||
@@ -75,22 +96,6 @@ impl Executor {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
let catalog = xdv_operand(body, b"docview");
|
||||
let outline = xdv_operand(body, b"outline").or_else(|| xdv_operand(body, b"out"));
|
||||
if let Some(operands) = catalog.or(outline) {
|
||||
self.reads.insert(Dependency::PdfCatalogState);
|
||||
let navigation = Arc::make_mut(self.state.xdv_navigation.get_or_insert_with(Default::default));
|
||||
let warnings = if catalog.is_some() {
|
||||
navigation.merge_catalog(operands, position, self.limits.tokens)
|
||||
} else {
|
||||
navigation.add_outline(operands, position, (position.page, graphics_step, 1), self.limits.tokens)
|
||||
}.map_err(|error| self.error(error, special.span))?;
|
||||
for warning in warnings {
|
||||
files.observe_diagnostic(WriteDestination::TerminalAndLog, &warning)
|
||||
.map_err(|error| self.error(error, special.span))?;
|
||||
}
|
||||
return Ok(true);
|
||||
}
|
||||
} else if let Some(body) = data.strip_prefix(b"dvipdfmx:").map(<[u8]>::trim_ascii_start)
|
||||
&& let Some(operands) = xdv_operand(body, b"config")
|
||||
{
|
||||
@@ -204,6 +209,27 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
|
||||
fn xdv_pdf_body(data: &[u8]) -> Option<&[u8]> {
|
||||
data.trim_ascii_start().strip_prefix(b"pdf:").map(<[u8]>::trim_ascii_start)
|
||||
}
|
||||
|
||||
pub(super) fn xdv_pagesize_operand(data: &[u8]) -> Option<&[u8]> {
|
||||
xdv_operand(xdv_pdf_body(data)?, b"pagesize")
|
||||
}
|
||||
|
||||
pub(super) fn xdv_navigation_operand(data: &[u8]) -> Option<(&'static [u8], &[u8])> {
|
||||
let body = xdv_pdf_body(data)?;
|
||||
for (name, kind) in [
|
||||
(b"dest".as_slice(), b"dest".as_slice()), (b"destination", b"dest"),
|
||||
(b"docview", b"docview"), (b"outline", b"outline"), (b"out", b"outline"),
|
||||
] {
|
||||
if let Some(operands) = xdv_operand(body, name) {
|
||||
return Some((kind, operands));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn xdv_operand<'a>(data: &'a [u8], command: &[u8]) -> Option<&'a [u8]> {
|
||||
data.strip_prefix(command).filter(|rest| {
|
||||
!rest.first().is_some_and(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b':'))
|
||||
|
||||
Reference in new issue
Block a user