//! Actual PDF device state shared by execution, painting and serialization. #[derive(Clone, Copy)] pub struct PdfInfo<'a> { pub entries: &'a [u8], pub date: Option<&'a str>, } #[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub struct PdfFileOptions { pub major: i32, pub minor: u8, pub object_compression: u8, pub decimal_digits: u8, pub pk_resolution: u32, } #[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub struct PdfPageData { pub file: PdfFileOptions, pub stream_compression: u8, } /// TeX round_xn_over_d, including signed halfway cases. pub fn magnify(value: i64, mag: i32) -> i64 { let n = i128::from(value) * i128::from(mag); if n < 0 { -((-n + 500) / 1000) as i64 } else { ((n + 500) / 1000) as i64 } } pub fn divide_scaled(value: i64, denominator: i64, digits: u8) -> (i64, i64) { let scale = 10i128.pow(u32::from(digits)); let n = i128::from(value).abs(); let d = i128::from(denominator); let mut q = n * scale / d; let mut rem = n * scale % d; if 2 * rem >= d { q += 1; rem -= d; } let out = n - rem / scale; let sign = if value < 0 { -1 } else { 1 }; ((q as i64) * sign, (out as i64) * sign) } pub fn print_decimal(value: i64, digits: u8) -> String { let scale = 10i64.pow(u32::from(digits)); let sign = if value < 0 { "-" } else { "" }; let n = value.abs(); if digits == 0 { format!("{value}") } else { format!( "{sign}{}.{:0width$}", n / scale, n % scale, width = usize::from(digits) ) } } /// pdfTeX divide_scaled(s, one_hundred_bp, digits+2), printed as bp. pub fn print_sp(value: i64, digits: u8) -> String { let scale = 10i128.pow(u32::from(digits)); let n = i128::from(value).abs() * 100 * scale; let rounded = (n + 3_289_088) / 6_578_176; let sign = if value < 0 && rounded != 0 { "-" } else { "" }; if digits == 0 { format!("{sign}{rounded}") } else { format!( "{sign}{}.{:0width$}", rounded / scale, rounded % scale, width = usize::from(digits) ) } } mod color; mod graphics; pub(crate) use color::{ColorResult, PdfColorStacks}; pub use color::{PdfColorProgram, PdfColorStackAction}; pub(crate) use graphics::Affine; pub use graphics::{PdfGraphics, PdfMatrix}; pub mod catalog; pub mod links;