From b59b8bfb352f57d50acd67a048baa8390d37e374 Mon Sep 17 00:00:00 2001 From: bluebear94 Date: Wed, 23 Aug 2023 07:39:22 -0400 Subject: linebreak_optimized: Handle breakpoints separated only by spaces (#1821) --- crates/typst-library/src/layout/par.rs | 17 +++++++++++++++-- tests/ref/layout/par-justify.png | Bin 19571 -> 27297 bytes tests/typ/layout/par-justify.typ | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/typst-library/src/layout/par.rs b/crates/typst-library/src/layout/par.rs index 9e5d4a97..23579105 100644 --- a/crates/typst-library/src/layout/par.rs +++ b/crates/typst-library/src/layout/par.rs @@ -929,9 +929,22 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec = None; // Find the optimal predecessor. - for (i, pred) in table.iter_mut().enumerate().skip(active) { + for (i, pred) in table.iter().enumerate().skip(active) { // Layout the line. let start = pred.line.end; + + // Fix for https://github.com/unicode-org/icu4x/issues/3811 + if i > 0 { + if let Some(s_pred) = table.get(i + 1) { + let next_start = s_pred.line.end; + if !p.bidi.text[start..next_start] + .contains(|c: char| !c.is_whitespace()) + { + continue; + } + } + } + let attempt = line(vt, p, start..end, mandatory, hyphen); // Determine how much the line's spaces would need to be stretched @@ -996,7 +1009,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec