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

+16 -13
View File
@@ -767,23 +767,29 @@ fn page_content(
}
continue;
}
if let DisplayItem::PdfGraphics {
x,
y,
operation: PdfGraphics::Literal { mode, bytes },
} = item
{
let literal = match item {
DisplayItem::PdfGraphics {
x,
y,
operation: PdfGraphics::Literal { mode, bytes },
} => Some((*x, *y, *mode, bytes.as_ref())),
DisplayItem::PdfColor {
x, y, mode, program, ..
} => Some((*x, *y, *mode, program.literal().as_bytes())),
_ => None,
};
if let Some((x, y, mode, bytes)) = literal {
NativeTextRun::flush(&mut native_text, &mut content);
let previous_origin = content.origin.position();
let special_origin = mode.xdv_origin([*x, height - *y], height, list.magnification);
let special_origin = mode.xdv_origin([x, height - y], height, list.magnification);
match mode {
PdfLiteralMode::Direct => {
native_text::NativeText::break_string(&mut tex_text, &mut content);
}
PdfLiteralMode::Page | PdfLiteralMode::Origin => {
native_text::NativeText::finish(&mut tex_text, &mut content);
if *mode == PdfLiteralMode::Origin {
content.move_origin([*x, height - *y], list.units, digits);
if mode == PdfLiteralMode::Origin {
content.move_origin([x, height - y], list.units, digits);
}
}
PdfLiteralMode::XdvOrigin | PdfLiteralMode::XdvDirect => {
@@ -1145,10 +1151,7 @@ fn page_content(
content.push_str(special);
content.push(b'\n');
}
DisplayItem::PdfColor(program) => {
content.push_str(program.literal());
content.push(b'\n');
}
DisplayItem::PdfColor { .. } => unreachable!("color handled before text"),
DisplayItem::PdfGraphics { x, y, operation } => {
let xdv = list.pdf.as_ref().is_some_and(|pdf| pdf.driver == PdfDriver::Xdv);
let device_origin = list.units == DisplayUnits::TeX && !xdv;