fix(edit): reach as high as a larger range's glyphs

With only a range enlarged, row_step is the source leading, so the
styled rewrite's reach rose one source line above its old box while a
120-point range draws far higher, and an image there was missed. The
pitch is now at least 1.2 times the largest size.

The landing test gains a 120-point range on a 12-point OCR line under an
image above the old box; it fails without the floor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SqmHYx8FiWM5PcsoiErgp9
This commit is contained in:
KenM76andClaude Opus 5.5 committed 2026-10-30 03:31:03 -04:00
1 parent 8fd151ff79
commit 8e5f423d6d
2 files changed
+15 -1

No files matched your search

+13
View File
@@ -4579,6 +4579,18 @@ fn an_ocr_rewrite_goes_on_top_of_paint_over_where_it_lands() {
let moved = text::BlockStyle { offset: Some([-290.0, -450.0]), ..Default::default() };
let sized = text::BlockStyle { size: Some(24.0), ..Default::default() };
let spaced = text::BlockStyle { line_spacing: Some(3.0), ..Default::default() };
let range = text::RangeStyle {
range: 0..2,
family: None,
resource: None,
size: Some(120.0),
color: None,
underline: None,
char_spacing: None,
scale: None,
};
let enlarged = text::BlockStyle { ranges: vec![range], ..Default::default() };
let above = "q 200 0 0 60 100 200 cm /Im0 Do Q";
let cases = [
("BT /F1 12 Tf 3 Tr 400 600 Td (Away) Tj ET", "Moved", &moved),
("BT /F1 12 Tf 3 Tr 400 600 Td (Away) Tj ET", "Moved\nTwice", &moved),
@@ -4590,6 +4602,7 @@ fn an_ocr_rewrite_goes_on_top_of_paint_over_where_it_lands() {
let cases = cases.into_iter().map(|(c, e, s)| (c, e, s, scan)).chain([
("BT /F1 12 Tf 3 Tr 110 500 Td (Above) Tj ET", "One\nTwo\nThree\nFour\nFive\nSix", &sized, low),
("BT /F1 12 Tf 3 Tr 110 500 Td (Above) Tj ET", "One\nTwo\nThree\nFour\nFive\nSix", &spaced, low),
("BT /F1 12 Tf 3 Tr 110 150 Td (Hi there) Tj ET", "Hi there", &enlarged, above),
]);
for (content, edit, style, scan) in cases {
let mut doc = image_page_with(&format!("{content} {scan}"));
+2 -1
View File
@@ -824,7 +824,8 @@ pub(crate) fn rewrite_styled_block(
// from the initial state.
let largest =
block.lines.iter().filter_map(|i| lines.get(*i)).map(|l| l.size).chain(style.ranges.iter().filter_map(|r| r.size)).fold(first.size, f64::max);
let pitch = source_leading.max(row_step(style, largest, source_leading));
// At least one line of the largest glyphs, so a larger range reaches up as far as it draws.
let pitch = source_leading.max(row_step(style, largest, source_leading)).max(largest * 1.2);
let widest = measured.iter().copied().fold(width, f64::max);
// This path lays rows out along user-space baselines, so the paragraph is upright here.
let reach = crate::Reach { rect: block.rect, offset: [dx, dy], width: widest, rows: rows.len(), pitch, upright: true };