pdftract/tests/debug_content_fingerprint_fixtures.rs
jedarden d0f52751ce fix(pdftract-39gey): fix indent trigger to not split drop-cap paragraphs
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
2026-06-07 13:43:19 -04:00

45 lines
1.9 KiB
Rust

//! Debug content fingerprint fixtures
use pdftract_core::document::parse_pdf_file;
fn main() {
env_logger::init();
let test_cases = vec![
("content_edit_one_glyph", "tests/fingerprint/fixtures/content_edit_one_glyph/v1.pdf", "tests/fingerprint/fixtures/content_edit_one_glyph/v2.pdf"),
("content_edit_one_paragraph", "tests/fingerprint/fixtures/content_edit_one_paragraph/v1.pdf", "tests/fingerprint/fixtures/content_edit_one_paragraph/v2.pdf"),
];
for (name, v1_path, v2_path) in test_cases {
println!("\n=== {} ===", name);
let (fp1, catalog1, pages1, _) = parse_pdf_file(std::path::Path::new(v1_path))
.unwrap_or_else(|e| panic!("Failed to parse {}: {}", v1_path, e));
let (fp2, catalog2, pages2, _) = parse_pdf_file(std::path::Path::new(v2_path))
.unwrap_or_else(|e| panic!("Failed to parse {}: {}", v2_path, e));
println!("v1 fingerprint: {}", fp1);
println!("v2 fingerprint: {}", fp2);
println!("Fingerprints match: {}", fp1 == fp2);
println!("v1 page count: {}", pages1.len());
println!("v2 page count: {}", pages2.len());
for (i, (p1, p2)) in pages1.iter().zip(pages2.iter()).enumerate() {
println!("\nPage {}:", i);
println!(" v1 contents refs: {:?}", p1.contents);
println!(" v2 contents refs: {:?}", p2.contents);
println!(" v1 mediabox: {:?}", p1.media_box);
println!(" v2 mediabox: {:?}", p2.media_box);
println!(" v1 rotate: {}", p1.rotate);
println!(" v2 rotate: {}", p2.rotate);
// Check if content refs are the same
if p1.contents == p2.contents {
println!(" WARNING: Contents refs are IDENTICAL");
} else {
println!(" Contents refs are DIFFERENT");
}
}
}
}