From a7d405b02d2b0c5e8b6f83ebf942b8ccacb19ae6 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 21 Sep 2024 22:14:41 +0100 Subject: [PATCH] Fix: ICUParagraphLayout line wrapping (#12956) In the case where the overflow run is not the start run, and the start run had a partial offset --- src/gfx_layout_icu.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gfx_layout_icu.cpp b/src/gfx_layout_icu.cpp index 9d3dff5f8e..cd03d9791a 100644 --- a/src/gfx_layout_icu.cpp +++ b/src/gfx_layout_icu.cpp @@ -461,9 +461,11 @@ std::unique_ptr ICUParagraphLayout::NextLine(int /* See if there is a good breakpoint inside this run. */ int32_t break_pos = break_iterator->preceding(char_pos + 1); - if (break_pos != icu::BreakIterator::DONE && break_pos > overflow_run->start + this->partial_offset) { + auto overflow_run_start = overflow_run->start; + if (overflow_run == start_run) overflow_run_start += this->partial_offset; + if (break_pos != icu::BreakIterator::DONE && break_pos > overflow_run_start) { /* There is a line-break inside this run that is suitable. */ - new_partial_length = break_pos - overflow_run->start - this->partial_offset; + new_partial_length = break_pos - overflow_run_start; } else if (overflow_run != start_run) { /* There is no suitable line-break in this run, but it is also not * the only run on this line. So we remove the run. */ @@ -472,7 +474,7 @@ std::unique_ptr ICUParagraphLayout::NextLine(int /* There is no suitable line-break and this is the only run on the * line. So we break at the cluster. This is not pretty, but the * best we can do. */ - new_partial_length = char_pos - overflow_run->start - this->partial_offset; + new_partial_length = char_pos - overflow_run_start; } } @@ -520,6 +522,7 @@ std::unique_ptr ICUParagraphLayout::NextLine(int if (new_partial_length > 0) { this->current_run = last_run - 1; + if (this->current_run != start_run) this->partial_offset = 0; this->partial_offset += new_partial_length; } else { this->current_run = last_run;