Track PDF literal transforms in native source maps

This commit is contained in:
gloamxun committed 2026-11-21 02:23:12 +08:00
1 parent d46d6d79a8
commit 7f74251c8a
9 files changed
+303 -22

No files matched your search

@@ -1,5 +1,6 @@
//! Graphics state produced by the pdfTeX extension whatsits.
use crate::render::DisplayUnits;
use std::sync::Arc;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
@@ -48,6 +49,41 @@ impl PdfMatrix {
}
}
/// Native device origin in logical scaled units, with the same rounding as
/// the emitted PDF translation. The returned operands have \`digits\` decimals.
#[derive(Default)]
pub(crate) struct DeviceOrigin([i64; 2]);
impl DeviceOrigin {
pub(crate) fn position(&self) -> [i64; 2] {
self.0
}
pub(crate) fn move_to(
&mut self,
point: [i64; 2],
units: DisplayUnits,
digits: u8,
) -> Option<[i64; 2]> {
let delta = [point[0] - self.0[0], point[1] - self.0[1]];
if delta == [0, 0] {
return None;
}
let (scale, precision) = match units {
DisplayUnits::TeX => (6_578_176, digits + 2),
DisplayUnits::PostScript => (65_536, digits),
};
let [(h, h_sp), (v, v_sp)] =
delta.map(|value| super::divide_scaled(value, scale, precision));
if h == 0 && v == 0 {
return None;
}
self.0[0] += h_sp;
self.0[1] += v_sp;
Some([h, v])
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct Affine(pub [f64; 6]);
@@ -174,7 +174,7 @@ impl PdfObjects {
}
}
fn check_pdf_nesting(bytes: &[u8]) -> Result<(), String> {
pub(crate) fn check_pdf_nesting(bytes: &[u8]) -> Result<(), String> {
let mut input = bytes.iter().copied().peekable();
let mut depth = 0usize;
let mut literal = 0usize;