use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ImageFormat {
Png,
Jpeg,
}
impl ImageFormat {
pub fn extension(self) -> &'static str {
match self {
ImageFormat::Png => "png",
ImageFormat::Jpeg => "jpg",
}
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ToImagesOptions {
pub dpi: u32,
pub format: ImageFormat,
pub pages: Option<(usize, usize)>,
}
impl Default for ToImagesOptions {
fn default() -> Self {
Self {
dpi: 150,
format: ImageFormat::Png,
pages: None,
}
}
}
impl ToImagesOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_dpi(mut self, dpi: u32) -> Self {
self.dpi = dpi;
self
}
pub fn with_format(mut self, format: ImageFormat) -> Self {
self.format = format;
self
}
pub fn with_pages(mut self, from: usize, to: usize) -> Self {
self.pages = Some((from, to));
self
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct CompressOptions {
pub subset_fonts: bool,
pub compress_streams: bool,
pub deduplicate_streams: bool,
pub remove_unused: bool,
}
impl Default for CompressOptions {
fn default() -> Self {
Self {
subset_fonts: true,
compress_streams: true,
deduplicate_streams: true,
remove_unused: true,
}
}
}
impl CompressOptions {
pub fn new() -> Self {
Self::default()
}
pub fn strict() -> Self {
Self {
subset_fonts: true,
compress_streams: true,
deduplicate_streams: true,
remove_unused: true,
}
}
pub fn lossy() -> Self {
Self::strict()
}
pub fn archival() -> Self {
Self {
subset_fonts: true,
compress_streams: true,
deduplicate_streams: true,
remove_unused: false,
}
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct FontSubsetReport {
pub fonts_processed: usize,
pub fonts_subsetted: usize,
pub bytes_saved: usize,
}
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct CompressReport {
pub font_subset: Option<FontSubsetReport>,
pub streams_compressed: usize,
pub streams_deduplicated: usize,
pub unused_removed: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum InsertImageFormat {
Jpeg,
Png,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ImageInsert {
pub bytes: Vec<u8>,
pub format: InsertImageFormat,
pub page: usize,
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
pub opacity: Option<f64>,
}
impl ImageInsert {
pub fn new(
bytes: impl Into<Vec<u8>>,
format: InsertImageFormat,
page: usize,
x: f64,
y: f64,
width: f64,
height: f64,
) -> Self {
Self {
bytes: bytes.into(),
format,
page,
x,
y,
width,
height,
opacity: None,
}
}
pub fn with_opacity(mut self, opacity: f64) -> Self {
self.opacity = Some(opacity.clamp(0.0, 1.0));
self
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ImageInsertReport {
pub pixel_width: u32,
pub pixel_height: u32,
pub resource_name: String,
}
#[derive(Debug, Clone)]
pub struct ToImagesReport {
pub paths: Vec<PathBuf>,
}