Apply XDV color state and page backgrounds at shipout
This commit is contained in:
1 parent
cc147e93d8
commit
8be7867b37
10 files changed
+590
-19
No files matched your search
@@ -323,7 +323,11 @@ impl Executor {
|
||||
} else {
|
||||
(Default::default(), Default::default())
|
||||
};
|
||||
let pdf_color_start = if device.pdf.is_some() {
|
||||
use crate::pdf_device::PdfDriver;
|
||||
let xdv = device.pdf.as_ref().is_some_and(|pdf| pdf.driver == PdfDriver::Xdv);
|
||||
let pdf_color_start = if xdv {
|
||||
self.xdv_colors.start_page().into_iter().collect()
|
||||
} else if device.pdf.is_some() {
|
||||
self.pdf_colors.start_page()
|
||||
} else {
|
||||
Vec::new()
|
||||
@@ -343,6 +347,8 @@ impl Executor {
|
||||
pdf_color_start,
|
||||
pdf_color_steps: Vec::new(),
|
||||
pdf_graphics_steps: Vec::new(),
|
||||
xdv_color_steps: Default::default(),
|
||||
pdf_background: None,
|
||||
pdf_special_images: Default::default(),
|
||||
specials: Vec::new(),
|
||||
pdf_text_spaces: None,
|
||||
@@ -442,13 +448,22 @@ impl Executor {
|
||||
(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 pdf.driver == crate::pdf_device::PdfDriver::Xdv
|
||||
&& self.xdv_destination_special(&special, point, &mut shipout.pdf_links)?
|
||||
{
|
||||
if let Some(color) = xdv.then(|| self.xdv_colors.apply(&special.bytes)).flatten() {
|
||||
let color = color.map_err(|error| self.error(error, special.span))?;
|
||||
if let Some(warning) = color.warning {
|
||||
files.observe_diagnostic(
|
||||
WriteDestination::TerminalAndLog, &format!("xdvipdfmx: warning: {warning}\n"),
|
||||
).map_err(|error| self.error(error, special.span))?;
|
||||
}
|
||||
if let Some(program) = color.program {
|
||||
shipout.xdv_color_steps.insert(graphics_step, program);
|
||||
}
|
||||
None
|
||||
} else if pdf.driver == crate::pdf_device::PdfDriver::Xdv
|
||||
&& let Some(image) = crate::pdf_device::xdv_image::ImageSpecial::parse(
|
||||
} else if xdv && self.xdv_destination_special(&special, point, &mut shipout.pdf_links)? {
|
||||
None
|
||||
} else if xdv && let Some(image) = crate::pdf_device::xdv_image::ImageSpecial::parse(
|
||||
&special.bytes, device.magnification,
|
||||
).map_err(|error| self.error(error, special.span))?
|
||||
{
|
||||
@@ -471,11 +486,11 @@ impl Executor {
|
||||
use crate::pdf_device::PdfGraphics;
|
||||
match &graphics {
|
||||
Some(PdfGraphics::Save) => {
|
||||
xdv_graphics_stack.push((special.span, xdv_transform));
|
||||
xdv_graphics_stack.push((special.span, xdv_transform, self.xdv_colors.current()));
|
||||
}
|
||||
Some(operation @ (PdfGraphics::SaveMatrix(matrix) | PdfGraphics::Matrix(matrix))) => {
|
||||
if matches!(operation, PdfGraphics::SaveMatrix(_)) {
|
||||
xdv_graphics_stack.push((special.span, xdv_transform));
|
||||
xdv_graphics_stack.push((special.span, xdv_transform, self.xdv_colors.current()));
|
||||
}
|
||||
let [x, y] = special.position;
|
||||
let pivot = matrix.about(
|
||||
@@ -486,10 +501,13 @@ impl Executor {
|
||||
xdv_transform = xdv_transform.concatenate(pivot);
|
||||
}
|
||||
Some(PdfGraphics::Restore { .. }) => {
|
||||
let Some((_, previous)) = xdv_graphics_stack.pop() else {
|
||||
let Some((_, previous, color_at_save)) = xdv_graphics_stack.pop() else {
|
||||
return Err(self.error("unmatched XDV graphics restore", special.span));
|
||||
};
|
||||
xdv_transform = previous;
|
||||
if let Some(program) = self.xdv_colors.restore_after_save(color_at_save) {
|
||||
shipout.xdv_color_steps.insert(graphics_step, program);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -565,7 +583,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() {
|
||||
@@ -605,9 +623,8 @@ impl Executor {
|
||||
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
|
||||
{
|
||||
if let Some(pdf) = &mut shipout.device.pdf && xdv {
|
||||
shipout.pdf_background = self.xdv_colors.background();
|
||||
self.state.xdv_setup.apply_version(&mut pdf.file);
|
||||
}
|
||||
self.current = current;
|
||||
|
||||
Reference in new issue
Block a user