Skip to content

Commit 271c987

Browse files
committed
Merge pull request #102647 from bruvzg/el_space
[TextServer] Use all available space when string is too short for ellipsis.
2 parents fa85645 + 316b50b commit 271c987

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

modules/text_server_adv/text_server_adv.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5415,14 +5415,15 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
54155415

54165416
int ell_min_characters = 6;
54175417
double width = sd->width;
5418+
double width_without_el = width;
54185419

54195420
bool is_rtl = sd->para_direction == DIRECTION_RTL;
54205421

54215422
int trim_pos = (is_rtl) ? sd_size : 0;
54225423
int ellipsis_pos = (enforce_ellipsis) ? 0 : -1;
54235424

5424-
int last_valid_cut = 0;
5425-
bool found = false;
5425+
int last_valid_cut = -1;
5426+
int last_valid_cut_witout_el = -1;
54265427

54275428
int glyphs_from = (is_rtl) ? 0 : sd_size - 1;
54285429
int glyphs_to = (is_rtl) ? sd_size - 1 : -1;
@@ -5438,18 +5439,32 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
54385439
}
54395440
if (sd_glyphs[i].count > 0) {
54405441
bool above_min_char_threshold = ((is_rtl) ? sd_size - 1 - i : i) >= ell_min_characters;
5441-
5442+
if (!above_min_char_threshold && last_valid_cut_witout_el != -1) {
5443+
trim_pos = last_valid_cut_witout_el;
5444+
ellipsis_pos = -1;
5445+
width = width_without_el;
5446+
break;
5447+
}
5448+
if (!enforce_ellipsis && width <= p_width && last_valid_cut_witout_el == -1) {
5449+
if (cut_per_word && above_min_char_threshold) {
5450+
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
5451+
last_valid_cut_witout_el = i;
5452+
width_without_el = width;
5453+
}
5454+
} else {
5455+
last_valid_cut_witout_el = i;
5456+
width_without_el = width;
5457+
}
5458+
}
54425459
if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0) <= p_width) {
54435460
if (cut_per_word && above_min_char_threshold) {
54445461
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
54455462
last_valid_cut = i;
5446-
found = true;
54475463
}
54485464
} else {
54495465
last_valid_cut = i;
5450-
found = true;
54515466
}
5452-
if (found) {
5467+
if (last_valid_cut != -1) {
54535468
trim_pos = last_valid_cut;
54545469

54555470
if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) {

modules/text_server_fb/text_server_fb.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,12 +4210,13 @@ void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
42104210

42114211
int ell_min_characters = 6;
42124212
double width = sd->width;
4213+
double width_without_el = width;
42134214

42144215
int trim_pos = 0;
42154216
int ellipsis_pos = (enforce_ellipsis) ? 0 : -1;
42164217

4217-
int last_valid_cut = 0;
4218-
bool found = false;
4218+
int last_valid_cut = -1;
4219+
int last_valid_cut_witout_el = -1;
42194220

42204221
if (enforce_ellipsis && (width + ellipsis_width <= p_width)) {
42214222
trim_pos = -1;
@@ -4226,18 +4227,32 @@ void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
42264227

42274228
if (sd_glyphs[i].count > 0) {
42284229
bool above_min_char_threshold = (i >= ell_min_characters);
4229-
4230+
if (!above_min_char_threshold && last_valid_cut_witout_el != -1) {
4231+
trim_pos = last_valid_cut_witout_el;
4232+
ellipsis_pos = -1;
4233+
width = width_without_el;
4234+
break;
4235+
}
4236+
if (!enforce_ellipsis && width <= p_width && last_valid_cut_witout_el == -1) {
4237+
if (cut_per_word && above_min_char_threshold) {
4238+
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
4239+
last_valid_cut_witout_el = i;
4240+
width_without_el = width;
4241+
}
4242+
} else {
4243+
last_valid_cut_witout_el = i;
4244+
width_without_el = width;
4245+
}
4246+
}
42304247
if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0) <= p_width) {
42314248
if (cut_per_word && above_min_char_threshold) {
42324249
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
42334250
last_valid_cut = i;
4234-
found = true;
42354251
}
42364252
} else {
42374253
last_valid_cut = i;
4238-
found = true;
42394254
}
4240-
if (found) {
4255+
if (last_valid_cut != -1) {
42414256
trim_pos = last_valid_cut;
42424257

42434258
if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) {

0 commit comments

Comments
 (0)