[CTL] Do not break line on the span (e.g. RTL BBCode tag) edges.

This commit is contained in:
bruvzg 2021-01-25 09:34:31 +02:00
parent d39f6386ce
commit eeced6d6f2
No known key found for this signature in database
GPG Key ID: 009E1BFE42239B95
1 changed files with 14 additions and 6 deletions

View File

@ -1602,11 +1602,18 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) {
HashMap<int, bool> breaks; HashMap<int, bool> breaks;
UErrorCode err = U_ZERO_ERROR; UErrorCode err = U_ZERO_ERROR;
for (int i = 0; i < sd->spans.size(); i++) { int i = 0;
UBreakIterator *bi = ubrk_open(UBRK_LINE, sd->spans[i].language.ascii().get_data(), data + _convert_pos_inv(sd, sd->spans[i].start), _convert_pos_inv(sd, sd->spans[i].end - sd->spans[i].start), &err); while (i < sd->spans.size()) {
String language = sd->spans[i].language;
int r_start = sd->spans[i].start;
while (i + 1 < sd->spans.size() && language == sd->spans[i + 1].language) {
i++;
}
int r_end = sd->spans[i].end;
UBreakIterator *bi = ubrk_open(UBRK_LINE, language.ascii().get_data(), data + _convert_pos_inv(sd, r_start), _convert_pos_inv(sd, r_end - r_start), &err);
if (U_FAILURE(err)) { if (U_FAILURE(err)) {
//No data loaded - use fallback. //No data loaded - use fallback.
for (int j = sd->spans[i].start; j < sd->spans[i].end; j++) { for (int j = r_start; j < r_end; j++) {
char32_t c = sd->text[j - sd->start]; char32_t c = sd->text[j - sd->start];
if (is_whitespace(c)) { if (is_whitespace(c)) {
breaks[j] = false; breaks[j] = false;
@ -1617,8 +1624,8 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) {
} }
} else { } else {
while (ubrk_next(bi) != UBRK_DONE) { while (ubrk_next(bi) != UBRK_DONE) {
int pos = _convert_pos(sd, ubrk_current(bi)) + sd->spans[i].start - 1; int pos = _convert_pos(sd, ubrk_current(bi)) + r_start - 1;
if (pos != sd->spans[i].end) { if (pos != r_end) {
if ((ubrk_getRuleStatus(bi) >= UBRK_LINE_HARD) && (ubrk_getRuleStatus(bi) < UBRK_LINE_HARD_LIMIT)) { if ((ubrk_getRuleStatus(bi) >= UBRK_LINE_HARD) && (ubrk_getRuleStatus(bi) < UBRK_LINE_HARD_LIMIT)) {
breaks[pos] = true; breaks[pos] = true;
} else if ((ubrk_getRuleStatus(bi) >= UBRK_LINE_SOFT) && (ubrk_getRuleStatus(bi) < UBRK_LINE_SOFT_LIMIT)) { } else if ((ubrk_getRuleStatus(bi) >= UBRK_LINE_SOFT) && (ubrk_getRuleStatus(bi) < UBRK_LINE_SOFT_LIMIT)) {
@ -1628,6 +1635,7 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) {
} }
} }
ubrk_close(bi); ubrk_close(bi);
i++;
} }
sd->sort_valid = false; sd->sort_valid = false;
@ -1636,7 +1644,7 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) {
const char32_t *ch = sd->text.ptr(); const char32_t *ch = sd->text.ptr();
Glyph *sd_glyphs = sd->glyphs.ptrw(); Glyph *sd_glyphs = sd->glyphs.ptrw();
for (int i = 0; i < sd_size; i++) { for (i = 0; i < sd_size; i++) {
if (sd_glyphs[i].count > 0) { if (sd_glyphs[i].count > 0) {
char32_t c = ch[sd_glyphs[i].start - sd->start]; char32_t c = ch[sd_glyphs[i].start - sd->start];
if (c == 0xfffc) { if (c == 0xfffc) {