pub mod config;
pub mod creep;
pub mod layout;
pub mod marks;
pub mod preview;
pub mod sheet;
use super::doc::PdfDoc;
use super::geometry::Size;
use super::Result;
#[derive(Debug, Clone, Copy)]
pub struct ImpositionParams {
pub style: BindingStyle,
pub sheets_per_signature: usize,
pub blank: BlankPolicy,
pub sheet_size: Size,
pub creep: CreepStrategy,
pub paper_thickness_mm: f32,
pub marks: marks::MarkConfig,
pub crop_offset_mm: f32,
pub fold_mark_length_mm: f32,
}
pub fn impose(src: &PdfDoc, params: &ImpositionParams) -> Result<PdfDoc> {
let layout = layout::plan(
params.style,
params.sheets_per_signature,
src.page_count(),
params.blank,
);
sheet::emit(src, &layout, params)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BindingStyle {
SaddleStitch,
PerfectBound,
Concertina,
Stab,
}
impl BindingStyle {
pub fn parse(s: &str) -> Option<Self> {
match s.trim().to_ascii_lowercase().as_str() {
"saddle_stitch" | "saddle-stitch" | "saddle" => Some(Self::SaddleStitch),
"perfect_bound" | "perfect-bound" | "perfect" => Some(Self::PerfectBound),
"concertina" | "accordion" => Some(Self::Concertina),
"stab" | "japanese_stab" | "japanese-stab" => Some(Self::Stab),
_ => None,
}
}
pub fn columns_per_side(self) -> usize {
match self {
Self::Stab | Self::Concertina => 1,
_ => 2,
}
}
pub fn is_folded(self) -> bool {
matches!(self, Self::SaddleStitch | Self::PerfectBound)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BlankPolicy {
Prepend,
Append,
Balance,
Error,
}
impl BlankPolicy {
pub fn parse(s: &str) -> Option<Self> {
match s.trim().to_ascii_lowercase().as_str() {
"prepend" => Some(Self::Prepend),
"append" => Some(Self::Append),
"balance" => Some(Self::Balance),
"error" => Some(Self::Error),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CreepStrategy {
None,
Shingle,
Pushout,
}
impl CreepStrategy {
pub fn parse(s: &str) -> Option<Self> {
match s.trim().to_ascii_lowercase().as_str() {
"none" | "off" => Some(Self::None),
"shingle" => Some(Self::Shingle),
"pushout" | "push_out" | "push-out" => Some(Self::Pushout),
_ => None,
}
}
}