Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,128 @@
|
||||
//! Per-shipout device state. Original TeX boxes remain unscaled semantic lists.
|
||||
use super::*;
|
||||
use crate::pdf_device::{PdfColorProgram, PdfGraphics};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ShipoutDevice {
|
||||
pub magnification: i32,
|
||||
/// Page and reference-point coordinates in original TeX sp.
|
||||
pub page_width: i64,
|
||||
pub page_height: i64,
|
||||
pub horizontal_origin: i64,
|
||||
pub vertical_origin: i64,
|
||||
/// None denotes a raw DVI job; native PDF export rejects that backend.
|
||||
pub pdf: Option<crate::pdf_device::PdfPageData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct NativeShipout {
|
||||
pub box_node: NativeBox,
|
||||
pub device: ShipoutDevice,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub(super) pdf_color_start: Vec<Arc<PdfColorProgram>>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub(super) pdf_color_steps: Vec<Option<Arc<PdfColorProgram>>>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub(super) pdf_graphics_steps: Vec<PdfGraphics>,
|
||||
}
|
||||
impl NativeShipout {
|
||||
pub fn display_list(&self) -> Result<crate::render::DisplayList, String> {
|
||||
let mut page = crate::render::DisplayList {
|
||||
width: self.device.page_width,
|
||||
height: self.device.page_height,
|
||||
magnification: self.device.magnification,
|
||||
units: crate::render::DisplayUnits::TeX,
|
||||
pdf: self.device.pdf.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
use crate::{math_engine_tex::MathItem, render::DisplayItem};
|
||||
page.items.extend(
|
||||
self.pdf_color_start
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(DisplayItem::PdfColor),
|
||||
);
|
||||
let mut color_steps = self.pdf_color_steps.iter();
|
||||
let mut graphics_steps = self.pdf_graphics_steps.iter();
|
||||
let mut invalid_geometry = false;
|
||||
let mut missing_color_step = false;
|
||||
let mut missing_graphics_step = false;
|
||||
self.box_node.visit_geometry(|item| {
|
||||
let p = match item {
|
||||
boxes::GeometryItem::Paint(p) => p,
|
||||
boxes::GeometryItem::PdfColor => {
|
||||
match color_steps.next() {
|
||||
Some(Some(program)) => {
|
||||
page.items.push(DisplayItem::PdfColor(program.clone()))
|
||||
}
|
||||
Some(None) => {}
|
||||
None => missing_color_step = true,
|
||||
}
|
||||
return;
|
||||
}
|
||||
boxes::GeometryItem::PdfGraphics { x, y } => {
|
||||
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,
|
||||
});
|
||||
} else {
|
||||
missing_graphics_step = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
if !p.source.tokens.is_empty() {
|
||||
page.sources.insert(page.items.len(), p.source);
|
||||
}
|
||||
let x = self.device.horizontal_origin + p.x;
|
||||
let y = self.device.vertical_origin + self.box_node.height + p.y;
|
||||
page.items.push(match p.item {
|
||||
MathItem::NativeGlyph {
|
||||
font,
|
||||
slot,
|
||||
size,
|
||||
character,
|
||||
..
|
||||
} => DisplayItem::NativeGlyph {
|
||||
x,
|
||||
y,
|
||||
size,
|
||||
font,
|
||||
slot,
|
||||
character,
|
||||
paint: None,
|
||||
},
|
||||
MathItem::Rule { width, height } => DisplayItem::Rule {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
},
|
||||
MathItem::PdfImage(image) => DisplayItem::PdfImage {
|
||||
x,
|
||||
y: y - image.height,
|
||||
width: image.width,
|
||||
height: image.height + image.depth,
|
||||
image,
|
||||
},
|
||||
_ => {
|
||||
invalid_geometry = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
})?;
|
||||
if invalid_geometry {
|
||||
return Err("native shipout requires actual native glyph resources".into());
|
||||
}
|
||||
if missing_color_step || color_steps.next().is_some() {
|
||||
return Err("shipped PDF color order does not match its packed list".into());
|
||||
}
|
||||
if missing_graphics_step || graphics_steps.next().is_some() {
|
||||
return Err("shipped PDF graphics order does not match its packed list".into());
|
||||
}
|
||||
Ok(page)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user