1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-30 16:26:50 +00:00

Merge pull request #112435 from bruvzg/ts_dup_fonts

[TextServer] Fix `FontPriorityList` returning duplicate fonts.
This commit is contained in:
Thaddeus Crews
2025-11-05 13:05:44 -06:00

View File

@@ -709,7 +709,8 @@ class TextServerAdvanced : public TextServerExtension {
struct FontPriorityList { struct FontPriorityList {
friend class TextServerAdvanced; friend class TextServerAdvanced;
const int MAX_PRIORITY = 2; const int PRIORITY_SKIP = 100; // Font already used.
const int PRIORITY_MAX = 2;
int current_priority = 0; int current_priority = 0;
uint32_t current_index = 0; uint32_t current_index = 0;
uint32_t font_count = 0; uint32_t font_count = 0;
@@ -733,7 +734,7 @@ class TextServerAdvanced : public TextServerExtension {
fonts.reserve(font_count); fonts.reserve(font_count);
if (font_count > 0) { if (font_count > 0) {
fonts.push_back(p_fonts[0]); fonts.push_back(p_fonts[0]);
unprocessed_fonts[0].second = 0; unprocessed_fonts[0].second = PRIORITY_SKIP;
current_index++; current_index++;
} }
} }
@@ -742,15 +743,15 @@ class TextServerAdvanced : public TextServerExtension {
return font_count; return font_count;
} }
_FORCE_INLINE_ int _get_priority(const RID &font) { _FORCE_INLINE_ int _get_priority(const RID &p_font) {
return text_server->_font_is_script_supported(font, *script_code) ? (text_server->_font_is_language_supported(font, *language) ? 0 : 1) : 2; return text_server->_font_is_script_supported(p_font, *script_code) ? (text_server->_font_is_language_supported(p_font, *language) ? 0 : 1) : 2;
} }
RID operator[](uint32_t index) { RID operator[](uint32_t p_index) {
if (index < fonts.size()) { if (p_index < fonts.size()) {
return fonts[index]; return fonts[p_index];
} }
while (current_priority < MAX_PRIORITY || current_index < font_count) { while (current_priority < PRIORITY_MAX || current_index < font_count) {
if (current_index >= font_count) { if (current_index >= font_count) {
current_priority++; current_priority++;
current_index = 0; current_index = 0;
@@ -761,9 +762,10 @@ class TextServerAdvanced : public TextServerExtension {
priority = _get_priority(font); priority = _get_priority(font);
} }
if (priority == current_priority) { if (priority == current_priority) {
unprocessed_fonts[current_index].second = PRIORITY_SKIP;
fonts.push_back(font); fonts.push_back(font);
if (index < fonts.size()) { if (p_index < fonts.size()) {
return fonts[index]; return fonts[p_index];
} }
} }
current_index++; current_index++;