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
83 lines
3.3 KiB
Rust
83 lines
3.3 KiB
Rust
//! Debug test to trace fingerprint content-sensitivity issue.
|
|
//!
|
|
//! This test prints the intermediate values in fingerprint computation
|
|
//! to diagnose why content_edit fixtures produce identical fingerprints.
|
|
|
|
use pdftract_core::document::parse_pdf_file;
|
|
use std::path::Path;
|
|
|
|
fn main() {
|
|
let v1_path = Path::new("tests/fingerprint/fixtures/content_edit_one_glyph/v1.pdf");
|
|
let v2_path = Path::new("tests/fingerprint/fixtures/content_edit_one_glyph/v2.pdf");
|
|
|
|
println!("=== Content-Sensitivity Debug Test ===\n");
|
|
|
|
// Parse v1.pdf
|
|
println!("Parsing v1.pdf...");
|
|
let (fp1, catalog1, pages1, resolver1) = parse_pdf_file(v1_path)
|
|
.expect("Failed to parse v1.pdf");
|
|
println!(" Fingerprint: {}", fp1);
|
|
println!(" Page count: {}", pages1.len());
|
|
|
|
// Parse v2.pdf
|
|
println!("\nParsing v2.pdf...");
|
|
let (fp2, catalog2, pages2, resolver2) = parse_pdf_file(v2_path)
|
|
.expect("Failed to parse v2.pdf");
|
|
println!(" Fingerprint: {}", fp2);
|
|
println!(" Page count: {}", pages2.len());
|
|
|
|
// Compare page contents
|
|
println!("\n=== Page 0 Contents Comparison ===");
|
|
if let (Some(page1), Some(page2)) = (pages1.first(), pages2.first()) {
|
|
println!(" v1 contents refs: {:?}", page1.contents);
|
|
println!(" v2 contents refs: {:?}", page2.contents);
|
|
|
|
// Resolve and compare content streams
|
|
for (i, (&ref1, &ref2)) in page1.contents.iter().zip(page2.contents.iter()).enumerate() {
|
|
println!("\n Content stream {}:", i);
|
|
|
|
let obj1 = resolver1.resolve(ref1);
|
|
let obj2 = resolver2.resolve(ref2);
|
|
|
|
match (obj1, obj2) {
|
|
(Ok(pdftract_core::parser::object::PdfObject::Stream(s1)),
|
|
Ok(pdftract_core::parser::object::PdfObject::Stream(s2))) => {
|
|
println!(" Both are streams");
|
|
|
|
// Get raw stream lengths
|
|
let raw1 = s1.stream_bytes.len();
|
|
let raw2 = s2.stream_bytes.len();
|
|
println!(" v1 raw stream length: {} bytes", raw1);
|
|
println!(" v2 raw stream length: {} bytes", raw2);
|
|
|
|
// Check if raw bytes differ
|
|
if s1.stream_bytes != s2.stream_bytes {
|
|
println!(" ✓ Raw streams are DIFFERENT");
|
|
} else {
|
|
println!(" ✗ Raw streams are IDENTICAL");
|
|
}
|
|
|
|
// Compare dictionaries
|
|
println!(" v1 dict keys: {:?}", s1.dict.keys().collect::<Vec<_>>());
|
|
println!(" v2 dict keys: {:?}", s2.dict.keys().collect::<Vec<_>>());
|
|
}
|
|
_ => {
|
|
println!(" ✗ One or both are not streams: obj1={:?}, obj2={:?}", obj1.is_ok(), obj2.is_ok());
|
|
}
|
|
}
|
|
}
|
|
|
|
println!("\n v1 media_box: {:?}", page1.media_box);
|
|
println!(" v2 media_box: {:?}", page2.media_box);
|
|
println!("\n v1 rotate: {}", page1.rotate);
|
|
println!(" v2 rotate: {}", page2.rotate);
|
|
}
|
|
|
|
// Final comparison
|
|
println!("\n=== Final Comparison ===");
|
|
if fp1 == fp2 {
|
|
println!(" ✗ FAIL: Fingerprints are IDENTICAL (should be DIFFERENT)");
|
|
} else {
|
|
println!(" ✓ PASS: Fingerprints are DIFFERENT (expected)");
|
|
}
|
|
}
|