Skip to content

Commit 8926bf2

Browse files
committed
[TextServer] Fix FontPriorityList returning duplicate fonts.
1 parent 019889d commit 8926bf2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

modules/text_server_adv/text_server_adv.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ class TextServerAdvanced : public TextServerExtension {
709709
struct FontPriorityList {
710710
friend class TextServerAdvanced;
711711

712-
const int MAX_PRIORITY = 2;
712+
const int PRIORITY_SKIP = 100; // Font already used.
713+
const int PRIORITY_MAX = 2;
713714
int current_priority = 0;
714715
uint32_t current_index = 0;
715716
uint32_t font_count = 0;
@@ -733,7 +734,7 @@ class TextServerAdvanced : public TextServerExtension {
733734
fonts.reserve(font_count);
734735
if (font_count > 0) {
735736
fonts.push_back(p_fonts[0]);
736-
unprocessed_fonts[0].second = 0;
737+
unprocessed_fonts[0].second = PRIORITY_SKIP;
737738
current_index++;
738739
}
739740
}
@@ -742,15 +743,15 @@ class TextServerAdvanced : public TextServerExtension {
742743
return font_count;
743744
}
744745

745-
_FORCE_INLINE_ int _get_priority(const RID &font) {
746-
return text_server->_font_is_script_supported(font, *script_code) ? (text_server->_font_is_language_supported(font, *language) ? 0 : 1) : 2;
746+
_FORCE_INLINE_ int _get_priority(const RID &p_font) {
747+
return text_server->_font_is_script_supported(p_font, *script_code) ? (text_server->_font_is_language_supported(p_font, *language) ? 0 : 1) : 2;
747748
}
748749

749-
RID operator[](uint32_t index) {
750-
if (index < fonts.size()) {
751-
return fonts[index];
750+
RID operator[](uint32_t p_index) {
751+
if (p_index < fonts.size()) {
752+
return fonts[p_index];
752753
}
753-
while (current_priority < MAX_PRIORITY || current_index < font_count) {
754+
while (current_priority < PRIORITY_MAX || current_index < font_count) {
754755
if (current_index >= font_count) {
755756
current_priority++;
756757
current_index = 0;
@@ -761,9 +762,10 @@ class TextServerAdvanced : public TextServerExtension {
761762
priority = _get_priority(font);
762763
}
763764
if (priority == current_priority) {
765+
unprocessed_fonts[current_index].second = PRIORITY_SKIP;
764766
fonts.push_back(font);
765-
if (index < fonts.size()) {
766-
return fonts[index];
767+
if (p_index < fonts.size()) {
768+
return fonts[p_index];
767769
}
768770
}
769771
current_index++;

0 commit comments

Comments
 (0)