Preserve pdfTeX text positioning across direct color changes
This commit is contained in:
1 parent
0f6aa1f33d
commit
f88a16d101
15 files changed
+193
-44
No files matched your search
@@ -231,7 +231,7 @@ pub(super) struct BoxLayout {
|
||||
pub(super) enum GeometryItem {
|
||||
Output,
|
||||
Paint(crate::math_engine_tex::PositionedItem),
|
||||
PdfColor,
|
||||
PdfColor { x: i64, y: i64 },
|
||||
PdfGraphics { x: i64, y: i64 },
|
||||
PdfTextSpace { x: i64, y: i64, operation: crate::pdf_device::text_spaces::SpaceOperation },
|
||||
}
|
||||
@@ -846,7 +846,7 @@ impl NativeBox {
|
||||
let b = match node {
|
||||
BoxPaint::Box(b) => b,
|
||||
BoxPaint::PdfColor => {
|
||||
emit(GeometryItem::PdfColor);
|
||||
emit(GeometryItem::PdfColor { x, y });
|
||||
return;
|
||||
}
|
||||
BoxPaint::PdfGraphics => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Per-shipout device state. Original TeX boxes remain unscaled semantic lists.
|
||||
use super::*;
|
||||
use crate::pdf_device::{PdfColorProgram, PdfGraphics};
|
||||
use crate::pdf_device::{PdfColorProgram, PdfGraphics, ShippedColor};
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
@@ -35,9 +35,9 @@ pub struct NativeShipout {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(super) pdf_font_bindings: Option<Arc<crate::native_font::PdfFontBindings>>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub(super) pdf_color_start: Vec<Arc<PdfColorProgram>>,
|
||||
pub(super) pdf_color_start: Vec<ShippedColor>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub(super) pdf_color_steps: Vec<Option<Arc<PdfColorProgram>>>,
|
||||
pub(super) pdf_color_steps: Vec<Option<ShippedColor>>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub(super) pdf_graphics_steps: Vec<Option<PdfGraphics>>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
@@ -91,11 +91,12 @@ impl NativeShipout {
|
||||
..Default::default()
|
||||
};
|
||||
use crate::{math_engine_tex::MathItem, render::DisplayItem};
|
||||
let left = self.device.horizontal_origin;
|
||||
let baseline = self.device.vertical_origin + self.box_node.height;
|
||||
page.items.extend(
|
||||
self.pdf_color_start
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(DisplayItem::PdfColor),
|
||||
.map(|color| color.display_item(left, baseline)),
|
||||
);
|
||||
let mut color_steps = self.pdf_color_steps.iter();
|
||||
let mut graphics_steps = self.pdf_graphics_steps.iter().enumerate();
|
||||
@@ -115,10 +116,10 @@ impl NativeShipout {
|
||||
return;
|
||||
}
|
||||
boxes::GeometryItem::Paint(p) => p,
|
||||
boxes::GeometryItem::PdfColor => {
|
||||
boxes::GeometryItem::PdfColor { x, y } => {
|
||||
match color_steps.next() {
|
||||
Some(Some(program)) => {
|
||||
page.items.push(DisplayItem::PdfColor(program.clone()))
|
||||
Some(Some(color)) => {
|
||||
page.items.push(color.display_item(left + x, baseline + y))
|
||||
}
|
||||
Some(None) => {}
|
||||
None => missing_color_step = true,
|
||||
@@ -144,7 +145,12 @@ impl NativeShipout {
|
||||
});
|
||||
}
|
||||
if let Some(program) = self.xdv_color_steps.get(&step) {
|
||||
page.items.push(DisplayItem::PdfColor(program.clone()));
|
||||
page.items.push(DisplayItem::PdfColor {
|
||||
x: left + x,
|
||||
y: baseline + y,
|
||||
program: program.clone(),
|
||||
mode: crate::pdf_device::PdfLiteralMode::Page,
|
||||
});
|
||||
}
|
||||
if let Some((image, origin)) = self.pdf_special_images.get(&step) {
|
||||
let [left, bottom] = image.xdv.as_ref().unwrap().layout_offset;
|
||||
|
||||
@@ -334,7 +334,11 @@ impl Executor {
|
||||
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()
|
||||
self.xdv_colors
|
||||
.start_page()
|
||||
.into_iter()
|
||||
.map(crate::pdf_device::ShippedColor::Page)
|
||||
.collect()
|
||||
} else if device.pdf.is_some() {
|
||||
self.pdf_colors.start_page()
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::pdf_device::{ColorResult, PdfColorProgram, PdfColorStackAction};
|
||||
use crate::pdf_device::{ColorResult, PdfColorProgram, PdfColorStackAction, PdfLiteralMode, ShippedColor};
|
||||
|
||||
impl Executor {
|
||||
fn scan_pdf_color_program(
|
||||
@@ -16,13 +16,16 @@ impl Executor {
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<usize, Error> {
|
||||
let replay_on_page = self.keyword("page", files)?;
|
||||
// Device-color operators are independent of the coordinate origin.
|
||||
if !self.keyword("direct", files)? {
|
||||
self.keyword("page", files)?;
|
||||
}
|
||||
let mode = if self.keyword("direct", files)? {
|
||||
PdfLiteralMode::Direct
|
||||
} else if self.keyword("page", files)? {
|
||||
PdfLiteralMode::Page
|
||||
} else {
|
||||
PdfLiteralMode::Origin
|
||||
};
|
||||
let initial = self.scan_pdf_color_program(files)?;
|
||||
self.pdf_colors
|
||||
.allocate(initial, replay_on_page)
|
||||
.allocate(initial, mode, replay_on_page)
|
||||
.map_err(|message| self.error(message, self.current))
|
||||
}
|
||||
|
||||
@@ -62,7 +65,7 @@ impl Executor {
|
||||
action: &PdfColorStackAction,
|
||||
span: Span,
|
||||
files: &mut impl SourceProvider,
|
||||
) -> Result<Option<Arc<PdfColorProgram>>, Error> {
|
||||
) -> Result<Option<ShippedColor>, Error> {
|
||||
self.current = span;
|
||||
self.tick()?;
|
||||
let warning = match self.pdf_colors.apply(stack, action) {
|
||||
|
||||
@@ -769,7 +769,7 @@ impl Execution {
|
||||
let mut font_affects_paint = BTreeMap::new();
|
||||
for page in pages.iter_mut() {
|
||||
let states = page.items.iter().filter_map(|item| match item {
|
||||
DisplayItem::PdfColor(program) => Some(&program.graphics_states),
|
||||
DisplayItem::PdfColor { program, .. } => Some(&program.graphics_states),
|
||||
_ => None,
|
||||
}).flatten().cloned().collect();
|
||||
page.pdf_resources = PageResources::from_page(
|
||||
|
||||
Reference in new issue
Block a user