Handle legacy XeTeX paper and landscape specials
This commit is contained in:
1 parent
d944552188
commit
7ff988031f
5 files changed
+274
-55
No files matched your search
@@ -415,17 +415,8 @@ impl Executor {
|
||||
let mut pdf_objects = Vec::new();
|
||||
let mut xdv_annotations = std::collections::BTreeMap::new();
|
||||
let mut reopened_images = false;
|
||||
let mut xdv_paper = self.state.xdv_setup.paper;
|
||||
if xdv {
|
||||
// XeTeX emits an implicit pagesize at the start of every page.
|
||||
if requested_page_width > 0 && requested_page_height > 0 {
|
||||
xdv_paper.size = [Some(requested_page_width), Some(requested_page_height)];
|
||||
} else {
|
||||
xdv_paper.offset = [None; 2];
|
||||
}
|
||||
}
|
||||
let mut xdv_paper_specials = Vec::new();
|
||||
let mut xdv_navigation = Vec::new();
|
||||
let first_page = self.shipped_pages == 0;
|
||||
for (index, output) in outputs.into_iter().enumerate() {
|
||||
while font_uses.peek().is_some_and(|usage| usage.before_output == index) {
|
||||
self.current = current;
|
||||
@@ -486,14 +477,8 @@ impl Executor {
|
||||
} else if xdv && crate::pdf_device::xdv_annotation::Command::recognize(&special.bytes).is_some() {
|
||||
xdv_annotations.insert(graphics_step, shipout.specials.len());
|
||||
None
|
||||
} else if xdv && let Some(operands) = super::specials::xdv_pagesize_operand(&special.bytes) {
|
||||
if let Err(message) = xdv_paper.read(
|
||||
operands, magnification, (!first_page).then_some(self.state.xdv_setup.paper.size),
|
||||
) {
|
||||
files.observe_diagnostic(
|
||||
WriteDestination::TerminalAndLog, &format!("xdvipdfmx: warning: {message}\n"),
|
||||
).map_err(|error| self.error(error, special.span))?;
|
||||
}
|
||||
} else if xdv && crate::pdf_device::xdv_paper::Special::parse(&special.bytes).is_some() {
|
||||
xdv_paper_specials.push(shipout.specials.len());
|
||||
None
|
||||
} else if xdv && super::specials::xdv_navigation_operand(&special.bytes).is_some() {
|
||||
let point = xdv_transform.point(
|
||||
@@ -673,11 +658,14 @@ impl Executor {
|
||||
if xdv {
|
||||
// Page setup applies to the entire page, including graphics and
|
||||
// destination specials emitted before the paper special.
|
||||
let setup = &mut self.state.xdv_setup.paper;
|
||||
if first_page {
|
||||
setup.size = xdv_paper.size;
|
||||
}
|
||||
setup.offset = xdv_paper.offset;
|
||||
let xdv_paper = self.ship_xdv_paper(
|
||||
&shipout.specials,
|
||||
&xdv_paper_specials,
|
||||
[requested_page_width, requested_page_height],
|
||||
[default_canvas(612), default_canvas(792)],
|
||||
magnification,
|
||||
files,
|
||||
)?;
|
||||
let device = &mut shipout.device;
|
||||
if let Some(width) = xdv_paper.size[0] {
|
||||
device.page_width = width;
|
||||
@@ -724,6 +712,49 @@ impl Executor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ship_xdv_paper(
|
||||
&mut self,
|
||||
specials: &[ShipoutSpecial],
|
||||
indices: &[usize],
|
||||
requested: [i64; 2],
|
||||
fallback: [i64; 2],
|
||||
magnification: i32,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<crate::pdf_device::xdv_paper::Paper, Error> {
|
||||
use crate::pdf_device::xdv_paper::Special;
|
||||
let mut document = self.state.xdv_setup.paper;
|
||||
// The driver's initial scan also buffers the first page for output.
|
||||
// Its orientation establishes the global paper before later pages.
|
||||
let first_page = self.shipped_pages == 0;
|
||||
if first_page {
|
||||
document.size = fallback.map(Some);
|
||||
}
|
||||
let mut page = document;
|
||||
page.start_page(requested);
|
||||
for &index in indices {
|
||||
let special = &specials[index];
|
||||
let command = Special::parse(&special.bytes).expect("recognized paper special");
|
||||
let global = (!first_page).then_some(&mut document);
|
||||
if let Err(message) = page.read(command, magnification, global) {
|
||||
files.observe_diagnostic(
|
||||
WriteDestination::TerminalAndLog, &format!("xdvipdfmx: warning: {message}\n"),
|
||||
).map_err(|error| self.error(error, special.span))?;
|
||||
}
|
||||
}
|
||||
if first_page {
|
||||
if page.landscape {
|
||||
page.size.swap(0, 1);
|
||||
}
|
||||
document = page;
|
||||
} else if page.landscape != document.landscape {
|
||||
page.size.swap(0, 1);
|
||||
document.landscape = page.landscape;
|
||||
}
|
||||
document.offset = page.offset;
|
||||
self.state.xdv_setup.paper = document;
|
||||
Ok(page)
|
||||
}
|
||||
|
||||
fn pdf_space_settings(
|
||||
&mut self,
|
||||
automatic_at_start: bool,
|
||||
|
||||
Reference in new issue
Block a user