Scope XDV PDF content at the driver page origin

This commit is contained in:
gloamxun committed 2026-11-28 07:25:57 +08:00
1 parent ab6b1093ec
commit 526ec9b3b0
9 files changed
+176 -46

No files matched your search

@@ -10,26 +10,30 @@ pub enum PdfLiteralMode {
Direct,
XdvOrigin,
XdvDirect,
/// XDV page content relative to the special, inside a local graphics state.
XdvContent,
}
impl PdfLiteralMode {
pub(crate) fn xdv_origin(
self,
point: [i64; 2],
page_height: i64,
magnification: i32,
page_origin: [i64; 2],
) -> Option<[i64; 2]> {
match self {
Self::XdvOrigin => Some(point),
Self::XdvDirect => {
let inch = super::unmagnify(4_736_286, magnification);
Some([inch, page_height - inch])
}
Self::XdvOrigin | Self::XdvContent => Some(point),
Self::XdvDirect => Some(page_origin),
_ => None,
}
}
}
/// The XDV device writes content relative to the one-inch page origin.
pub(crate) fn xdv_page_origin(units: DisplayUnits, height: i64, magnification: i32) -> [i64; 2] {
let inch = (72_000. / (units.bp(1) * f64::from(magnification))).round() as i64;
[inch, height - inch]
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum PdfGraphics {
Save,
@@ -83,7 +87,7 @@ 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)]
#[derive(Clone, Copy, Default)]
pub(crate) struct DeviceOrigin([i64; 2]);
impl DeviceOrigin {