Tests: use a 300 DPI scan for OCR searchability (#1197)

This commit is contained in:
Earl Co authored and GitHub committed 2026-10-15 02:16:45 -04:00
1 parent 039706c437
commit fc601b89e1
1 file changed
+5 -2
+5 -2
View File
@@ -2639,7 +2639,8 @@ fn recognize_text_makes_a_scanned_page_searchable() {
let mut s = Session::new().with_clock(|| 1_700_000_000);
let text = s.create_from_text("t", "The quick brown fox jumps over the lazy dog.").unwrap();
let id = s.open("text.pdf", None, text, None).unwrap();
let png = export::Exporter::new(s.get(id).unwrap()).png(0, 150.0).unwrap();
// A typical 300 DPI scan keeps the small leading glyph in "quick" legible to OCR.
let png = export::Exporter::new(s.get(id).unwrap()).png(0, 300.0).unwrap();
let scan = s.create_from_images(&[("scan.png".into(), png)]).unwrap();
let id = s.open("scan.pdf", None, scan, None).unwrap();
assert_eq!(page_texts(&s, id), [""], "a picture has no text");
@@ -2656,7 +2657,9 @@ fn recognize_text_makes_a_scanned_page_searchable() {
let q = words.iter().find(|w| w.text.to_lowercase().contains("quick")).unwrap();
let l = words.iter().find(|w| w.text.to_lowercase().contains("lazy")).unwrap();
let top = |w: &ocr::PlacedWord| w.origin[1] + w.up[1];
assert!(q.origin[0] < l.origin[0] && (top(q) - top(l)).abs() < 3.0, "{q:?} {l:?}");
// OCR boxes can differ by a few pixels at 300 DPI and still sit on the same line.
let line_tolerance = q.up[1].abs().max(l.up[1].abs()) / 4.0;
assert!(q.origin[0] < l.origin[0] && (top(q) - top(l)).abs() < line_tolerance, "{q:?} {l:?}");
// A second pass skips the page: it has text now.
let again = s.recognize_text(id, &[], ocr::OcrSettings::default()).unwrap();