Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

[TextServer] Fix font face selection and name update.

Pāvels Nadtočajevs9574b10bbc60
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index cfda76a6bff..1998d89d7d2 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -1737,6 +1737,7 @@ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_font_data, const
unsigned int num_entries = 0;
const hb_ot_name_entry_t *names = hb_ot_name_list_names(hb_face, &num_entries);
+ p_font_data->font_name = String();
for (unsigned int i = 0; i < num_entries; i++) {
if (names[i].name_id != HB_OT_NAME_ID_FONT_FAMILY) {
continue;
@@ -2332,6 +2333,10 @@ void TextServerAdvanced::_font_set_face_index(const RID &p_font_rid, int64_t p_f
if (fd->face_index != p_face_index) {
fd->face_index = p_face_index;
_font_clear_cache(fd);
+ if (fd->face) {
+ FT_Done_Face(fd->face);
+ fd->face = nullptr;
+ }
}
}
diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp
index 8a516a71970..775df134a51 100644
--- a/modules/text_server_fb/text_server_fb.cpp
+++ b/modules/text_server_fb/text_server_fb.cpp
@@ -946,6 +946,7 @@ bool TextServerFallback::_ensure_cache_for_size(FontFallback *p_font_data, const
// When a font does not provide a `family_name`, FreeType tries to synthesize one based on other names.
// FreeType automatically converts non-ASCII characters to "?" in the synthesized name.
// To avoid that behavior, use the format-specific name directly if available.
+ p_font_data->font_name = String();
if (FT_IS_SFNT(p_font_data->face)) {
int name_count = FT_Get_Sfnt_Name_Count(p_font_data->face);
for (int i = 0; i < name_count; i++) {
@@ -1201,6 +1202,10 @@ void TextServerFallback::_font_set_face_index(const RID &p_font_rid, int64_t p_f
if (fd->face_index != p_face_index) {
fd->face_index = p_face_index;
_font_clear_cache(fd);
+ if (fd->face) {
+ FT_Done_Face(fd->face);
+ fd->face = nullptr;
+ }
}
}