Emit native PDF literals at scan and shipout boundaries
This commit is contained in:
1 parent
13ab32247d
commit
432c1d2ba7
21 files changed
+264
-61
No files matched your search
@@ -75,11 +75,11 @@ impl NativeShipout {
|
||||
return;
|
||||
}
|
||||
boxes::GeometryItem::PdfGraphics { x, y } => {
|
||||
if let Some(&operation) = graphics_steps.next() {
|
||||
if let Some(operation) = graphics_steps.next() {
|
||||
page.items.push(DisplayItem::PdfGraphics {
|
||||
x: self.device.horizontal_origin + x,
|
||||
y: self.device.vertical_origin + self.box_node.height + y,
|
||||
operation,
|
||||
operation: operation.clone(),
|
||||
});
|
||||
} else {
|
||||
missing_graphics_step = true;
|
||||
|
||||
@@ -614,6 +614,19 @@ impl Printer<'_> {
|
||||
LinkNode::Destination { .. } => "pdfdest",
|
||||
});
|
||||
}
|
||||
OutputOperation::PdfLiteral { mode, shipout, tokens } => {
|
||||
use crate::pdf_device::PdfLiteralMode;
|
||||
self.command("pdfliteral");
|
||||
if *shipout {
|
||||
self.literal(" shipout");
|
||||
}
|
||||
match mode {
|
||||
PdfLiteralMode::Origin => {}
|
||||
PdfLiteralMode::Page => self.literal(" page"),
|
||||
PdfLiteralMode::Direct => self.literal(" direct"),
|
||||
}
|
||||
self.tokens(tokens)?;
|
||||
}
|
||||
OutputOperation::PdfSetMatrix(tokens) => {
|
||||
self.command("pdfsetmatrix");
|
||||
self.tokens(tokens)?;
|
||||
|
||||
@@ -1510,7 +1510,10 @@ impl Executor {
|
||||
self.push(vec![
|
||||
Token::new(TokenKind::Character('{', CatCode::BeginGroup), span).into(),
|
||||
])?;
|
||||
let expanded = self.scan_expanded_group(files)?;
|
||||
let previous_writing = std::mem::replace(&mut self.writing, true);
|
||||
let expanded = self.scan_expanded_group(files);
|
||||
self.writing = previous_writing;
|
||||
let expanded = expanded?;
|
||||
if !self.required_raw(files)?.end_write {
|
||||
return self.fail("unbalanced expanded native write");
|
||||
}
|
||||
@@ -2790,7 +2793,8 @@ impl Executor {
|
||||
}
|
||||
OutputOperation::PdfSave
|
||||
| OutputOperation::PdfSetMatrix(_)
|
||||
| OutputOperation::PdfRestore => {
|
||||
| OutputOperation::PdfRestore
|
||||
| OutputOperation::PdfLiteral { .. } => {
|
||||
return self.fail("PDF graphics operation requires a positioned shipout");
|
||||
}
|
||||
OutputOperation::Open { stream, name, from } => {
|
||||
@@ -2812,10 +2816,7 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
OutputOperation::Write { stream, tokens } => {
|
||||
let previous_writing = std::mem::replace(&mut self.writing, true);
|
||||
let expanded = self.fully_expand(tokens.clone(), files);
|
||||
self.writing = previous_writing;
|
||||
let expanded = expanded?;
|
||||
let expanded = self.fully_expand(tokens.clone(), files)?;
|
||||
let text = self.token_list_text(&expanded);
|
||||
let mut text = self.external_print(&text);
|
||||
if *stream == 18 {
|
||||
@@ -3758,7 +3759,7 @@ impl Executor {
|
||||
self.output_command(primitive, token.span, files)?
|
||||
}
|
||||
Pdfcolorstack => self.scan_pdf_color_action(token.span, files)?,
|
||||
Pdfsave | Pdfsetmatrix | Pdfrestore => {
|
||||
Pdfsave | Pdfsetmatrix | Pdfrestore | Pdfliteral => {
|
||||
self.scan_pdf_graphics(primitive, token.span, files)?
|
||||
}
|
||||
Pdfstartlink | Pdfendlink | Pdfdest => {
|
||||
|
||||
@@ -788,7 +788,7 @@ impl Executor {
|
||||
| Scriptscriptfont | Endlinechar | Newlinechar | Escapechar | Globaldefs | Time
|
||||
| Day | Month | Year | BeginGroup | EndGroup | Relax | Message | Errmessage
|
||||
| Endinput | Showbox | Show | Showthe | Discretionary | DiscretionaryHyphen
|
||||
| Parshape | Partokenname => {
|
||||
| Parshape | Partokenname | Pdfliteral => {
|
||||
return Ok(false);
|
||||
}
|
||||
_ => return self.fail(format!("unsupported native math primitive: {p:?}")),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::pdf_device::{PdfGraphics, PdfMatrix};
|
||||
use crate::pdf_device::{PdfGraphics, PdfLiteralMode, PdfMatrix};
|
||||
|
||||
impl Executor {
|
||||
pub(super) fn scan_pdf_graphics(
|
||||
@@ -14,6 +14,26 @@ impl Executor {
|
||||
let operation = match command {
|
||||
Primitive::Pdfsave => OutputOperation::PdfSave,
|
||||
Primitive::Pdfrestore => OutputOperation::PdfRestore,
|
||||
Primitive::Pdfliteral => {
|
||||
let shipout = self.keyword("shipout", files)?;
|
||||
let mode = if self.keyword("direct", files)? {
|
||||
PdfLiteralMode::Direct
|
||||
} else if self.keyword("page", files)? {
|
||||
PdfLiteralMode::Page
|
||||
} else {
|
||||
PdfLiteralMode::Origin
|
||||
};
|
||||
let tokens = if shipout {
|
||||
self.scan_group(files)?
|
||||
} else {
|
||||
self.scan_expanded_group(files)?
|
||||
};
|
||||
OutputOperation::PdfLiteral {
|
||||
mode,
|
||||
shipout,
|
||||
tokens,
|
||||
}
|
||||
}
|
||||
Primitive::Pdfsetmatrix => {
|
||||
let tokens = self.with_scanner(ScannerStatus::Absorbing, |scanner| {
|
||||
scanner.scan_expanded_group_mode(files, false)
|
||||
@@ -45,6 +65,19 @@ impl Executor {
|
||||
.map_err(|error| self.error(format!("\\pdfsetmatrix: {error}"), node.span))?;
|
||||
Ok(PdfGraphics::Matrix(matrix))
|
||||
}
|
||||
OutputOperation::PdfLiteral { mode, shipout, tokens } => {
|
||||
let expanded;
|
||||
let tokens = if *shipout {
|
||||
expanded = self.fully_expand(tokens.clone(), files)?;
|
||||
&expanded
|
||||
} else {
|
||||
tokens
|
||||
};
|
||||
Ok(PdfGraphics::Literal {
|
||||
mode: *mode,
|
||||
bytes: self.pdf_token_bytes(tokens)?.into(),
|
||||
})
|
||||
}
|
||||
OutputOperation::PdfRestore => {
|
||||
let (shift, warning) = match saved.pop() {
|
||||
Some((previous, _)) if previous == point => ([0, 0], None),
|
||||
|
||||
@@ -231,6 +231,7 @@ impl Executor {
|
||||
previous.1 || *dx != 0 || *dy != 0);
|
||||
}
|
||||
}
|
||||
Some(PdfGraphics::Literal { .. }) => {}
|
||||
None => failure = Some(self.error("missing PDF transform at link shipout", self.current)),
|
||||
},
|
||||
BoxPaint::RowStart(row) => {
|
||||
|
||||
@@ -8,8 +8,8 @@ use std::{
|
||||
sync::{Arc, Mutex, OnceLock, Weak},
|
||||
};
|
||||
|
||||
const SCHEMA: u32 = 37;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 9] = [27, 28, 31, 32, 33, 34, 35, 36, SCHEMA];
|
||||
const SCHEMA: u32 = 38;
|
||||
const COMPATIBLE_SCHEMAS: [u32; 10] = [27, 28, 31, 32, 33, 34, 35, 36, 37, SCHEMA];
|
||||
const ENGINE: &str = concat!("texrra-native/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -246,6 +246,11 @@ pub enum OutputOperation {
|
||||
image: std::sync::Arc<crate::pdf_image::PdfImageUse>,
|
||||
origin: super::TokenOrigin,
|
||||
},
|
||||
PdfLiteral {
|
||||
mode: crate::pdf_device::PdfLiteralMode,
|
||||
shipout: bool,
|
||||
tokens: Vec<Token>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
@@ -265,6 +270,7 @@ impl OutputNode {
|
||||
OutputOperation::PdfSave
|
||||
| OutputOperation::PdfSetMatrix(_)
|
||||
| OutputOperation::PdfRestore
|
||||
| OutputOperation::PdfLiteral { .. }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -328,6 +328,7 @@ pub enum Primitive {
|
||||
Pdfnormaldeviate,
|
||||
Pdfpageref,
|
||||
Partokenname,
|
||||
Pdfliteral,
|
||||
}
|
||||
|
||||
impl Primitive {
|
||||
@@ -970,6 +971,7 @@ impl Default for State {
|
||||
("pdfnormaldeviate", Pdfnormaldeviate),
|
||||
("pdfpageref", Pdfpageref),
|
||||
("partokenname", Partokenname),
|
||||
("pdfliteral", Pdfliteral),
|
||||
("pdfcolorstack", Pdfcolorstack),
|
||||
("pdfsave", Pdfsave),
|
||||
("pdfstartlink", Pdfstartlink),
|
||||
|
||||
@@ -174,7 +174,9 @@ impl Collector {
|
||||
}
|
||||
}
|
||||
pub fn output(&mut self, n: &OutputNode) {
|
||||
if let OutputOperation::Write { tokens, .. } = &n.operation {
|
||||
if let OutputOperation::Write { tokens, .. }
|
||||
| OutputOperation::PdfLiteral { tokens, .. } = &n.operation
|
||||
{
|
||||
self.usage.token_list_cells += tokens.len();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ struct NativeTextRun {
|
||||
text: String,
|
||||
}
|
||||
impl NativeTextRun {
|
||||
fn flush(run: &mut Option<Self>, content: &mut String) {
|
||||
fn flush(run: &mut Option<Self>, content: &mut PageContent) {
|
||||
if let Some(run) = run.take() {
|
||||
content.push_str(&run.text);
|
||||
if run.expansion == 0 {
|
||||
@@ -607,6 +607,48 @@ fn write_type0_font(
|
||||
type0_id
|
||||
}
|
||||
|
||||
/// The PDF stream can contain an 8-bit TeX literal. Keep its bytes alongside
|
||||
/// the device origin used by subsequent positioned text, rules, and images.
|
||||
#[derive(Default)]
|
||||
struct PageContent {
|
||||
bytes: Vec<u8>,
|
||||
origin: [i64; 2],
|
||||
}
|
||||
|
||||
impl PageContent {
|
||||
fn push_str(&mut self, text: &str) {
|
||||
self.bytes.extend_from_slice(text.as_bytes());
|
||||
}
|
||||
|
||||
fn push(&mut self, byte: u8) {
|
||||
self.bytes.push(byte);
|
||||
}
|
||||
|
||||
fn move_origin(&mut self, point: [i64; 2], units: crate::render::DisplayUnits, digits: u8) {
|
||||
let delta = [point[0] - self.origin[0], point[1] - self.origin[1]];
|
||||
if delta == [0, 0] {
|
||||
return;
|
||||
}
|
||||
let (scale, precision) = match units {
|
||||
crate::render::DisplayUnits::TeX => (6_578_176, digits + 2),
|
||||
crate::render::DisplayUnits::PostScript => (65_536, digits),
|
||||
};
|
||||
let [(h, h_sp), (v, v_sp)] = delta.map(|value| {
|
||||
crate::pdf_device::divide_scaled(value, scale, precision)
|
||||
});
|
||||
if h == 0 && v == 0 {
|
||||
return;
|
||||
}
|
||||
self.origin[0] += h_sp;
|
||||
self.origin[1] += v_sp;
|
||||
self.push_str(&format!(
|
||||
"1 0 0 1 {} {} cm\n",
|
||||
crate::pdf_device::print_decimal(h, digits),
|
||||
crate::pdf_device::print_decimal(v, digits),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn page_content(
|
||||
list: &DisplayList,
|
||||
height: i64,
|
||||
@@ -615,7 +657,7 @@ fn page_content(
|
||||
cm_codes: &[Option<&BTreeMap<char, u8>>],
|
||||
fallback_ids: &[usize; FACE_COUNT],
|
||||
origin: PageOrigin,
|
||||
) -> String {
|
||||
) -> Vec<u8> {
|
||||
let digits = list.pdf.as_ref().map_or(3, |p| p.file.decimal_digits);
|
||||
let pt = |n: i64| {
|
||||
if list.units == crate::render::DisplayUnits::TeX {
|
||||
@@ -624,7 +666,11 @@ fn page_content(
|
||||
pt(n)
|
||||
}
|
||||
};
|
||||
let mut content = String::from("q\n0 0 0 rg\n");
|
||||
use crate::pdf_device::{PdfGraphics, PdfLiteralMode};
|
||||
use crate::render::DisplayUnits;
|
||||
|
||||
let mut content = PageContent::default();
|
||||
content.push_str("q\n0 0 0 rg\n");
|
||||
if list.magnification != 1000 {
|
||||
let ratio = f64::from(list.magnification) / 1000.0;
|
||||
content.push_str(&format!("{ratio:.3} 0 0 {ratio:.3} 0 0 cm\n"));
|
||||
@@ -649,7 +695,29 @@ fn page_content(
|
||||
let mut native_text: Option<NativeTextRun> = None;
|
||||
let mut tex_text: Option<native_text::NativeText> = None;
|
||||
for item in &list.items {
|
||||
if list.units == crate::render::DisplayUnits::TeX {
|
||||
if let DisplayItem::PdfGraphics {
|
||||
x,
|
||||
y,
|
||||
operation: PdfGraphics::Literal { mode, bytes },
|
||||
} = item
|
||||
{
|
||||
NativeTextRun::flush(&mut native_text, &mut content);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
content.bytes.extend_from_slice(bytes);
|
||||
content.push(b'\n');
|
||||
continue;
|
||||
}
|
||||
if list.units == DisplayUnits::TeX {
|
||||
if let DisplayItem::NativeGlyph {
|
||||
x,
|
||||
y,
|
||||
@@ -660,6 +728,9 @@ fn page_content(
|
||||
} = item
|
||||
{
|
||||
assert!(paint.is_some(), "native glyph program must be resolved");
|
||||
if tex_text.is_none() {
|
||||
content.move_origin([0, 0], list.units, digits);
|
||||
}
|
||||
native_text::NativeText::glyph(
|
||||
&mut tex_text,
|
||||
&mut content,
|
||||
@@ -681,7 +752,10 @@ fn page_content(
|
||||
height: rule_height,
|
||||
} = item
|
||||
{
|
||||
native_text::rule(&mut content, *x, *y, *width, *rule_height, height, digits);
|
||||
let [h, v] = content.origin;
|
||||
native_text::rule(
|
||||
&mut content, *x - h, *y + v, *width, *rule_height, height, digits,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -692,6 +766,9 @@ fn page_content(
|
||||
NativeTextRun::flush(&mut native_text, &mut content);
|
||||
}
|
||||
}
|
||||
let [h, v] = content.origin;
|
||||
let px = |x| pt(x - h);
|
||||
let py = |y| pt(height - y - v);
|
||||
match item {
|
||||
DisplayItem::NativeGlyph {
|
||||
x,
|
||||
@@ -721,13 +798,13 @@ fn page_content(
|
||||
expansion: font.expansion,
|
||||
size: *size,
|
||||
y: *y,
|
||||
cursor: pt(*x).parse().unwrap(),
|
||||
cursor: px(*x).parse().unwrap(),
|
||||
point_size: point_size * f64::from(1000 + font.expansion) / 1000.0,
|
||||
text: format!(
|
||||
"BT /N{} {point_size:.4} Tf {spacing}1 0 0 1 {} {} Tm [",
|
||||
font.id.index(),
|
||||
pt(*x),
|
||||
pt(height - *y)
|
||||
px(*x),
|
||||
py(*y)
|
||||
),
|
||||
}
|
||||
});
|
||||
@@ -745,8 +822,8 @@ fn page_content(
|
||||
"BT /M{} {} Tf 1 0 0 1 {} {} Tm <{slot:02X}> Tj ET\n",
|
||||
face.0,
|
||||
pt(*size),
|
||||
pt(*x),
|
||||
pt(height - *y)
|
||||
px(*x),
|
||||
py(*y)
|
||||
));
|
||||
}
|
||||
DisplayItem::Text {
|
||||
@@ -785,8 +862,8 @@ fn page_content(
|
||||
"BT /{} {} Tf 1 0 0 1 {} {} Tm {} Tj ET\n",
|
||||
resource,
|
||||
pt(*size),
|
||||
pt(*x),
|
||||
pt(height - *y),
|
||||
px(*x),
|
||||
py(*y),
|
||||
operand
|
||||
));
|
||||
}
|
||||
@@ -803,8 +880,8 @@ fn page_content(
|
||||
color[0] as f64 / 255.0,
|
||||
color[1] as f64 / 255.0,
|
||||
color[2] as f64 / 255.0,
|
||||
pt(*x),
|
||||
pt(height - *y - *height),
|
||||
px(*x),
|
||||
py(*y + *height),
|
||||
pt(*width),
|
||||
pt(*height)
|
||||
));
|
||||
@@ -817,8 +894,8 @@ fn page_content(
|
||||
} => {
|
||||
content.push_str(&format!(
|
||||
"{} {} {} {} re f\n",
|
||||
pt(*x),
|
||||
pt(height - *y - *rule_height),
|
||||
px(*x),
|
||||
py(*y + *rule_height),
|
||||
pt(*width),
|
||||
pt(*rule_height)
|
||||
));
|
||||
@@ -833,10 +910,10 @@ fn page_content(
|
||||
content.push_str(&format!(
|
||||
"{} w {} {} m {} {} l S\n",
|
||||
pt(*line_width),
|
||||
pt(*x1),
|
||||
pt(height - *y1),
|
||||
pt(*x2),
|
||||
pt(height - *y2)
|
||||
px(*x1),
|
||||
py(*y1),
|
||||
px(*x2),
|
||||
py(*y2)
|
||||
));
|
||||
}
|
||||
DisplayItem::Image {
|
||||
@@ -851,8 +928,8 @@ fn page_content(
|
||||
"q {} 0 0 {} {} {} cm /{name} Do Q\n",
|
||||
pt(*width),
|
||||
pt(*image_height),
|
||||
pt(*x),
|
||||
pt(height - *y - *image_height)
|
||||
px(*x),
|
||||
py(*y + *image_height)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -892,8 +969,8 @@ fn page_content(
|
||||
let name = image.id;
|
||||
content.push_str(&format!(
|
||||
"q {sx} 0 0 {sy} {} {} cm /PI{name} Do Q\n",
|
||||
pt(*x),
|
||||
pt(height - *y - *image_height)
|
||||
px(*x),
|
||||
py(*y + *image_height)
|
||||
));
|
||||
}
|
||||
DisplayItem::Frame {
|
||||
@@ -910,8 +987,8 @@ fn page_content(
|
||||
color[1] as f64 / 255.0,
|
||||
color[2] as f64 / 255.0,
|
||||
*thickness as f64 / 65_536.0,
|
||||
pt(*x),
|
||||
pt(list.height - *y - *height),
|
||||
px(*x),
|
||||
pt(list.height - *y - *height - v),
|
||||
pt(*width),
|
||||
pt(*height)
|
||||
));
|
||||
@@ -928,33 +1005,42 @@ fn page_content(
|
||||
}
|
||||
DisplayItem::Special(special) => {
|
||||
content.push_str(special);
|
||||
content.push('\n');
|
||||
content.push(b'\n');
|
||||
}
|
||||
DisplayItem::PdfColor(program) => {
|
||||
content.push_str(program.literal());
|
||||
content.push('\n');
|
||||
content.push(b'\n');
|
||||
}
|
||||
DisplayItem::PdfGraphics { x, y, operation } => {
|
||||
use crate::pdf_device::PdfGraphics;
|
||||
let device_origin = list.units == DisplayUnits::TeX;
|
||||
if device_origin {
|
||||
content.move_origin([*x, height - *y], list.units, digits);
|
||||
}
|
||||
match operation {
|
||||
PdfGraphics::Save => content.push_str("q\n"),
|
||||
PdfGraphics::Restore { shift: [dx, dy] } => {
|
||||
content.push_str("Q\n");
|
||||
if *dx != 0 || *dy != 0 {
|
||||
content.push_str(&format!("1 0 0 1 {} {} cm\n", pt(*dx), pt(-*dy)));
|
||||
if !device_origin && (*dx != 0 || *dy != 0) {
|
||||
content.push_str(&format!(
|
||||
"1 0 0 1 {} {} cm\n", pt(*dx), pt(-*dy),
|
||||
));
|
||||
}
|
||||
}
|
||||
PdfGraphics::Matrix(matrix) => {
|
||||
let point = |coordinate| {
|
||||
let displayed = pt(coordinate);
|
||||
displayed.parse::<f64>().expect("formatted PDF dimension")
|
||||
let coordinates = if device_origin {
|
||||
[0.0, 0.0]
|
||||
} else {
|
||||
[*x, height - *y].map(|coordinate| {
|
||||
pt(coordinate).parse::<f64>().expect("formatted PDF dimension")
|
||||
})
|
||||
};
|
||||
let [a, b, c, d, e, f] = matrix
|
||||
.about(point(*x), point(height - *y), false)
|
||||
.about(coordinates[0], coordinates[1], false)
|
||||
.0
|
||||
.map(crate::pdf_image::real);
|
||||
content.push_str(&format!("{a} {b} {c} {d} {e} {f} cm\n"));
|
||||
}
|
||||
PdfGraphics::Literal { .. } => unreachable!("literal handled before text"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -962,7 +1048,7 @@ fn page_content(
|
||||
NativeTextRun::flush(&mut native_text, &mut content);
|
||||
native_text::NativeText::finish(&mut tex_text, &mut content);
|
||||
content.push_str("Q\n");
|
||||
content
|
||||
content.bytes
|
||||
}
|
||||
|
||||
/// Document information written into the PDF Info dictionary.
|
||||
@@ -2181,7 +2267,7 @@ fn write_pdf(
|
||||
);
|
||||
objects.push(objects::stream(
|
||||
"",
|
||||
content.as_bytes(),
|
||||
&content,
|
||||
list.pdf.as_ref().map_or(0, |p| p.stream_compression),
|
||||
));
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ mod graphics;
|
||||
pub(crate) use color::{ColorResult, PdfColorStacks};
|
||||
pub use color::{PdfColorProgram, PdfColorStackAction};
|
||||
pub(crate) use graphics::Affine;
|
||||
pub use graphics::{PdfGraphics, PdfMatrix};
|
||||
pub use graphics::{PdfGraphics, PdfLiteralMode, PdfMatrix};
|
||||
pub mod catalog;
|
||||
pub mod links;
|
||||
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
//! Graphics state produced by the pdfTeX extension whatsits.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum PdfLiteralMode {
|
||||
Origin,
|
||||
Page,
|
||||
Direct,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum PdfGraphics {
|
||||
Save,
|
||||
Matrix(PdfMatrix),
|
||||
Restore { shift: [i64; 2] },
|
||||
Literal { mode: PdfLiteralMode, bytes: Arc<[u8]> },
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! Native pdfTeX text cursor, in original TeX sp, before the page matrix.
|
||||
use super::PageContent;
|
||||
use crate::{
|
||||
execution::FontId,
|
||||
native_font::NativeFont,
|
||||
@@ -16,7 +17,7 @@ pub(super) struct NativeText {
|
||||
impl NativeText {
|
||||
pub(super) fn glyph(
|
||||
text: &mut Option<Self>,
|
||||
out: &mut String,
|
||||
out: &mut PageContent,
|
||||
x: i64,
|
||||
y: i64,
|
||||
font: &NativeFont,
|
||||
@@ -84,7 +85,7 @@ impl NativeText {
|
||||
shift = 0;
|
||||
}
|
||||
if !state.opened {
|
||||
out.push('[');
|
||||
out.push(b'[');
|
||||
state.opened = true;
|
||||
}
|
||||
if shift != 0 {
|
||||
@@ -109,13 +110,19 @@ impl NativeText {
|
||||
crate::pdf_device::magnify(advance, 1000 + font.expansion)
|
||||
};
|
||||
}
|
||||
fn close_string(&mut self, out: &mut String) {
|
||||
fn close_string(&mut self, out: &mut PageContent) {
|
||||
if self.opened {
|
||||
out.push_str("] TJ\n");
|
||||
self.opened = false;
|
||||
}
|
||||
}
|
||||
pub(super) fn finish(text: &mut Option<Self>, out: &mut String) {
|
||||
pub(super) fn break_string(text: &mut Option<Self>, out: &mut PageContent) {
|
||||
if let Some(text) = text {
|
||||
text.close_string(out);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn finish(text: &mut Option<Self>, out: &mut PageContent) {
|
||||
if let Some(mut text) = text.take() {
|
||||
text.close_string(out);
|
||||
if text.expansion != 0 {
|
||||
@@ -127,7 +134,7 @@ impl NativeText {
|
||||
}
|
||||
|
||||
pub(super) fn rule(
|
||||
out: &mut String,
|
||||
out: &mut PageContent,
|
||||
x: i64,
|
||||
top: i64,
|
||||
w: i64,
|
||||
|
||||
@@ -301,7 +301,11 @@ impl DisplayList {
|
||||
|| self
|
||||
.items
|
||||
.iter()
|
||||
.any(|item| matches!(item, DisplayItem::PdfImage { .. }))
|
||||
.any(|item| matches!(item, DisplayItem::PdfImage { .. }
|
||||
| DisplayItem::PdfGraphics {
|
||||
operation: crate::pdf_device::PdfGraphics::Literal { .. },
|
||||
..
|
||||
}))
|
||||
}
|
||||
|
||||
/// Compare the inputs consumed by SVG rendering. Font data for glyphs not
|
||||
@@ -653,6 +657,7 @@ impl DisplayList {
|
||||
DisplayItem::PdfGraphics { x, y, operation } => {
|
||||
use crate::pdf_device::PdfGraphics;
|
||||
match operation {
|
||||
PdfGraphics::Literal { .. } => unreachable!("PDF literal requires PDF rendering"),
|
||||
PdfGraphics::Save => {
|
||||
graphics.push((
|
||||
open_transforms,
|
||||
|
||||
@@ -299,6 +299,7 @@ impl SourceMap {
|
||||
for (item_index, item) in page.items.iter().enumerate() {
|
||||
if let DisplayItem::PdfGraphics { x, y, operation } = item {
|
||||
match operation {
|
||||
PdfGraphics::Literal { .. } => {}
|
||||
PdfGraphics::Save => graphics_stack.push(transform),
|
||||
PdfGraphics::Matrix(matrix) => {
|
||||
transform =
|
||||
|
||||
@@ -246,7 +246,7 @@ fn genuine_fraction_primitives_and_retained_boxes_survive_format_roundtrip() {
|
||||
let envelope: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
|
||||
let payload: serde_json::Value =
|
||||
serde_json::from_str(envelope["payload"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(payload["schema"], 37);
|
||||
assert_eq!(payload["schema"], 38);
|
||||
let state = State::initex().with_etex();
|
||||
let loaded = FormatImage::decode(&bytes)
|
||||
.unwrap()
|
||||
|
||||
@@ -334,7 +334,7 @@ fn old_schema_and_missing_unicode_state_are_rejected_even_with_valid_checksums()
|
||||
let envelope: serde_json::Value = serde_json::from_slice(&encoded).unwrap();
|
||||
let original: serde_json::Value =
|
||||
serde_json::from_str(envelope["payload"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(original["schema"], 37);
|
||||
assert_eq!(original["schema"], 38);
|
||||
for (schema, expected) in [
|
||||
(1, "incompatible native format"),
|
||||
(2, "incompatible native format"),
|
||||
|
||||
@@ -164,7 +164,7 @@ fn new_format_owns_vcenter_and_boxed_math_without_reinjecting_old_meanings() {
|
||||
let envelope: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
|
||||
let payload: serde_json::Value =
|
||||
serde_json::from_str(envelope["payload"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(payload["schema"], 37);
|
||||
assert_eq!(payload["schema"], 38);
|
||||
let executor = FormatImage::decode(&bytes)
|
||||
.unwrap()
|
||||
.new_job(
|
||||
|
||||
@@ -1126,6 +1126,33 @@ schema28 更新。schema 1至26和29仍拒绝,27与28缺少必需 Unicode
|
||||
[原样模板记录](PUBLISHER_TEMPLATE_MATRIX.md#aps-revtex-原样双栏样稿)
|
||||
[pdfTeX 的重音布局](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/pdftexdir/pdftex.web#L28084-L28143)
|
||||
|
||||
### 原生 PDF 字面与实际设备原点
|
||||
|
||||
`\pdfliteral` 保留实际列表节点和八位 PDF 字节。普通节点在扫描时展开,
|
||||
`shipout` 节点按实际发页顺序读取当时的宏和状态。默认模式移动 PDF
|
||||
设备原点,`page` 结束文本对象并保留已有原点,`direct` 只关闭当前
|
||||
字形串。显式的矩阵和图形状态栈、文字、规则及图片使用同一设备原点。
|
||||
schema38 保存新增原语和列表节点。包含原始指令的预览页由已发布的原生
|
||||
PDF 生成 SVG。来源映射使用 TeX 的布局坐标与受跟踪的显式矩阵,任意
|
||||
原始 PDF 字面引入的坐标变换还需接入来源映射。
|
||||
[pdfTeX 的字面扫描与出页](https://github.com/TeX-Live/texlive-source/blob/trunk/texk/web2c/pdftexdir/pdftex.web#L18575-L18597)
|
||||
|
||||
两页冻结用例对照实际内容流、两次出页读取的值、同一 PDF 文本对象内
|
||||
的 `direct` 指令及144 DPI灰度图,两页图像逐像素相同。独立字节用例
|
||||
保留了实际 `0xe9`,且丢弃盒中的未定义延迟命令未执行。字面与显式
|
||||
保存、恢复和矩阵混合的第三页对照也逐像素一致,灰度图 SHA-256
|
||||
为 `3a81caa031e393fced824bc4aa29a18927cc206c47c956bafe6b15e42a652923`。
|
||||
|
||||
编辑第二页的延迟展开值时,检查点复用927步,第一次发页前已构建的
|
||||
盒保持有效,只更新第二页。PDF、SVG 和来源映射与独立零复用一致。
|
||||
来源映射仅归一化测试项目根及会话修订号。
|
||||
|
||||
`target/p3-pdf-literal-native` 的回执:
|
||||
|
||||
- `receipt.json` 为 `786c7e5ee75063120fa887daf8af621c0f1185d2836d9b96f018df002ba43fca`。
|
||||
- `checkpoint/receipt.json` 为 `4e53adbb0497ab957c4baab4b8fdf1afaec216af12cd033c2f4a89c2583683e2`。
|
||||
- `graphics-regression.log` 为 `edcd9a0528a7bef897569a6381241c61849067cd58853c29143a9d412db16782`。
|
||||
|
||||
### 原生段落结束 token 和分组上下文
|
||||
|
||||
`\partokenname` 全局选择引擎插入的段落 token,并用实际 token 身份检查
|
||||
|
||||
@@ -459,6 +459,15 @@ alignment command。回溯显示 `\reserved@c` 展开为 `\ifnum 0=` 加
|
||||
`target/p3-arxiv-title-alignment/original-arxiv/receipt.json` 的 SHA-256
|
||||
为 `75a1803375d875d710427f6cf8e36a972657728d0890f5ab96026c9c0ac41762`。
|
||||
|
||||
schema37 优化版使用冻结输入耗时197.5秒生成原样格式,LaTeX 自己把
|
||||
`\partokencontext` 设为2。原样 arXiv 的六个源输入及原字体映射经再次
|
||||
核对。作业越过段落原语,在同一公式结束路径读取 `\leftmarginkern`
|
||||
时停止,该轮未生成 PDF。`target/p3-paragraph-token-native`
|
||||
保留两份实际回执。
|
||||
|
||||
- `format/receipt.json` 为 `cbccbcfa02f2eaeba27662357b093087441fbee999a4c6cebbfbaf31f521691d`。
|
||||
- `original-arxiv/receipt.json` 为 `441d98f0c53f7a46a2696e3e93d7a7efb7620d1e01dfb8ee28d05aa82c50bd79`。
|
||||
|
||||
### Elsevier CAS 双栏首轮输出
|
||||
|
||||
通用展开调度改动通过了实际图像高度与 LaTeX 浮点公式的差分。
|
||||
|
||||
Reference in new issue
Block a user