Skip to content

A fast, helpful, and open-source document parser

fix: apply content filters in is_complex before the layout pass

apeshimam-hebbia4cba0f24166d
diff --git a/crates/liteparse/src/parser.rs b/crates/liteparse/src/parser.rs
index 6f1581d..042b405 100644
--- a/crates/liteparse/src/parser.rs
+++ b/crates/liteparse/src/parser.rs
@@ -471,7 +471,7 @@ impl LiteParse {
// pass fast (its whole purpose is a cheap pre-OCR check).
let password = self.config.password.as_deref();
- let (pages, mut page_complexities) = {
+ let (mut pages, mut page_complexities) = {
let lib = Library::init();
let document = self.open_document(&lib, &validated_input, password)?;
@@ -536,6 +536,8 @@ impl LiteParse {
// Layout signals come from the real projection pass so they match
// what a full parse will decide.
let t_layout = web_time::Instant::now();
+ // Same order as parse: complexity sees every item, layout the filtered page.
+ stages::apply_content_filters(&mut pages, &self.content_filters());
let parsed_pages = stages::project(pages);
for (stats, page) in page_complexities.iter_mut().zip(&parsed_pages) {
stats.layout = Some(stages::layout_complexity(page));
diff --git a/crates/liteparse/tests/integration_test.rs b/crates/liteparse/tests/integration_test.rs
index 1b0e5eb..bb3b090 100644
--- a/crates/liteparse/tests/integration_test.rs
+++ b/crates/liteparse/tests/integration_test.rs
@@ -1,6 +1,6 @@
use std::path::Path;
-use liteparse::config::OutputFormat;
+use liteparse::config::{CropBox, OutputFormat};
use liteparse::conversion::convert_data_to_pdf;
use liteparse::ocr_merge::ComplexityReason;
use liteparse::types::PdfInput;
@@ -1197,3 +1197,45 @@ async fn test_orientation_correction_rejects_non_cardinal_angle() {
Ok(_) => panic!("45° is not a valid correction and must be rejected"),
}
}
+
+async fn diagonal_column_count(config: LiteParseConfig) -> usize {
+ let stats = LiteParse::new(LiteParseConfig {
+ quiet: true,
+ ..config
+ })
+ .is_complex(PdfInput::Path(
+ "../../integration_tests_data/diagonal_column.pdf".into(),
+ ))
+ .await
+ .expect("is_complex should succeed");
+ stats[0].layout.as_ref().expect("layout stats").column_count
+}
+
+/// `is_complex` honors the same content filters as `parse`, so a column of
+/// diagonal watermark text only counts when it isn't filtered out.
+#[tokio::test]
+#[serial]
+async fn test_is_complex_applies_content_filters() {
+ assert_eq!(diagonal_column_count(LiteParseConfig::default()).await, 2);
+ assert_eq!(
+ diagonal_column_count(LiteParseConfig {
+ skip_diagonal_text: true,
+ ..LiteParseConfig::default()
+ })
+ .await,
+ 1
+ );
+ assert_eq!(
+ diagonal_column_count(LiteParseConfig {
+ crop_box: Some(CropBox {
+ top: 0.0,
+ right: 0.5,
+ bottom: 0.0,
+ left: 0.0,
+ }),
+ ..LiteParseConfig::default()
+ })
+ .await,
+ 1
+ );
+}
diff --git a/integration_tests_data/diagonal_column.pdf b/integration_tests_data/diagonal_column.pdf
new file mode 100644
index 0000000..49b0d49
Binary files /dev/null and b/integration_tests_data/diagonal_column.pdf differ