mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-28 12:08:46 -06:00
refactor(engine): move the page filters to page_filter.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fc6072154d
commit
8ca4bf641f
@@ -38,6 +38,7 @@ pub mod links;
|
||||
pub mod ocr;
|
||||
mod open;
|
||||
pub mod optimizer;
|
||||
mod page_filter;
|
||||
mod pictures;
|
||||
pub mod print_raster;
|
||||
pub mod printcheck;
|
||||
@@ -162,6 +163,7 @@ pub use fill_sign::{displayed_offset, text_box_at, typed_signature_graphic, type
|
||||
pub use history::Label;
|
||||
use layers::{apply_layer_state, set_default_layer_state, use_layer_choices};
|
||||
pub use open::{OpenContext, PreparedDocument};
|
||||
pub use page_filter::{PageOrientation, PageParity, filter_pages};
|
||||
pub use pictures::MarkFile;
|
||||
use pictures::{embed_image, fit_picture, mark_source};
|
||||
use protection::unrestricted;
|
||||
@@ -269,43 +271,3 @@ pub struct OptimizeReport {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// Page filters of Acrobat's Rotate Pages and page selection: even/odd page numbers and
|
||||
/// orientation (as displayed).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub enum PageParity {
|
||||
#[default]
|
||||
Both,
|
||||
Even,
|
||||
Odd,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub enum PageOrientation {
|
||||
#[default]
|
||||
Both,
|
||||
Landscape,
|
||||
Portrait,
|
||||
}
|
||||
|
||||
/// The pages of `pages` (0-based) that pass the filters.
|
||||
pub fn filter_pages(info: &pdfcraft_render::DocInfo, pages: &[usize], parity: PageParity, orientation: PageOrientation) -> Vec<usize> {
|
||||
pages
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|p| match parity {
|
||||
PageParity::Both => true,
|
||||
// Page numbers are 1-based: index 1 is page 2, an even page.
|
||||
PageParity::Even => p % 2 == 1,
|
||||
PageParity::Odd => p % 2 == 0,
|
||||
})
|
||||
.filter(|p| {
|
||||
let Some(pg) = info.pages.get(*p) else { return false };
|
||||
match orientation {
|
||||
PageOrientation::Both => true,
|
||||
PageOrientation::Landscape => pg.width > pg.height,
|
||||
PageOrientation::Portrait => pg.width <= pg.height,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
//! Page filters: even or odd page numbers, and orientation as displayed.
|
||||
|
||||
/// Page filters of Acrobat's Rotate Pages and page selection: even/odd page numbers and
|
||||
/// orientation (as displayed).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub enum PageParity {
|
||||
#[default]
|
||||
Both,
|
||||
Even,
|
||||
Odd,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub enum PageOrientation {
|
||||
#[default]
|
||||
Both,
|
||||
Landscape,
|
||||
Portrait,
|
||||
}
|
||||
|
||||
/// The pages of `pages` (0-based) that pass the filters.
|
||||
pub fn filter_pages(info: &pdfcraft_render::DocInfo, pages: &[usize], parity: PageParity, orientation: PageOrientation) -> Vec<usize> {
|
||||
pages
|
||||
.iter()
|
||||
.copied()
|
||||
.filter(|p| match parity {
|
||||
PageParity::Both => true,
|
||||
// Page numbers are 1-based: index 1 is page 2, an even page.
|
||||
PageParity::Even => p % 2 == 1,
|
||||
PageParity::Odd => p % 2 == 0,
|
||||
})
|
||||
.filter(|p| {
|
||||
let Some(pg) = info.pages.get(*p) else { return false };
|
||||
match orientation {
|
||||
PageOrientation::Both => true,
|
||||
PageOrientation::Landscape => pg.width > pg.height,
|
||||
PageOrientation::Portrait => pg.width <= pg.height,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
Reference in New Issue
Block a user