@@ -5882,6 +5882,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
58825882 bool add_ellipsis = p_trim_flags.has_flag (OVERRUN_ADD_ELLIPSIS);
58835883 bool cut_per_word = p_trim_flags.has_flag (OVERRUN_TRIM_WORD_ONLY);
58845884 bool enforce_ellipsis = p_trim_flags.has_flag (OVERRUN_ENFORCE_ELLIPSIS);
5885+ bool short_string_ellipsis = p_trim_flags.has_flag (OVERRUN_SHORT_STRING_ELLIPSIS);
58855886 bool justification_aware = p_trim_flags.has_flag (OVERRUN_JUSTIFICATION_AWARE);
58865887
58875888 Glyph *sd_glyphs = sd->glyphs .ptr ();
@@ -5914,7 +5915,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
59145915
59155916 // Find usable fonts, if fonts from the last glyph do not have required chars.
59165917 RID dot_gl_font_rid = sd_glyphs[sd_size - 1 ].font_rid ;
5917- if (add_ellipsis || enforce_ellipsis) {
5918+ if (add_ellipsis || enforce_ellipsis || short_string_ellipsis ) {
59185919 if (!_font_has_char (dot_gl_font_rid, sd->el_char )) {
59195920 const Array &fonts = spans[span_size - 1 ].fonts ;
59205921 for (int i = 0 ; i < fonts.size (); i++) {
@@ -5967,8 +5968,8 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
59675968 }
59685969 }
59695970
5970- int32_t dot_gl_idx = ((add_ellipsis || enforce_ellipsis) && dot_gl_font_rid.is_valid ()) ? _font_get_glyph_index (dot_gl_font_rid, last_gl_font_size, (found_el_char ? sd->el_char : ' .' ), 0 ) : -1 ;
5971- Vector2 dot_adv = ((add_ellipsis || enforce_ellipsis) && dot_gl_font_rid.is_valid ()) ? _font_get_glyph_advance (dot_gl_font_rid, last_gl_font_size, dot_gl_idx) : Vector2 ();
5971+ int32_t dot_gl_idx = ((add_ellipsis || enforce_ellipsis || short_string_ellipsis ) && dot_gl_font_rid.is_valid ()) ? _font_get_glyph_index (dot_gl_font_rid, last_gl_font_size, (found_el_char ? sd->el_char : ' .' ), 0 ) : -1 ;
5972+ Vector2 dot_adv = ((add_ellipsis || enforce_ellipsis || short_string_ellipsis ) && dot_gl_font_rid.is_valid ()) ? _font_get_glyph_advance (dot_gl_font_rid, last_gl_font_size, dot_gl_idx) : Vector2 ();
59725973 int32_t whitespace_gl_idx = whitespace_gl_font_rid.is_valid () ? _font_get_glyph_index (whitespace_gl_font_rid, last_gl_font_size, ' ' , 0 ) : -1 ;
59735974 Vector2 whitespace_adv = whitespace_gl_font_rid.is_valid () ? _font_get_glyph_advance (whitespace_gl_font_rid, last_gl_font_size, whitespace_gl_idx) : Vector2 ();
59745975
@@ -5984,7 +5985,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
59845985 bool is_rtl = sd->para_direction == DIRECTION_RTL;
59855986
59865987 int trim_pos = (is_rtl) ? sd_size : 0 ;
5987- int ellipsis_pos = (enforce_ellipsis) ? 0 : -1 ;
5988+ int ellipsis_pos = (enforce_ellipsis || short_string_ellipsis ) ? 0 : -1 ;
59885989
59895990 int last_valid_cut = -1 ;
59905991 int last_valid_cut_witout_el = -1 ;
@@ -5993,7 +5994,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
59935994 int glyphs_to = (is_rtl) ? sd_size - 1 : -1 ;
59945995 int glyphs_delta = (is_rtl) ? +1 : -1 ;
59955996
5996- if (enforce_ellipsis && (width + ellipsis_width <= p_width)) {
5997+ if (( enforce_ellipsis || short_string_ellipsis) && (width + ellipsis_width <= p_width)) {
59975998 trim_pos = -1 ;
59985999 ellipsis_pos = (is_rtl) ? 0 : sd_size;
59996000 } else {
@@ -6009,7 +6010,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
60096010 width = width_without_el;
60106011 break ;
60116012 }
6012- if (!enforce_ellipsis && width <= p_width && last_valid_cut_witout_el == -1 ) {
6013+ if (!( enforce_ellipsis || short_string_ellipsis) && width <= p_width && last_valid_cut_witout_el == -1 ) {
60136014 if (cut_per_word && above_min_char_threshold) {
60146015 if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
60156016 last_valid_cut_witout_el = i;
@@ -6020,7 +6021,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
60206021 width_without_el = width;
60216022 }
60226023 }
6023- if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis) ? ellipsis_width : 0 ) <= p_width) {
6024+ if (width + (((above_min_char_threshold && add_ellipsis) || enforce_ellipsis || short_string_ellipsis ) ? ellipsis_width : 0 ) <= p_width) {
60246025 if (cut_per_word && above_min_char_threshold) {
60256026 if ((sd_glyphs[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) {
60266027 last_valid_cut = i;
@@ -6031,7 +6032,7 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
60316032 if (last_valid_cut != -1 ) {
60326033 trim_pos = last_valid_cut;
60336034
6034- if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis) && width - ellipsis_width <= p_width) {
6035+ if (add_ellipsis && (above_min_char_threshold || enforce_ellipsis || short_string_ellipsis ) && width - ellipsis_width <= p_width) {
60356036 ellipsis_pos = trim_pos;
60366037 }
60376038 break ;
@@ -6046,12 +6047,12 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
60466047
60476048 sd->overrun_trim_data .trim_pos = trim_pos;
60486049 sd->overrun_trim_data .ellipsis_pos = ellipsis_pos;
6049- if (trim_pos == 0 && enforce_ellipsis && add_ellipsis) {
6050+ if (trim_pos == 0 && ( enforce_ellipsis || short_string_ellipsis) && add_ellipsis) {
60506051 sd->overrun_trim_data .ellipsis_pos = 0 ;
60516052 }
60526053
6053- if ((trim_pos >= 0 && sd->width > p_width) || enforce_ellipsis) {
6054- if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis)) {
6054+ if ((trim_pos >= 0 && sd->width > p_width) || enforce_ellipsis || short_string_ellipsis ) {
6055+ if (add_ellipsis && (ellipsis_pos > 0 || enforce_ellipsis || short_string_ellipsis )) {
60556056 // Insert an additional space when cutting word bound for aesthetics.
60566057 if (cut_per_word && (ellipsis_pos > 0 )) {
60576058 Glyph gl;
0 commit comments