Preserve pdfTeX text positioning across direct color changes

This commit is contained in:
gloamxun committed 2026-11-26 15:19:17 +08:00
1 parent 0f6aa1f33d
commit f88a16d101
15 files changed
+193 -44

No files matched your search

+15 -9
View File
@@ -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;