From b58e45ed4379cf74423f5341ae7c52151483504b Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:15:11 +0200 Subject: [PATCH] [TextServer] Fix fallback line breaking code adding two breaks for CR-LF. --- modules/text_server_adv/text_server_adv.cpp | 5 ++++- modules/text_server_fb/text_server_fb.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index ea88278a177a..3da19aaee8ca 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -5360,11 +5360,14 @@ bool TextServerAdvanced::_shaped_text_update_breaks(const RID &p_shaped) { // No data loaded - use fallback. for (int j = r_start; j < r_end; j++) { char32_t c = sd->text[j - sd->start]; + char32_t c_next = (j < r_end) ? sd->text[j - sd->start + 1] : 0x0000; if (is_whitespace(c)) { sd->breaks[j + 1] = false; } if (is_linebreak(c)) { - sd->breaks[j + 1] = true; + if (c != 0x000D || c_next != 0x000A) { // Skip first hard break in CR-LF pair. + sd->breaks[j + 1] = true; + } } } } else { diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index f2d70db7a475..7e34de0bbc67 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -3617,6 +3617,7 @@ bool TextServerFallback::_shaped_text_update_breaks(const RID &p_shaped) { for (int i = 0; i < sd_size; i++) { if (sd_glyphs[i].count > 0) { char32_t c = sd->text[sd_glyphs[i].start - sd->start]; + char32_t c_next = i < sd_size ? sd->text[sd_glyphs[i].start - sd->start + 1] : 0x0000; if (c_punct_size == 0) { if (is_punct(c) && c != 0x005F && c != ' ') { sd_glyphs[i].flags |= GRAPHEME_IS_PUNCTUATION; @@ -3640,7 +3641,9 @@ bool TextServerFallback::_shaped_text_update_breaks(const RID &p_shaped) { } if (is_linebreak(c)) { sd_glyphs[i].flags |= GRAPHEME_IS_SPACE; - sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_HARD; + if (c != 0x000D || c_next != 0x000A) { // Skip first hard break in CR-LF pair. + sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_HARD; + } } if (c == 0x0009 || c == 0x000b) { sd_glyphs[i].flags |= GRAPHEME_IS_TAB;