pdftract/debug_fingerprint.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

38 lines
1.7 KiB
Rust

// Debug script to check content stream bytes
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");
// Simple: just read the files and print the raw bytes around content streams
let v1_bytes = std::fs::read(v1_path).expect("Failed to read v1");
let v2_bytes = std::fs::read(v2_path).expect("Failed to read v2");
// Find content stream markers
println!("=== v1.pdf content stream ===");
if let Some(pos) = v1_bytes.windows(3).position(|w| w == b"end") {
// Look for the stream content
let stream_start = v1_bytes.windows(6).position(|w| w == b"stream").unwrap_or(0);
if stream_start > 0 {
let after_newline = stream_start + 6;
while after_newline < v1_bytes.len() && v1_bytes[after_newline] == b'\r' || v1_bytes[after_newline] == b'\n' {
// skip whitespace
}
let endstream = v1_bytes.windows(9).position(|w| w == b"endstream").unwrap_or(v1_bytes.len());
println!("Stream bytes: {:?}", &v1_bytes[stream_start+6..stream_start+200]);
}
}
// Just search for the string literal "(Hello" in both files
println!("\n=== Searching for '(Hello' ===");
let v1_hello = v1_bytes.windows(6).position(|w| w == b"(Hello").unwrap_or(usize::MAX);
let v2_hello = v2_bytes.windows(6).position(|w| w == b"(Hello").unwrap_or(usize::MAX);
if v1_hello < v1_bytes.len() {
println!("v1 found at {}: {:?}", v1_hello, &v1_bytes[v1_hello..v1_hello+20]));
}
if v2_hello < v2_bytes.len() {
println!("v2 found at {}: {:?}", v2_hello, &v2_bytes[v2_hello..v2_hello+20]));
}
}