Skip to content

Commit de48d9f

Browse files
committed
Merge pull request #98841 from bruvzg/ts_el_load
[TextServer] Only load ellipsis glyph when it's used.
2 parents 3d2f77d + 4daa336 commit de48d9f

File tree

2 files changed

+64
-60
lines changed

2 files changed

+64
-60
lines changed

modules/text_server_adv/text_server_adv.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5264,42 +5264,44 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
52645264

52655265
// Find usable fonts, if fonts from the last glyph do not have required chars.
52665266
RID dot_gl_font_rid = sd_glyphs[sd_size - 1].font_rid;
5267-
if (!_font_has_char(dot_gl_font_rid, sd->el_char)) {
5268-
const Array &fonts = spans[spans.size() - 1].fonts;
5269-
for (int i = 0; i < fonts.size(); i++) {
5270-
if (_font_has_char(fonts[i], sd->el_char)) {
5271-
dot_gl_font_rid = fonts[i];
5272-
found_el_char = true;
5273-
break;
5274-
}
5275-
}
5276-
if (!found_el_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
5277-
const char32_t u32str[] = { sd->el_char, 0 };
5278-
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, u32str);
5279-
if (rid.is_valid()) {
5280-
dot_gl_font_rid = rid;
5281-
found_el_char = true;
5282-
}
5283-
}
5284-
} else {
5285-
found_el_char = true;
5286-
}
5287-
if (!found_el_char) {
5288-
bool found_dot_char = false;
5289-
dot_gl_font_rid = sd_glyphs[sd_size - 1].font_rid;
5290-
if (!_font_has_char(dot_gl_font_rid, '.')) {
5267+
if (add_ellipsis || enforce_ellipsis) {
5268+
if (!_font_has_char(dot_gl_font_rid, sd->el_char)) {
52915269
const Array &fonts = spans[spans.size() - 1].fonts;
52925270
for (int i = 0; i < fonts.size(); i++) {
5293-
if (_font_has_char(fonts[i], '.')) {
5271+
if (_font_has_char(fonts[i], sd->el_char)) {
52945272
dot_gl_font_rid = fonts[i];
5295-
found_dot_char = true;
5273+
found_el_char = true;
52965274
break;
52975275
}
52985276
}
5299-
if (!found_dot_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
5300-
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, ".");
5277+
if (!found_el_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
5278+
const char32_t u32str[] = { sd->el_char, 0 };
5279+
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, u32str);
53015280
if (rid.is_valid()) {
53025281
dot_gl_font_rid = rid;
5282+
found_el_char = true;
5283+
}
5284+
}
5285+
} else {
5286+
found_el_char = true;
5287+
}
5288+
if (!found_el_char) {
5289+
bool found_dot_char = false;
5290+
dot_gl_font_rid = sd_glyphs[sd_size - 1].font_rid;
5291+
if (!_font_has_char(dot_gl_font_rid, '.')) {
5292+
const Array &fonts = spans[spans.size() - 1].fonts;
5293+
for (int i = 0; i < fonts.size(); i++) {
5294+
if (_font_has_char(fonts[i], '.')) {
5295+
dot_gl_font_rid = fonts[i];
5296+
found_dot_char = true;
5297+
break;
5298+
}
5299+
}
5300+
if (!found_dot_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
5301+
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, ".");
5302+
if (rid.is_valid()) {
5303+
dot_gl_font_rid = rid;
5304+
}
53035305
}
53045306
}
53055307
}
@@ -5315,8 +5317,8 @@ void TextServerAdvanced::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
53155317
}
53165318
}
53175319

5318-
int32_t dot_gl_idx = 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;
5319-
Vector2 dot_adv = dot_gl_font_rid.is_valid() ? _font_get_glyph_advance(dot_gl_font_rid, last_gl_font_size, dot_gl_idx) : Vector2();
5320+
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;
5321+
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();
53205322
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;
53215323
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();
53225324

