diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-03 17:27:06 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-03 17:27:06 +0200 |
| commit | 0f5669be51b82e5ab6dbb65aa07444a62b4fa4e9 (patch) | |
| tree | 796d15f302291eeacaaa902d5881207e43e503b6 | |
| parent | dbd4c79c3846aca18a638a4529ad6cb4ba9be0a3 (diff) | |
| parent | a5a0e48dbc924a942dea6b108c628ea7df0d0327 (diff) | |
| download | redot-engine-0f5669be51b82e5ab6dbb65aa07444a62b4fa4e9.tar.gz | |
Merge pull request #82712 from bruvzg/font_collection_name_select
[SystemFont] Check name when selecting the best matching face from a collection.
| -rw-r--r-- | scene/resources/font.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 621b027489..cb9cda59b2 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -3034,14 +3034,19 @@ void SystemFont::_update_base_font() { continue; } - // If it's a font collection check all faces to match requested style. + // If it's a font collection check all faces to match requested style and name. int best_score = 0; for (int i = 0; i < file->get_face_count(); i++) { + int score = 0; file->set_face_index(0, i); + const String n = file->get_font_name(); + if (n.to_upper() == E.to_upper()) { + score += 80; + } BitField<TextServer::FontStyle> style = file->get_font_style(); int font_weight = file->get_font_weight(); int font_stretch = file->get_font_stretch(); - int score = (20 - Math::abs(font_weight - weight) / 50); + score += (20 - Math::abs(font_weight - weight) / 50); score += (20 - Math::abs(font_stretch - stretch) / 10); if (bool(style & TextServer::FONT_ITALIC) == italic) { score += 30; @@ -3060,7 +3065,7 @@ void SystemFont::_update_base_font() { file->set_face_index(0, face_indeces[0]); // If it's a variable font, apply weight, stretch and italic coordinates to match requested style. - if (best_score != 50) { + if (best_score != 150) { Dictionary ftr = file->get_supported_variation_list(); if (ftr.has(TS->name_to_tag("width"))) { ftr_stretch = stretch; |
