pdftract/examples/debug_png_pred15.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

47 lines
1.9 KiB
Rust

use pdftract_core::parser::stream::FlateDecoder;
use pdftract_core::parser::object::PdfObject;
use indexmap::IndexMap;
fn main() {
let input = std::fs::read("tests/stream_decoder/fixtures/flate_png_pred15_all_six.bin")
.expect("fixture should exist");
let expected = std::fs::read("tests/stream_decoder/fixtures/flate_png_pred15_all_six.expected")
.expect("expected should exist");
// Create PNG predictor params: predictor=15, columns=8, colors=1, bits=8
let mut dict = IndexMap::new();
dict.insert("/Predictor".into(), PdfObject::Integer(15));
dict.insert("/Columns".into(), PdfObject::Integer(8));
dict.insert("/Colors".into(), PdfObject::Integer(1));
dict.insert("/BitsPerComponent".into(), PdfObject::Integer(8));
let params = PdfObject::Dict(Box::new(dict));
let mut counter = 0u64;
let result = FlateDecoder.decode(&input, Some(&params), &mut counter, u64::MAX);
match result {
Ok(decoded) => {
eprintln!("Expected: {:?}", String::from_utf8_lossy(&expected));
eprintln!("Got: {:?}", String::from_utf8_lossy(&decoded));
eprintln!("Expected bytes: {:?}", expected);
eprintln!("Got bytes: {:?}", decoded.as_slice());
if decoded == expected.as_slice() {
eprintln!("SUCCESS: Output matches!");
} else {
eprintln!("FAILURE: Output does not match!");
for (i, (exp, got)) in expected.iter().zip(decoded.iter()).enumerate() {
if exp != got {
eprintln!(" Mismatch at byte {}: expected 0x{:02x}, got 0x{:02x}", i, exp, got);
}
}
if decoded.len() != expected.len() {
eprintln!(" Length mismatch: expected {}, got {}", expected.len(), decoded.len());
}
}
}
Err(e) => {
eprintln!("Decode error: {}", e);
}
}
}