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
@@ -292,7 +292,8 @@ impl Executor {
|
||||
origin(i64::from(self.read_parameter(Parameter::Pdfhorigin).width())) + h_offset;
|
||||
let vertical_origin =
|
||||
origin(i64::from(self.read_parameter(Parameter::Pdfvorigin).width())) + v_offset;
|
||||
let mut page_width = i64::from(self.read_parameter(Parameter::Pdfpagewidth).width());
|
||||
let requested_page_width = i64::from(self.read_parameter(Parameter::Pdfpagewidth).width());
|
||||
let mut page_width = requested_page_width;
|
||||
let requested_page_height = i64::from(self.read_parameter(Parameter::Pdfpageheight).width());
|
||||
let default_canvas = |bp: i64| origin(bp * 803 * 65536 / 800);
|
||||
if page_width == 0 {
|
||||
@@ -414,6 +415,17 @@ 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_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;
|
||||
@@ -458,10 +470,6 @@ impl Executor {
|
||||
let special = self.resolve_special(
|
||||
output, position.expect("special needs a shipout position"), files,
|
||||
)?;
|
||||
let point = xdv_transform.point(
|
||||
(special.position[0] + horizontal_origin) as f64,
|
||||
(special.position[1] + vertical_origin + b.height) as f64,
|
||||
).map(|coordinate| coordinate.round() as i64);
|
||||
let graphics_step = shipout.pdf_graphics_steps.len();
|
||||
let graphics = if let Some(pdf) = &device.pdf {
|
||||
if let Some(color) = xdv.then(|| self.xdv_colors.apply(&special.bytes)).flatten() {
|
||||
@@ -478,18 +486,23 @@ 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 && self.xdv_page_special(
|
||||
&special,
|
||||
crate::pdf_device::xdv_object::Position {
|
||||
page: self.shipped_pages + 1,
|
||||
coordinates: point,
|
||||
height: device.page_height,
|
||||
magnification: device.magnification,
|
||||
},
|
||||
graphics_step,
|
||||
&mut shipout.pdf_links,
|
||||
files,
|
||||
)? {
|
||||
} 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))?;
|
||||
}
|
||||
None
|
||||
} else if xdv && super::specials::xdv_navigation_operand(&special.bytes).is_some() {
|
||||
let point = xdv_transform.point(
|
||||
(special.position[0] + horizontal_origin) as f64,
|
||||
(special.position[1] + vertical_origin + b.height) as f64,
|
||||
).map(|coordinate| coordinate.round() as i64);
|
||||
xdv_navigation.push((shipout.specials.len(), graphics_step, point));
|
||||
None
|
||||
} else if xdv && self.xdv_setup_special(&special)? {
|
||||
None
|
||||
} else if xdv && let Some(image) = crate::pdf_device::xdv_image::ImageSpecial::parse(
|
||||
&special.bytes, device.magnification,
|
||||
@@ -657,6 +670,41 @@ impl Executor {
|
||||
if reopened_images {
|
||||
self.rebind_shipped_format_images(&mut shipout.box_node)?;
|
||||
}
|
||||
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 device = &mut shipout.device;
|
||||
if let Some(width) = xdv_paper.size[0] {
|
||||
device.page_width = width;
|
||||
}
|
||||
if let Some(height) = xdv_paper.size[1] {
|
||||
device.page_height = height;
|
||||
}
|
||||
if let Some(offset) = xdv_paper.offset[0] {
|
||||
device.horizontal_origin = offset + h_offset;
|
||||
}
|
||||
if let Some(offset) = xdv_paper.offset[1] {
|
||||
device.vertical_origin = offset + v_offset;
|
||||
}
|
||||
let delta = [device.horizontal_origin - horizontal_origin, device.vertical_origin - vertical_origin];
|
||||
for (index, graphics_step, [x, y]) in xdv_navigation {
|
||||
self.ship_xdv_navigation(
|
||||
&shipout.specials[index],
|
||||
crate::pdf_device::xdv_object::Position {
|
||||
page: self.shipped_pages + 1,
|
||||
coordinates: [x + delta[0], y + delta[1]],
|
||||
height: device.page_height,
|
||||
magnification,
|
||||
},
|
||||
graphics_step, &mut shipout.pdf_links, files,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
if xdv && (!xdv_annotations.is_empty() || self.xdv_annotations.is_active()) {
|
||||
shipout.pdf_links.xdv_annotations = self.ship_xdv_annotations(&shipout, &xdv_annotations, files)?;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user