Resolve XDV named destinations at PDF shipout
This commit is contained in:
1 parent
dd695a8945
commit
cc147e93d8
12 files changed
+456
-9
No files matched your search
@@ -354,6 +354,7 @@ impl Executor {
|
||||
let device = &shipout.device;
|
||||
let mut graphics_stack = Vec::new();
|
||||
let mut xdv_graphics_stack = Vec::new();
|
||||
let mut xdv_transform = crate::pdf_device::Affine::IDENTITY;
|
||||
let (mut outputs, has_leaders) = b.output_nodes();
|
||||
let leader_effects = if has_leaders {
|
||||
let limit = self
|
||||
@@ -437,8 +438,16 @@ 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 = if let Some(pdf) = &device.pdf {
|
||||
if pdf.driver == crate::pdf_device::PdfDriver::Xdv
|
||||
&& self.xdv_destination_special(&special, point, &mut shipout.pdf_links)?
|
||||
{
|
||||
None
|
||||
} else if pdf.driver == crate::pdf_device::PdfDriver::Xdv
|
||||
&& let Some(image) = crate::pdf_device::xdv_image::ImageSpecial::parse(
|
||||
&special.bytes, device.magnification,
|
||||
).map_err(|error| self.error(error, special.span))?
|
||||
@@ -461,11 +470,26 @@ impl Executor {
|
||||
};
|
||||
use crate::pdf_device::PdfGraphics;
|
||||
match &graphics {
|
||||
Some(PdfGraphics::Save | PdfGraphics::SaveMatrix(_)) => {
|
||||
xdv_graphics_stack.push(special.span);
|
||||
Some(PdfGraphics::Save) => {
|
||||
xdv_graphics_stack.push((special.span, xdv_transform));
|
||||
}
|
||||
Some(PdfGraphics::Restore { .. }) if xdv_graphics_stack.pop().is_none() => {
|
||||
return Err(self.error("unmatched XDV graphics restore", special.span));
|
||||
Some(operation @ (PdfGraphics::SaveMatrix(matrix) | PdfGraphics::Matrix(matrix))) => {
|
||||
if matches!(operation, PdfGraphics::SaveMatrix(_)) {
|
||||
xdv_graphics_stack.push((special.span, xdv_transform));
|
||||
}
|
||||
let [x, y] = special.position;
|
||||
let pivot = matrix.about(
|
||||
(x + horizontal_origin) as f64,
|
||||
(y + vertical_origin + b.height) as f64,
|
||||
true,
|
||||
);
|
||||
xdv_transform = xdv_transform.concatenate(pivot);
|
||||
}
|
||||
Some(PdfGraphics::Restore { .. }) => {
|
||||
let Some((_, previous)) = xdv_graphics_stack.pop() else {
|
||||
return Err(self.error("unmatched XDV graphics restore", special.span));
|
||||
};
|
||||
xdv_transform = previous;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -541,7 +565,7 @@ impl Executor {
|
||||
if output_positions.next().is_some() {
|
||||
return self.fail("unexpected positioned native output node");
|
||||
}
|
||||
if let Some(&span) = xdv_graphics_stack.last() {
|
||||
if let Some(&(span, _)) = xdv_graphics_stack.last() {
|
||||
return Err(self.error("unclosed XDV graphics save at page shipout", span));
|
||||
}
|
||||
if let Some((_, span)) = graphics_stack.last() {
|
||||
@@ -575,9 +599,16 @@ impl Executor {
|
||||
self.write_pdf_object(number, files)?;
|
||||
}
|
||||
if has_link_material {
|
||||
shipout.pdf_links = self.ship_pdf_link_material(
|
||||
let mut links = self.ship_pdf_link_material(
|
||||
b, device, &shipout.pdf_graphics_steps, files,
|
||||
)?;
|
||||
links.xdv_destinations = std::mem::take(&mut shipout.pdf_links.xdv_destinations);
|
||||
shipout.pdf_links = links;
|
||||
}
|
||||
if let Some(pdf) = &mut shipout.device.pdf
|
||||
&& pdf.driver == crate::pdf_device::PdfDriver::Xdv
|
||||
{
|
||||
self.state.xdv_setup.apply_version(&mut pdf.file);
|
||||
}
|
||||
self.current = current;
|
||||
self.native_page.as_mut().unwrap().dead_cycles = 0;
|
||||
|
||||
Reference in new issue
Block a user