From a64a7b3e55954e120037f57405e11bebc487be26 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sun, 8 Nov 2026 23:42:45 +0700 Subject: [PATCH] Test that only an OCR phrase with a usable size is set in one size Visible text keeps its runs' sizes, and a phrase whose size is NaN, zero, negative or infinite falls back to its words' sizes. --- crates/engine/tests/it/ocr_edit.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/engine/tests/it/ocr_edit.rs b/crates/engine/tests/it/ocr_edit.rs index c0dd805ddd..91fe8c2f6e 100644 --- a/crates/engine/tests/it/ocr_edit.rs +++ b/crates/engine/tests/it/ocr_edit.rs @@ -191,6 +191,21 @@ fn an_edited_ocr_phrase_is_drawn_at_one_size() { assert!(lines[1].rect[0] >= lines[0].rect[2] - 0.5, "Example runs into John"); } +/// Only invisible OCR text is set in one phrase size: visible text keeps each run's own size, and +/// a phrase whose size is NaN, zero, negative or infinite falls back to its words' sizes (#3313). +#[test] +fn only_an_ocr_phrase_with_a_usable_size_is_set_in_one_size() { + let (s, id) = uneven_phrase(); + let block = s.get(id).unwrap().text_blocks(0).remove(0); + assert!(block.invisible); + assert_eq!(block.phrase_size(), Some(block.size)); + let visible = pdfcraft_engine::TextBlock { invisible: false, ..block.clone() }; + assert_eq!(visible.phrase_size(), None, "visible text keeps its runs' sizes"); + for size in [f64::NAN, 0.0, -3.0, f64::INFINITY] { + assert_eq!(pdfcraft_engine::TextBlock { size, ..block.clone() }.phrase_size(), None, "a {size} pt phrase falls back to its words"); + } +} + /// Choosing a font sends the phrase through the single-style rewrite, which takes its size from /// the first run: that is the phrase's size too, not the first word's guess. #[test]