From 2b1364393cfcd09380cf18a221e7cdd325fc4deb Mon Sep 17 00:00:00 2001 From: VladimirPozdnyakov Date: Sun, 25 Oct 2026 19:51:45 +0300 Subject: [PATCH] A test for the edge-tip cap of the merge-back, and the dot-count comment fixed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FredApps' re-review: hanging_marks_of_a_split_run_keep_their_breaks was pinned by the chain guard, not by the at-most-two-cluster cap — reverting the cap alone surprised every hanging test. a_full_mark_row_does_not_ step_back_onto_a_short_line pins the cap: 'word ' followed by thirty hyphens in a 200 px box keeps three rows and the same geometry as hanging off; with the cap reverted the full mark row steps back and the line overflows the box by a row's worth of marks (test fails). The split-run test's comment now matches its 34 dots. --- crates/text/src/tests.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rs index 8bbe2da41e..4460e4d686 100644 --- a/crates/text/src/tests.rs +++ b/crates/text/src/tests.rs @@ -578,7 +578,7 @@ fn a_stepped_mark_row_keeps_its_clusters_and_glyphs_in_step() { fn hanging_marks_of_a_split_run_keep_their_breaks() { let mut e = TextEngine::new(); let mut boxed = |hanging: bool| { - let mut t = point("Loading..................................", 16.0); // 60 dots + let mut t = point("Loading..................................", 16.0); // 34 dots t.shape = TextShape::Box { x: 0.0, y: 0.0, width: 200.0, height: 400.0 }; e.layout(&with_para(t, ParagraphStyle { hanging, ..Default::default() }), 72.0) }; @@ -594,6 +594,33 @@ fn hanging_marks_of_a_split_run_keep_their_breaks() { } } +/// The edge-tip cap pins a case the chain guard alone doesn't: a run of marks pushed whole +/// as one row after a line that does NOT end in a mark. The chain guard only refuses the +/// second mark row onwards, so without the at-most-two-cluster cap that full row would step +/// back up and a `word` followed by thirty hyphens would make a 200 px box overflow by a +/// whole row's worth of marks. With the cap the rows keep their breaks, as with hanging off. +#[test] +fn a_full_mark_row_does_not_step_back_onto_a_short_line() { + let mut e = TextEngine::new(); + let hyphens = "word ------------------------------"; // 30 marks, 200 px holds ~28 + let mut boxed = |hanging: bool| { + let mut t = point(hyphens, 16.0); + t.shape = TextShape::Box { x: 0.0, y: 0.0, width: 200.0, height: 400.0 }; + e.layout(&with_para(t, ParagraphStyle { hanging, ..Default::default() }), 72.0) + }; + let off = boxed(false); + assert!(off.lines.len() >= 3, "the run wraps over rows: {:?}", off.lines); + let on = boxed(true); + assert_eq!(on.lines.len(), off.lines.len(), "the full mark row keeps its break: {:?} vs {:?}", on.lines, off.lines); + for (a, b) in off.lines.iter().zip(&on.lines) { + assert!((a.x0 - b.x0).abs() < 1e-3 && (a.x1 - b.x1).abs() < 1e-3, "same rows either way: {a:?} vs {b:?}"); + } + let adv = on.clusters.iter().map(|c| c.advance).fold(0.0f32, f32::max); + for (i, l) in on.lines.iter().enumerate() { + assert!(l.x1 - l.x0 <= 200.0 + 2.0 * adv + 0.5, "line {i} steps a full mark row back up: {l:?} (tip {adv})"); + } +} + /// The last line of a justified paragraph keeps its own last-line alignment: a marks-only /// row that the box pushed out must not merge into the justified row above, whose placed /// clusters already carry the spread — that would spread the real last line edge to edge