From 54485a66ceb7a7b6eaa584deee5bb76a85ea310f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 19:19:04 +0000 Subject: [PATCH] Test malformed break ordering --- crates/text/src/composer.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/text/src/composer.rs b/crates/text/src/composer.rs index 905d235b4..de1e4f287 100644 --- a/crates/text/src/composer.rs +++ b/crates/text/src/composer.rs @@ -199,7 +199,7 @@ pub fn compose_with( let n = g.len(); // The search assumes increasing break positions when indexing its prefix sums. // Reject malformed candidates before they can make a later line run backwards. - if cands.windows(2).any(|pair| pair[0].end >= pair[1].end) { + if cands.windows(2).any(|pair| pair[0].end > pair[1].end) { return None; } if n == 0 { @@ -358,6 +358,14 @@ mod tests { 0.0 } } + #[test] + fn rejects_breaks_that_move_backwards() { + let glyphs: Vec<_> = "abcd".chars().map(Unit).collect(); + let candidates = [Breakpoint { end: 3, hyphen: 0.0 }, Breakpoint { end: 1, hyphen: 0.0 }]; + let params = Params { justify_last: false, ragged: true, tolerance: 100.0, uniform_from: 0, hyphen_limit: 0 }; + assert_eq!(compose(&glyphs, &|_| 3.0, &|_| 0.0, &|_| 0.0, &candidates, &[] as &[Rigid], ¶ms), None); + } + #[test] fn composes_ragged_paragraph_and_trims_spaces() { let glyphs: Vec<_> = "aa bb cc".chars().map(Unit).collect();