diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2020-12-17 09:02:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-17 09:02:01 +0100 |
commit | 9e49dbda2a145165269f07bc4f621211c695de52 (patch) | |
tree | ad77d80e6538f3011b7f54fce936932b698467c7 /modules | |
parent | 933cf114d880651a65082e417c05c77bf771af95 (diff) | |
parent | 06ae77a320ba7b83616e4a30b1f40152bd1d3a82 (diff) |
Merge pull request #44360 from bruvzg/ctl_punct_word_break
Add word breaks on punctuation characters.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/text_server_adv/text_server_adv.cpp | 15 | ||||
-rw-r--r-- | modules/text_server_fb/text_server_fb.cpp | 7 |
2 files changed, 19 insertions, 3 deletions
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 803004f93f..3a706286e5 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -1645,13 +1645,18 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { if (c == 0x0009 || c == 0x000b) { sd_glyphs[i].flags |= GRAPHEME_IS_TAB; } + if (is_whitespace(c)) { + sd_glyphs[i].flags |= GRAPHEME_IS_SPACE; + } + if (u_ispunct(c)) { + sd_glyphs[i].flags |= GRAPHEME_IS_PUNCTUATION; + } if (breaks.has(sd->glyphs[i].start)) { if (breaks[sd->glyphs[i].start]) { sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_HARD; } else { if (is_whitespace(c)) { sd_glyphs[i].flags |= GRAPHEME_IS_BREAK_SOFT; - sd_glyphs[i].flags |= GRAPHEME_IS_SPACE; } else { TextServer::Glyph gl; gl.start = sd_glyphs[i].start; @@ -1766,6 +1771,10 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { shaped_text_update_breaks(p_shaped); } + if (sd->justification_ops_valid) { + return true; // Noting to do. + } + const UChar *data = sd->utf16.ptr(); int32_t data_size = sd->utf16.length(); @@ -1796,9 +1805,9 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { if (ubrk_getRuleStatus(bi) != UBRK_WORD_NONE) { int i = _convert_pos(sd, ubrk_current(bi)); jstops[i + sd->start] = false; - int ks = _generate_kashida_justification_opportunies(sd->text, limit, i) + sd->start; + int ks = _generate_kashida_justification_opportunies(sd->text, limit, i); if (ks != -1) { - jstops[ks] = true; + jstops[ks + sd->start] = true; } limit = i; } diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 383250996d..675d0e5d4d 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -45,6 +45,10 @@ _FORCE_INLINE_ bool is_linebreak(char32_t p_char) { return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029); } +_FORCE_INLINE_ bool is_punct(char32_t p_char) { + return (p_char >= 0x0020 && p_char <= 0x002F) || (p_char >= 0x003A && p_char <= 0x0040) || (p_char >= 0x005B && p_char <= 0x0060) || (p_char >= 0x007B && p_char <= 0x007E) || (p_char >= 0x2000 && p_char <= 0x206F) || (p_char >= 0x3000 && p_char <= 0x303F); +} + /*************************************************************************/ String TextServerFallback::interface_name = "Fallback"; @@ -1029,6 +1033,9 @@ bool TextServerFallback::shaped_text_update_breaks(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]; + if (is_punct(c)) { + sd->glyphs.write[i].flags |= GRAPHEME_IS_PUNCTUATION; + } if (is_whitespace(c) && !is_linebreak(c)) { sd->glyphs.write[i].flags |= GRAPHEME_IS_SPACE; sd->glyphs.write[i].flags |= GRAPHEME_IS_BREAK_SOFT; |