Save the TeX cursor in native shipout order
This commit is contained in:
1 parent
555a029505
commit
413939911f
12 files changed
+173
-28
No files matched your search
@@ -247,13 +247,15 @@ impl Executor {
|
||||
let vertical_origin =
|
||||
i64::from(self.read_parameter(Parameter::Pdfvorigin).width()) + v_offset;
|
||||
let mut page_width = i64::from(self.read_parameter(Parameter::Pdfpagewidth).width());
|
||||
let mut page_height = i64::from(self.read_parameter(Parameter::Pdfpageheight).width());
|
||||
let requested_page_height = i64::from(self.read_parameter(Parameter::Pdfpageheight).width());
|
||||
if page_width == 0 {
|
||||
page_width = b.width + 2 * horizontal_origin;
|
||||
}
|
||||
if page_height == 0 {
|
||||
page_height = b.height + b.depth + 2 * vertical_origin;
|
||||
}
|
||||
let page_height = if requested_page_height == 0 {
|
||||
b.height + b.depth + 2 * vertical_origin
|
||||
} else {
|
||||
requested_page_height
|
||||
};
|
||||
let device = ShipoutDevice {
|
||||
magnification,
|
||||
page_width,
|
||||
@@ -300,10 +302,10 @@ impl Executor {
|
||||
}
|
||||
let mut link_depth = self.pdf_link_stack.len();
|
||||
let has_link_material = link_depth != 0 || outputs.iter().any(|node| node.is_pdf_link());
|
||||
let mut graphics_positions = if let Some(effects) = &leader_effects {
|
||||
effects.graphics_positions.clone().into_iter()
|
||||
} else if outputs.iter().any(|node| node.is_pdf_graphics()) {
|
||||
b.pdf_graphics_positions().into_iter()
|
||||
let mut output_positions = if let Some(effects) = &leader_effects {
|
||||
effects.output_positions.clone().into_iter()
|
||||
} else if outputs.iter().any(|node| node.needs_shipout_position()) {
|
||||
b.positioned_outputs().into_iter()
|
||||
} else {
|
||||
Vec::new().into_iter()
|
||||
};
|
||||
@@ -313,6 +315,13 @@ impl Executor {
|
||||
let mut has_space_nodes = false;
|
||||
let mut pdf_objects = Vec::new();
|
||||
for output in outputs {
|
||||
let position = if output.needs_shipout_position() {
|
||||
Some(output_positions.next().ok_or_else(|| {
|
||||
self.error("missing positioned native output node", output.span)
|
||||
})?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let OutputOperation::PdfObject(number) = output.operation {
|
||||
self.current = output.span;
|
||||
self.tick()?;
|
||||
@@ -329,15 +338,34 @@ impl Executor {
|
||||
if device.pdf.is_none() {
|
||||
return self.fail("cannot ship a PDF graphics operation to DVI");
|
||||
}
|
||||
let point = graphics_positions.next().ok_or_else(|| {
|
||||
self.error("missing positioned PDF graphics node", output.span)
|
||||
})?;
|
||||
pdf_graphics_steps.push(self.ship_pdf_graphics(
|
||||
output,
|
||||
point,
|
||||
position.expect("PDF graphics need a shipout position"),
|
||||
&mut graphics_stack,
|
||||
files,
|
||||
)?);
|
||||
} else if let OutputOperation::PdfSavePosition = output.operation {
|
||||
self.current = output.span;
|
||||
self.tick()?;
|
||||
let [x, y] = position.expect("savepos needs a shipout position");
|
||||
let (left, top, height) = if device.pdf.is_some() {
|
||||
(horizontal_origin, vertical_origin, page_height)
|
||||
} else {
|
||||
const DVI_ORIGIN: i64 = 4_736_286;
|
||||
let top = v_offset + DVI_ORIGIN;
|
||||
let height = if requested_page_height == 0 {
|
||||
b.height + b.depth + 2 * top
|
||||
} else {
|
||||
requested_page_height
|
||||
};
|
||||
(h_offset + DVI_ORIGIN, top, height)
|
||||
};
|
||||
self.state.pdf_last_position = [
|
||||
i32::try_from(left + x)
|
||||
.map_err(|_| self.error("horizontal saved position overflow", output.span))?,
|
||||
i32::try_from(height - top - b.height - y)
|
||||
.map_err(|_| self.error("vertical saved position overflow", output.span))?,
|
||||
];
|
||||
} else if let OutputOperation::PdfTextSpace(operation) = output.operation {
|
||||
self.current = output.span;
|
||||
self.tick()?;
|
||||
@@ -371,8 +399,8 @@ impl Executor {
|
||||
self.output_node(output, files)?;
|
||||
}
|
||||
}
|
||||
if graphics_positions.next().is_some() {
|
||||
return self.fail("unexpected positioned PDF graphics node");
|
||||
if output_positions.next().is_some() {
|
||||
return self.fail("unexpected positioned native output node");
|
||||
}
|
||||
if let Some((_, span)) = graphics_stack.last() {
|
||||
return Err(self.error(
|
||||
|
||||
Reference in new issue
Block a user