modules/text_server_fb/text_server_fb.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4077,42 +4077,44 @@ void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
40774077

40784078
// Find usable fonts, if fonts from the last glyph do not have required chars.
40794079
RID dot_gl_font_rid = sd_glyphs[sd_size - 1].font_rid;
4080-
if (!_font_has_char(dot_gl_font_rid, sd->el_char)) {
4081-
const Array &fonts = spans[spans.size() - 1].fonts;
4082-
for (int i = 0; i < fonts.size(); i++) {
4083-
if (_font_has_char(fonts[i], sd->el_char)) {
4084-
dot_gl_font_rid = fonts[i];
4085-
found_el_char = true;
4086-
break;
4087-
}
4088-
}
4089-
if (!found_el_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
4090-
const char32_t u32str[] = { sd->el_char, 0 };
4091-
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, u32str);
4092-
if (rid.is_valid()) {
4093-
dot_gl_font_rid = rid;
4094-
found_el_char = true;
4095-
}
4096-
}
4097-
} else {
4098-
found_el_char = true;
4099-
}
4100-
if (!found_el_char) {
4101-
bool found_dot_char = false;
4102-
dot_gl_font_rid = sd_glyphs[sd_size - 1].font_rid;
4103-
if (!_font_has_char(dot_gl_font_rid, '.')) {
4080+
if (add_ellipsis || enforce_ellipsis) {
4081+
if (!_font_has_char(dot_gl_font_rid, sd->el_char)) {
41044082
const Array &fonts = spans[spans.size() - 1].fonts;
41054083
for (int i = 0; i < fonts.size(); i++) {
4106-
if (_font_has_char(fonts[i], '.')) {
4084+
if (_font_has_char(fonts[i], sd->el_char)) {
41074085
dot_gl_font_rid = fonts[i];
4108-
found_dot_char = true;
4086+
found_el_char = true;
41094087
break;
41104088
}
41114089
}
4112-
if (!found_dot_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
4113-
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, ".");
4090+
if (!found_el_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
4091+
const char32_t u32str[] = { sd->el_char, 0 };
4092+
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, u32str);
41144093
if (rid.is_valid()) {
41154094
dot_gl_font_rid = rid;
4095+
found_el_char = true;
4096+
}
4097+
}
4098+
} else {
4099+
found_el_char = true;
4100+
}
4101+
if (!found_el_char) {
4102+
bool found_dot_char = false;
4103+
dot_gl_font_rid = sd_glyphs[sd_size - 1].font_rid;
4104+
if (!_font_has_char(dot_gl_font_rid, '.')) {
4105+
const Array &fonts = spans[spans.size() - 1].fonts;
4106+
for (int i = 0; i < fonts.size(); i++) {
4107+
if (_font_has_char(fonts[i], '.')) {
4108+
dot_gl_font_rid = fonts[i];
4109+
found_dot_char = true;
4110+
break;
4111+
}
4112+
}
4113+
if (!found_dot_char && OS::get_singleton()->has_feature("system_fonts") && fonts.size() > 0 && _font_is_allow_system_fallback(fonts[0])) {
4114+
RID rid = _find_sys_font_for_text(fonts[0], String(), spans[spans.size() - 1].language, ".");
4115+
if (rid.is_valid()) {
4116+
dot_gl_font_rid = rid;
4117+
}
41164118
}
41174119
}
41184120
}
@@ -4128,8 +4130,8 @@ void TextServerFallback::_shaped_text_overrun_trim_to_width(const RID &p_shaped_
41284130
}
41294131
}
41304132

4131-
int32_t dot_gl_idx = 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;
4132-
Vector2 dot_adv = dot_gl_font_rid.is_valid() ? _font_get_glyph_advance(dot_gl_font_rid, last_gl_font_size, dot_gl_idx) : Vector2();
4133+
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;
4134+
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();
41334135
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;
41344136
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();
41354137

0 commit comments

Comments
 (0)