The indent trigger was using .abs() which fired on both increased indent (non-indented → indented) AND decreased indent (indented → non-indented). This caused drop-cap style paragraphs (indented first line, flush-left continuation) to incorrectly split into two blocks. Per plan Phase 4.4 heuristic #2, indent change should only trigger when the current line is MORE indented (to the right, larger x0) than the block average - i.e., a new paragraph starting after non-indented text. It should NOT trigger for decreased indent (first line indented, rest flush-left). Fix: Remove .abs() and only check if line_x0 - block_avg_x0 > threshold. Tests: - test_indented_first_line_new_block: PASS (non-indented → indented splits) - test_indented_first_line_of_paragraph_not_split: PASS (drop cap stays together) - All 179 line module tests: PASS
55 lines
2.3 KiB
Rust
55 lines
2.3 KiB
Rust
//! Debug test to see what content streams are extracted for the content_edit fixtures
|
|
|
|
use pdftract_core::document::parse_pdf_file;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let fixtures = vec![
|
|
("content_edit_one_glyph/v1.pdf", "Hello World"),
|
|
("content_edit_one_glyph/v2.pdf", "Hello Worl"),
|
|
];
|
|
|
|
for (fixture, expected_text) in fixtures {
|
|
let path = PathBuf::from("tests/fingerprint/fixtures").join(fixture);
|
|
println!("=== {} ===", fixture);
|
|
|
|
match parse_pdf_file(&path) {
|
|
Ok((fingerprint, catalog, pages, resolver)) => {
|
|
println!("Fingerprint: {}", fingerprint);
|
|
println!("Page count: {}", pages.len());
|
|
|
|
for (i, page) in pages.iter().enumerate() {
|
|
println!("Page {}:", i);
|
|
println!(" Contents refs: {:?}", page.contents);
|
|
println!(" MediaBox: {:?}", page.media_box);
|
|
|
|
// Try to resolve and decode content streams
|
|
use pdftract_core::parser::stream::{FileSource, decode_stream, ExtractionOptions};
|
|
use pdftract_core::fingerprint::ContentStreamData;
|
|
|
|
let source = FileSource::open(&path).unwrap();
|
|
let mut decompress_counter = 0u64;
|
|
let opts = ExtractionOptions::default();
|
|
|
|
for &obj_ref in &page.contents {
|
|
match resolver.resolve(obj_ref) {
|
|
Ok(pdf_obj) => {
|
|
println!(" Resolved obj: {:?}", pdf_obj);
|
|
if let pdftract_core::parser::object::PdfObject::Stream(stream) = pdf_obj {
|
|
let decoded = decode_stream(&stream, &source, &opts, &mut decompress_counter);
|
|
println!(" Decoded stream ({} bytes):", decoded.len());
|
|
println!(" {}", String::from_utf8_lossy(&decoded));
|
|
}
|
|
}
|
|
Err(e) => println!(" Failed to resolve: {:?}", e),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Err(e) => {
|
|
println!("Failed to parse: {:?}", e);
|
|
}
|
|
}
|
|
println!();
|
|
}
|
|
}
|