[TextServer] Use all available space when string is too short for ellipsis.
This commit is contained in:
@ -5415,14 +5415,15 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
|
|||||||
|
|
||||||
int ell_min_characters = 6;
|
int ell_min_characters = 6;
|
||||||
double width = sd->width;
|
double width = sd->width;
|
||||||
|
double width_without_el = width;
|
||||||
|
|
||||||
bool is_rtl = sd->para_direction == DIRECTION_RTL;
|
bool is_rtl = sd->para_direction == DIRECTION_RTL;
|
||||||
|
|
||||||
int trim_pos = (is_rtl) ? sd_size : 0;
|
int trim_pos = (is_rtl) ? sd_size : 0;
|
||||||
int ellipsis_pos = (enforce_ellipsis) ? 0 : -1;
|
int ellipsis_pos = (enforce_ellipsis) ? 0 : -1;
|
||||||
|
|
||||||
int last_valid_cut = 0;
|
int last_valid_cut = -1;
|
||||||
bool found = false;
|
int last_valid_cut_witout_el = -1;
|
||||||
|
|
||||||
int glyphs_from = (is_rtl) ? 0 : sd_size - 1;
|
int glyphs_from = (is_rtl) ? 0 : sd_size - 1;
|
||||||
int glyphs_to = (is_rtl) ? sd_size - 1 : -1;
|
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_
|
|||||||
}
|
}
|
||||||
if (sd_glyphs[i].count > 0) {
|
if (sd_glyphs[i].count > 0) {
|
||||||
bool above_min_char_threshold = ((is_rtl) ? sd_size - 1 - i : i) >= ell_min_characters;
|
bool above_min_char_threshold = ((is_rtl) ? sd_size - 1 - i : i) >= ell_min_characters;
|
||||||
|
if (!above_min_char_threshold && last_valid_cut_witout_el != -1) {
|
||||||
|
trim_pos = last_valid_cut_witout_el;
|
||||||
|
ellipsis_pos = -1;
|
||||||
|
width = width_without_el;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!enforce_ellipsis && width <= p_width && last_valid_cut_witout_el == -1) {
|
||||||
|
if (cut_per_word && above_min_char_threshold) {
|
||||||
|
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
||||||
|
last_valid_cut_witout_el = i;
|
||||||
|
width_without_el = width;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
last_valid_cut_witout_el = i;
|
||||||
|
width_without_el = width;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0) <= p_width) {
|
if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0) <= p_width) {
|
||||||
if (cut_per_word && above_min_char_threshold) {
|
if (cut_per_word && above_min_char_threshold) {
|
||||||
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
||||||
last_valid_cut = i;
|
last_valid_cut = i;
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
last_valid_cut = i;
|
last_valid_cut = i;
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
if (found) {
|
if (last_valid_cut != -1) {
|
||||||
trim_pos = last_valid_cut;
|
trim_pos = last_valid_cut;
|
||||||
|
|
||||||
if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) {
|
if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) {
|
||||||
|
|||||||
@ -4210,12 +4210,13 @@ void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
|
|||||||
|
|
||||||
int ell_min_characters = 6;
|
int ell_min_characters = 6;
|
||||||
double width = sd->width;
|
double width = sd->width;
|
||||||
|
double width_without_el = width;
|
||||||
|
|
||||||
int trim_pos = 0;
|
int trim_pos = 0;
|
||||||
int ellipsis_pos = (enforce_ellipsis) ? 0 : -1;
|
int ellipsis_pos = (enforce_ellipsis) ? 0 : -1;
|
||||||
|
|
||||||
int last_valid_cut = 0;
|
int last_valid_cut = -1;
|
||||||
bool found = false;
|
int last_valid_cut_witout_el = -1;
|
||||||
|
|
||||||
if (enforce_ellipsis && (width + ellipsis_width <= p_width)) {
|
if (enforce_ellipsis && (width + ellipsis_width <= p_width)) {
|
||||||
trim_pos = -1;
|
trim_pos = -1;
|
||||||
@ -4226,18 +4227,32 @@ void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
|
|||||||
|
|
||||||
if (sd_glyphs[i].count > 0) {
|
if (sd_glyphs[i].count > 0) {
|
||||||
bool above_min_char_threshold = (i >= ell_min_characters);
|
bool above_min_char_threshold = (i >= ell_min_characters);
|
||||||
|
if (!above_min_char_threshold && last_valid_cut_witout_el != -1) {
|
||||||
|
trim_pos = last_valid_cut_witout_el;
|
||||||
|
ellipsis_pos = -1;
|
||||||
|
width = width_without_el;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!enforce_ellipsis && width <= p_width && last_valid_cut_witout_el == -1) {
|
||||||
|
if (cut_per_word && above_min_char_threshold) {
|
||||||
|
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
||||||
|
last_valid_cut_witout_el = i;
|
||||||
|
width_without_el = width;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
last_valid_cut_witout_el = i;
|
||||||
|
width_without_el = width;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0) <= p_width) {
|
if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0) <= p_width) {
|
||||||
if (cut_per_word && above_min_char_threshold) {
|
if (cut_per_word && above_min_char_threshold) {
|
||||||
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
|
||||||
last_valid_cut = i;
|
last_valid_cut = i;
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
last_valid_cut = i;
|
last_valid_cut = i;
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
if (found) {
|
if (last_valid_cut != -1) {
|
||||||
trim_pos = last_valid_cut;
|
trim_pos = last_valid_cut;
|
||||||
|
|
||||||
if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) {
|
if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) {
|
||||||
|
|||||||
Reference in New Issue
Block a user