Preserve pdfTeX text positioning across direct color changes
This commit is contained in:
1 parent
0f6aa1f33d
commit
f88a16d101
15 files changed
+190
-41
No files matched your search
@@ -231,7 +231,7 @@ pub(super) struct BoxLayout {
|
|||||||
pub(super) enum GeometryItem {
|
pub(super) enum GeometryItem {
|
||||||
Output,
|
Output,
|
||||||
Paint(crate::math_engine_tex::PositionedItem),
|
Paint(crate::math_engine_tex::PositionedItem),
|
||||||
PdfColor,
|
PdfColor { x: i64, y: i64 },
|
||||||
PdfGraphics { x: i64, y: i64 },
|
PdfGraphics { x: i64, y: i64 },
|
||||||
PdfTextSpace { x: i64, y: i64, operation: crate::pdf_device::text_spaces::SpaceOperation },
|
PdfTextSpace { x: i64, y: i64, operation: crate::pdf_device::text_spaces::SpaceOperation },
|
||||||
}
|
}
|
||||||
@@ -846,7 +846,7 @@ impl NativeBox {
|
|||||||
let b = match node {
|
let b = match node {
|
||||||
BoxPaint::Box(b) => b,
|
BoxPaint::Box(b) => b,
|
||||||
BoxPaint::PdfColor => {
|
BoxPaint::PdfColor => {
|
||||||
emit(GeometryItem::PdfColor);
|
emit(GeometryItem::PdfColor { x, y });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BoxPaint::PdfGraphics => {
|
BoxPaint::PdfGraphics => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! Per-shipout device state. Original TeX boxes remain unscaled semantic lists.
|
//! Per-shipout device state. Original TeX boxes remain unscaled semantic lists.
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::pdf_device::{PdfColorProgram, PdfGraphics};
|
use crate::pdf_device::{PdfColorProgram, PdfGraphics, ShippedColor};
|
||||||
use std::{collections::BTreeMap, sync::Arc};
|
use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
@@ -35,9 +35,9 @@ pub struct NativeShipout {
|
|||||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
pub(super) pdf_font_bindings: Option<Arc<crate::native_font::PdfFontBindings>>,
|
pub(super) pdf_font_bindings: Option<Arc<crate::native_font::PdfFontBindings>>,
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
#[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")]
|
#[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")]
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
pub(super) pdf_graphics_steps: Vec<Option<PdfGraphics>>,
|
pub(super) pdf_graphics_steps: Vec<Option<PdfGraphics>>,
|
||||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||||
@@ -91,11 +91,12 @@ impl NativeShipout {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
use crate::{math_engine_tex::MathItem, render::DisplayItem};
|
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(
|
page.items.extend(
|
||||||
self.pdf_color_start
|
self.pdf_color_start
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.map(|color| color.display_item(left, baseline)),
|
||||||
.map(DisplayItem::PdfColor),
|
|
||||||
);
|
);
|
||||||
let mut color_steps = self.pdf_color_steps.iter();
|
let mut color_steps = self.pdf_color_steps.iter();
|
||||||
let mut graphics_steps = self.pdf_graphics_steps.iter().enumerate();
|
let mut graphics_steps = self.pdf_graphics_steps.iter().enumerate();
|
||||||
@@ -115,10 +116,10 @@ impl NativeShipout {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boxes::GeometryItem::Paint(p) => p,
|
boxes::GeometryItem::Paint(p) => p,
|
||||||
boxes::GeometryItem::PdfColor => {
|
boxes::GeometryItem::PdfColor { x, y } => {
|
||||||
match color_steps.next() {
|
match color_steps.next() {
|
||||||
Some(Some(program)) => {
|
Some(Some(color)) => {
|
||||||
page.items.push(DisplayItem::PdfColor(program.clone()))
|
page.items.push(color.display_item(left + x, baseline + y))
|
||||||
}
|
}
|
||||||
Some(None) => {}
|
Some(None) => {}
|
||||||
None => missing_color_step = true,
|
None => missing_color_step = true,
|
||||||
@@ -144,7 +145,12 @@ impl NativeShipout {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(program) = self.xdv_color_steps.get(&step) {
|
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) {
|
if let Some((image, origin)) = self.pdf_special_images.get(&step) {
|
||||||
let [left, bottom] = image.xdv.as_ref().unwrap().layout_offset;
|
let [left, bottom] = image.xdv.as_ref().unwrap().layout_offset;
|
||||||
|
|||||||
@@ -334,7 +334,11 @@ impl Executor {
|
|||||||
use crate::pdf_device::PdfDriver;
|
use crate::pdf_device::PdfDriver;
|
||||||
let xdv = device.pdf.as_ref().is_some_and(|pdf| pdf.driver == PdfDriver::Xdv);
|
let xdv = device.pdf.as_ref().is_some_and(|pdf| pdf.driver == PdfDriver::Xdv);
|
||||||
let pdf_color_start = if 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() {
|
} else if device.pdf.is_some() {
|
||||||
self.pdf_colors.start_page()
|
self.pdf_colors.start_page()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::pdf_device::{ColorResult, PdfColorProgram, PdfColorStackAction};
|
use crate::pdf_device::{ColorResult, PdfColorProgram, PdfColorStackAction, PdfLiteralMode, ShippedColor};
|
||||||
|
|
||||||
impl Executor {
|
impl Executor {
|
||||||
fn scan_pdf_color_program(
|
fn scan_pdf_color_program(
|
||||||
@@ -16,13 +16,16 @@ impl Executor {
|
|||||||
files: &mut impl SourceProvider,
|
files: &mut impl SourceProvider,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let replay_on_page = self.keyword("page", files)?;
|
let replay_on_page = self.keyword("page", files)?;
|
||||||
// Device-color operators are independent of the coordinate origin.
|
let mode = if self.keyword("direct", files)? {
|
||||||
if !self.keyword("direct", files)? {
|
PdfLiteralMode::Direct
|
||||||
self.keyword("page", files)?;
|
} else if self.keyword("page", files)? {
|
||||||
}
|
PdfLiteralMode::Page
|
||||||
|
} else {
|
||||||
|
PdfLiteralMode::Origin
|
||||||
|
};
|
||||||
let initial = self.scan_pdf_color_program(files)?;
|
let initial = self.scan_pdf_color_program(files)?;
|
||||||
self.pdf_colors
|
self.pdf_colors
|
||||||
.allocate(initial, replay_on_page)
|
.allocate(initial, mode, replay_on_page)
|
||||||
.map_err(|message| self.error(message, self.current))
|
.map_err(|message| self.error(message, self.current))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ impl Executor {
|
|||||||
action: &PdfColorStackAction,
|
action: &PdfColorStackAction,
|
||||||
span: Span,
|
span: Span,
|
||||||
files: &mut impl SourceProvider,
|
files: &mut impl SourceProvider,
|
||||||
) -> Result<Option<Arc<PdfColorProgram>>, Error> {
|
) -> Result<Option<ShippedColor>, Error> {
|
||||||
self.current = span;
|
self.current = span;
|
||||||
self.tick()?;
|
self.tick()?;
|
||||||
let warning = match self.pdf_colors.apply(stack, action) {
|
let warning = match self.pdf_colors.apply(stack, action) {
|
||||||
|
|||||||
@@ -769,7 +769,7 @@ impl Execution {
|
|||||||
let mut font_affects_paint = BTreeMap::new();
|
let mut font_affects_paint = BTreeMap::new();
|
||||||
for page in pages.iter_mut() {
|
for page in pages.iter_mut() {
|
||||||
let states = page.items.iter().filter_map(|item| match item {
|
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,
|
_ => None,
|
||||||
}).flatten().cloned().collect();
|
}).flatten().cloned().collect();
|
||||||
page.pdf_resources = PageResources::from_page(
|
page.pdf_resources = PageResources::from_page(
|
||||||
|
|||||||
@@ -767,23 +767,29 @@ fn page_content(
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let DisplayItem::PdfGraphics {
|
let literal = match item {
|
||||||
|
DisplayItem::PdfGraphics {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
operation: PdfGraphics::Literal { mode, bytes },
|
operation: PdfGraphics::Literal { mode, bytes },
|
||||||
} = item
|
} => 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);
|
NativeTextRun::flush(&mut native_text, &mut content);
|
||||||
let previous_origin = content.origin.position();
|
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 {
|
match mode {
|
||||||
PdfLiteralMode::Direct => {
|
PdfLiteralMode::Direct => {
|
||||||
native_text::NativeText::break_string(&mut tex_text, &mut content);
|
native_text::NativeText::break_string(&mut tex_text, &mut content);
|
||||||
}
|
}
|
||||||
PdfLiteralMode::Page | PdfLiteralMode::Origin => {
|
PdfLiteralMode::Page | PdfLiteralMode::Origin => {
|
||||||
native_text::NativeText::finish(&mut tex_text, &mut content);
|
native_text::NativeText::finish(&mut tex_text, &mut content);
|
||||||
if *mode == PdfLiteralMode::Origin {
|
if mode == PdfLiteralMode::Origin {
|
||||||
content.move_origin([*x, height - *y], list.units, digits);
|
content.move_origin([x, height - y], list.units, digits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PdfLiteralMode::XdvOrigin | PdfLiteralMode::XdvDirect => {
|
PdfLiteralMode::XdvOrigin | PdfLiteralMode::XdvDirect => {
|
||||||
@@ -1145,10 +1151,7 @@ fn page_content(
|
|||||||
content.push_str(special);
|
content.push_str(special);
|
||||||
content.push(b'\n');
|
content.push(b'\n');
|
||||||
}
|
}
|
||||||
DisplayItem::PdfColor(program) => {
|
DisplayItem::PdfColor { .. } => unreachable!("color handled before text"),
|
||||||
content.push_str(program.literal());
|
|
||||||
content.push(b'\n');
|
|
||||||
}
|
|
||||||
DisplayItem::PdfGraphics { x, y, operation } => {
|
DisplayItem::PdfGraphics { x, y, operation } => {
|
||||||
let xdv = list.pdf.as_ref().is_some_and(|pdf| pdf.driver == PdfDriver::Xdv);
|
let xdv = list.pdf.as_ref().is_some_and(|pdf| pdf.driver == PdfDriver::Xdv);
|
||||||
let device_origin = list.units == DisplayUnits::TeX && !xdv;
|
let device_origin = list.units == DisplayUnits::TeX && !xdv;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ pub(crate) mod xdv_image;
|
|||||||
pub(crate) mod xdv_navigation;
|
pub(crate) mod xdv_navigation;
|
||||||
pub(crate) mod xdv_object;
|
pub(crate) mod xdv_object;
|
||||||
mod graphics;
|
mod graphics;
|
||||||
pub(crate) use color::{ColorResult, PdfColorStacks};
|
pub(crate) use color::{ColorResult, PdfColorStacks, ShippedColor};
|
||||||
pub use color::{PdfColorProgram, PdfColorStackAction};
|
pub use color::{PdfColorProgram, PdfColorStackAction};
|
||||||
pub(crate) use graphics::{Affine, DeviceOrigin};
|
pub(crate) use graphics::{Affine, DeviceOrigin};
|
||||||
pub use graphics::{PdfGraphics, PdfLiteralMode, PdfMatrix};
|
pub use graphics::{PdfGraphics, PdfLiteralMode, PdfMatrix};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use super::PdfLiteralMode;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -100,19 +101,55 @@ pub enum PdfColorStackAction {
|
|||||||
Pop,
|
Pop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub(crate) enum ShippedColor {
|
||||||
|
WithMode {
|
||||||
|
program: Arc<PdfColorProgram>,
|
||||||
|
mode: PdfLiteralMode,
|
||||||
|
},
|
||||||
|
Page(Arc<PdfColorProgram>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ShippedColor {
|
||||||
|
pub(crate) fn display_item(&self, x: i64, y: i64) -> crate::render::DisplayItem {
|
||||||
|
let (program, mode) = match self {
|
||||||
|
Self::WithMode { program, mode } => (program, *mode),
|
||||||
|
Self::Page(program) => (program, PdfLiteralMode::Page),
|
||||||
|
};
|
||||||
|
crate::render::DisplayItem::PdfColor {
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
program: program.clone(),
|
||||||
|
mode,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct Stack {
|
struct Stack {
|
||||||
|
mode: PdfLiteralMode,
|
||||||
replay_on_page: bool,
|
replay_on_page: bool,
|
||||||
current: Arc<PdfColorProgram>,
|
current: Arc<PdfColorProgram>,
|
||||||
saved: Vec<Arc<PdfColorProgram>>,
|
saved: Vec<Arc<PdfColorProgram>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Stack {
|
||||||
|
fn shipped_color(&self) -> ShippedColor {
|
||||||
|
ShippedColor::WithMode {
|
||||||
|
program: self.current.clone(),
|
||||||
|
mode: self.mode,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct PdfColorStacks(Vec<Stack>);
|
pub(crate) struct PdfColorStacks(Vec<Stack>);
|
||||||
|
|
||||||
impl Default for PdfColorStacks {
|
impl Default for PdfColorStacks {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(vec![Stack {
|
Self(vec![Stack {
|
||||||
|
mode: PdfLiteralMode::Direct,
|
||||||
replay_on_page: true,
|
replay_on_page: true,
|
||||||
current: Arc::new(PdfColorProgram {
|
current: Arc::new(PdfColorProgram {
|
||||||
literal: "0 g 0 G".into(),
|
literal: "0 g 0 G".into(),
|
||||||
@@ -126,7 +163,7 @@ impl Default for PdfColorStacks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum ColorResult {
|
pub(crate) enum ColorResult {
|
||||||
Applied(Option<Arc<PdfColorProgram>>),
|
Applied(Option<ShippedColor>),
|
||||||
EmptyStack,
|
EmptyStack,
|
||||||
UnknownStack,
|
UnknownStack,
|
||||||
}
|
}
|
||||||
@@ -135,6 +172,7 @@ impl PdfColorStacks {
|
|||||||
pub(crate) fn allocate(
|
pub(crate) fn allocate(
|
||||||
&mut self,
|
&mut self,
|
||||||
initial: PdfColorProgram,
|
initial: PdfColorProgram,
|
||||||
|
mode: PdfLiteralMode,
|
||||||
replay_on_page: bool,
|
replay_on_page: bool,
|
||||||
) -> Result<usize, String> {
|
) -> Result<usize, String> {
|
||||||
let number = self.0.len();
|
let number = self.0.len();
|
||||||
@@ -142,6 +180,7 @@ impl PdfColorStacks {
|
|||||||
return Err("too many PDF color stacks".into());
|
return Err("too many PDF color stacks".into());
|
||||||
}
|
}
|
||||||
self.0.push(Stack {
|
self.0.push(Stack {
|
||||||
|
mode,
|
||||||
replay_on_page,
|
replay_on_page,
|
||||||
current: Arc::new(initial),
|
current: Arc::new(initial),
|
||||||
saved: Vec::new(),
|
saved: Vec::new(),
|
||||||
@@ -153,12 +192,12 @@ impl PdfColorStacks {
|
|||||||
number < self.0.len()
|
number < self.0.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn start_page(&self) -> Vec<Arc<PdfColorProgram>> {
|
pub(crate) fn start_page(&self) -> Vec<ShippedColor> {
|
||||||
self.0
|
self.0
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|stack| {
|
.filter_map(|stack| {
|
||||||
(stack.replay_on_page && !matches!(stack.current.literal(), "" | "0 g 0 G"))
|
(stack.replay_on_page && !matches!(stack.current.literal(), "" | "0 g 0 G"))
|
||||||
.then(|| stack.current.clone())
|
.then(|| stack.shipped_color())
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@@ -180,6 +219,6 @@ impl PdfColorStacks {
|
|||||||
None => return ColorResult::EmptyStack,
|
None => return ColorResult::EmptyStack,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ColorResult::Applied((!stack.current.literal().is_empty()).then(|| stack.current.clone()))
|
ColorResult::Applied((!stack.current.literal().is_empty()).then(|| stack.shipped_color()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -427,6 +427,10 @@ pub(crate) fn plan_spaces(
|
|||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
|
}
|
||||||
|
| DisplayItem::PdfColor {
|
||||||
|
mode: PdfLiteralMode::Direct,
|
||||||
|
..
|
||||||
} => {
|
} => {
|
||||||
NativeText::break_string(&mut text, &mut out);
|
NativeText::break_string(&mut text, &mut out);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,12 @@ pub enum DisplayItem {
|
|||||||
Background([u8; 3]),
|
Background([u8; 3]),
|
||||||
/// Switch the fill colour for following text (RGB).
|
/// Switch the fill colour for following text (RGB).
|
||||||
Fill([u8; 3]),
|
Fill([u8; 3]),
|
||||||
PdfColor(std::sync::Arc<crate::pdf_device::PdfColorProgram>),
|
PdfColor {
|
||||||
|
x: i64,
|
||||||
|
y: i64,
|
||||||
|
program: std::sync::Arc<crate::pdf_device::PdfColorProgram>,
|
||||||
|
mode: crate::pdf_device::PdfLiteralMode,
|
||||||
|
},
|
||||||
PdfGraphics {
|
PdfGraphics {
|
||||||
x: i64,
|
x: i64,
|
||||||
y: i64,
|
y: i64,
|
||||||
@@ -435,7 +440,7 @@ impl DisplayList {
|
|||||||
*x += dx;
|
*x += dx;
|
||||||
*y += dy;
|
*y += dy;
|
||||||
}
|
}
|
||||||
DisplayItem::Fill(_) | DisplayItem::Background(_) | DisplayItem::PdfColor(_) => {}
|
DisplayItem::Fill(_) | DisplayItem::Background(_) | DisplayItem::PdfColor { .. } => {}
|
||||||
DisplayItem::Special(_) | DisplayItem::PdfImageObject(_)
|
DisplayItem::Special(_) | DisplayItem::PdfImageObject(_)
|
||||||
| DisplayItem::OpenTypeActualText(_) | DisplayItem::OpenTypeColor(_) => {}
|
| DisplayItem::OpenTypeActualText(_) | DisplayItem::OpenTypeColor(_) => {}
|
||||||
}
|
}
|
||||||
@@ -455,7 +460,7 @@ impl DisplayList {
|
|||||||
return Err("this page requires a PDF renderer".into());
|
return Err("this page requires a PDF renderer".into());
|
||||||
}
|
}
|
||||||
for item in &self.items {
|
for item in &self.items {
|
||||||
if let DisplayItem::PdfColor(program) = item
|
if let DisplayItem::PdfColor { program, .. } = item
|
||||||
&& program
|
&& program
|
||||||
.graphics_states
|
.graphics_states
|
||||||
.iter()
|
.iter()
|
||||||
@@ -775,7 +780,7 @@ impl DisplayList {
|
|||||||
escape(content)
|
escape(content)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
DisplayItem::PdfColor(program) => {
|
DisplayItem::PdfColor { program, .. } => {
|
||||||
if let Some(rgb) = program.fill {
|
if let Some(rgb) = program.fill {
|
||||||
fill = rgb;
|
fill = rgb;
|
||||||
rule_fill = rgb;
|
rule_fill = rgb;
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ impl SourceMap {
|
|||||||
// Color controls change graphics state and occupy no geometry.
|
// Color controls change graphics state and occupy no geometry.
|
||||||
if matches!(
|
if matches!(
|
||||||
item,
|
item,
|
||||||
DisplayItem::PdfColor(_) | DisplayItem::PdfImageObject(_) | DisplayItem::PdfTextSpace { .. }
|
DisplayItem::PdfColor { .. } | DisplayItem::PdfImageObject(_) | DisplayItem::PdfTextSpace { .. }
|
||||||
| DisplayItem::OpenTypeColor(_)
|
| DisplayItem::OpenTypeColor(_)
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -354,3 +354,50 @@ fn colors_follow_actual_glyphs_and_survive_retained_execution() {
|
|||||||
"{report:?}: PDF glyph raster differs"
|
"{report:?}: PDF glyph raster differs"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn color_stack_modes_preserve_or_reset_the_text_cursor() {
|
||||||
|
let directory = std::env::temp_dir().join(format!("texrra-color-modes-{}", std::process::id()));
|
||||||
|
let data = br"\catcode123=1 \catcode125=2
|
||||||
|
\pdfoutput=1 \pdfcompresslevel=0 \pdfobjcompresslevel=0
|
||||||
|
\pdfpagewidth=210pt \pdfpageheight=120pt
|
||||||
|
\font\sample=cmr10 \sample
|
||||||
|
\edef\onpage{\pdfcolorstackinit page page{}}
|
||||||
|
\edef\atpoint{\pdfcolorstackinit{}}
|
||||||
|
\edef\intext{\pdfcolorstackinit direct{}}
|
||||||
|
\shipout\hbox{\kern131sp A\pdfcolorstack0 push{.21 g}\kern2.26pt B%
|
||||||
|
\pdfcolorstack\onpage set{.32 g}C\pdfcolorstack\atpoint set{.43 g}D%
|
||||||
|
\pdfcolorstack\intext set{.54 g}E}
|
||||||
|
\end
|
||||||
|
";
|
||||||
|
let original = reference_pdf(&directory, "colored-text-modes", data);
|
||||||
|
let mut host = Host::default();
|
||||||
|
let execution = run(data.to_vec(), &mut host).unwrap();
|
||||||
|
let restored: Execution =
|
||||||
|
serde_json::from_slice(&serde_json::to_vec(&execution).unwrap()).unwrap();
|
||||||
|
let mut pages = restored.shipout_display_lists().unwrap();
|
||||||
|
texrra_tex_core::native_font::resolve_native_fonts(&mut pages, &mut host).unwrap();
|
||||||
|
let native =
|
||||||
|
pdf::shipout_lists_to_native_pdf(&pages, restored.state.pdf_final_options()).unwrap();
|
||||||
|
|
||||||
|
for pdf in [fs::read(&original).unwrap(), native] {
|
||||||
|
let streams = streams(&pdf);
|
||||||
|
let page = streams.iter().find(|stream| stream.contains("\n.21 g\n")).unwrap();
|
||||||
|
let tokens: Vec<_> = page.split_ascii_whitespace().collect();
|
||||||
|
for (color, in_text, moves_origin) in [
|
||||||
|
(".21", true, false),
|
||||||
|
(".32", false, false),
|
||||||
|
(".43", false, true),
|
||||||
|
(".54", true, false),
|
||||||
|
] {
|
||||||
|
let at = tokens.windows(2).position(|w| w == [color, "g"]).unwrap();
|
||||||
|
let state = tokens[..at]
|
||||||
|
.iter()
|
||||||
|
.rev()
|
||||||
|
.find(|&&token| matches!(token, "BT" | "ET"))
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(*state == "BT", in_text, "color {color}");
|
||||||
|
assert_eq!(tokens[at - 1] == "cm", moves_origin, "color {color}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2175,6 +2175,33 @@ PDF,恢复实际 PFB 并反转斜切时复用 1277 步,只替换第二页。
|
|||||||
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
全量编译一致。incremental-receipt.json 的 SHA-256 为
|
||||||
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
bbc0991b0316e6d76aa58649ec873525f5544ab530d93fe491fc6e16bd00a27d。
|
||||||
|
|
||||||
|
### pdfTeX 颜色栈的文字游标与 CAS 双栏正文
|
||||||
|
|
||||||
|
内置栈和 direct 模式仅提交已积累的文字串,保留当前 PDF 文字对象、
|
||||||
|
位置及舍入余量。page 模式结束文字对象,默认的原点模式还按发页位置
|
||||||
|
设置绘制原点。栈模式独立于页首重放开关,在实际发页进入颜色操作。
|
||||||
|
PDF 写出与词间空格计划共用 direct 的文字边界。已保存的发页记录
|
||||||
|
仍能读取原字符串形式。
|
||||||
|
[pdfTeX 的内置颜色栈](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/utils.c#L995-L1012)
|
||||||
|
[pdfTeX 应用三种字面模式](https://github.com/TeX-Live/texlive-source/blob/fb6158926661cb7a7246b3a94a0cb170a9624d5a/texk/web2c/pdftexdir/pdftex.web#L16431-L16471)
|
||||||
|
|
||||||
|
原样 Elsevier CAS 双栏沿用 30 项原始交付、冻结参考、schema51
|
||||||
|
和字体映射。三轮 aux 与实际 BibTeX 的 bbl 逐字节匹配,终轮无未
|
||||||
|
定义引用。六页 10372 个字形的身份、顺序、位置、字号及伸缩一致。
|
||||||
|
1889 个词全部同序,词框一致,144 DPI 灰度差由 400 像素降为 0。
|
||||||
|
原生两版的布局与来源记录在归一化工作目录后相同。先前的字体导入
|
||||||
|
与版面差异证据仍随该基线保留。
|
||||||
|
|
||||||
|
三次跨文件更改颜色指令后的实际字形间距,各复用 99 步,只替换
|
||||||
|
第二页,PDF、SVG、来源映射和生成 aux 与同初始状态的独立全量相同。
|
||||||
|
新增颜色栈模式对照在旧版失败、当前通过。相关测试三项通过,一项
|
||||||
|
预存的规则绘制指令比较在前后两版同处失败,原断言和日志保留。
|
||||||
|
|
||||||
|
回执 `target/p3-cas-body-position/receipt.json` 的 SHA-256 为
|
||||||
|
`5c88336efad4830cf996e51d1af527a15bfbd1a3cce4fa5ed6dc6c8a79850c67`。
|
||||||
|
导入 Type1C、子集及描述符共享仍在后续功能范围,发布矩阵按同一
|
||||||
|
冻结版本统一验收。
|
||||||
|
|
||||||
### pdfTeX 导入页面的 Type 1 字体与 CAS 图摘
|
### pdfTeX 导入页面的 Type 1 字体与 CAS 图摘
|
||||||
|
|
||||||
`\pdfinclusioncopyfonts` 在首次初始化 PDF 输出时锁定,普通
|
`\pdfinclusioncopyfonts` 在首次初始化 PDF 输出时锁定,普通
|
||||||
|
|||||||
@@ -977,6 +977,17 @@ LuaLaTex、languages 和 argues 的断行与冻结参考一致。PDF 提取的
|
|||||||
字形提取仍待对照,当前整页版面门禁保持未通过。
|
字形提取仍待对照,当前整页版面门禁保持未通过。
|
||||||
阶段回执 `target/p3-xetex-native-hyphenation/receipt.json`。
|
阶段回执 `target/p3-xetex-native-hyphenation/receipt.json`。
|
||||||
|
|
||||||
|
### Elsevier CAS 双栏正文复验
|
||||||
|
|
||||||
|
原样 CAS 双栏在同一 30 项原始交付、冻结 schema51、字体映射及
|
||||||
|
参考下复编。双方的三轮 aux 与实际 BibTeX 的 bbl 逐字节一致,终轮
|
||||||
|
无未定义引用。颜色栈的直接输出保留 PDF 文字游标后,六页
|
||||||
|
10372 个字形的位置、1889 个词的顺序和词框均完全一致。六页
|
||||||
|
144 DPI 灰度图逐像素相同,前版第 3、4、5 页的 400 个差异像素
|
||||||
|
归零。原生布局与来源记录在归一化路径后相同。该样稿将在同版
|
||||||
|
出版模板矩阵中复验。
|
||||||
|
[阶段记录](P2_M1_PROGRESS.md#pdftex-颜色栈的文字游标与-cas-双栏正文)
|
||||||
|
|
||||||
### Elsevier CAS 双栏导入字体复验
|
### Elsevier CAS 双栏导入字体复验
|
||||||
|
|
||||||
保留原 30 项交付文件、冻结 schema51、字体映射和参考。原生三轮
|
保留原 30 项交付文件、冻结 schema51、字体映射和参考。原生三轮
|
||||||
|
|||||||
+1
-1
@@ -816,7 +816,7 @@ impl Files {
|
|||||||
"id":image.id, "page":image.image.page, "resource":image.image.version,
|
"id":image.id, "page":image.image.page, "resource":image.image.version,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
DisplayItem::PdfImageObject(_) | DisplayItem::PdfColor(_) | DisplayItem::PdfTextSpace { .. }
|
DisplayItem::PdfImageObject(_) | DisplayItem::PdfColor { .. } | DisplayItem::PdfTextSpace { .. }
|
||||||
| DisplayItem::OpenTypeActualText(_) | DisplayItem::OpenTypeColor(_) => {}
|
| DisplayItem::OpenTypeActualText(_) | DisplayItem::OpenTypeColor(_) => {}
|
||||||
DisplayItem::PdfGraphics { x, y, operation } => {
|
DisplayItem::PdfGraphics { x, y, operation } => {
|
||||||
paint_order.push(json!(["pdf_graphics", graphics.len()]));
|
paint_order.push(json!(["pdf_graphics", graphics.len()]));
|
||||||
|
|||||||
Reference in new issue
Block a user