Merge pull request #82712 from bruvzg/font_collection_name_select

[SystemFont] Check name when selecting the best matching face from a collection.
This commit is contained in:
Rémi Verschelde 2023-10-03 17:27:06 +02:00
commit 0f5669be51
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 8 additions and 3 deletions

View File

@ -3034,14 +3034,19 @@ void SystemFont::_update_base_font() {
continue; 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; int best_score = 0;
for (int i = 0; i < file->get_face_count(); i++) { for (int i = 0; i < file->get_face_count(); i++) {
int score = 0;
file->set_face_index(0, i); 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(); BitField<TextServer::FontStyle> style = file->get_font_style();
int font_weight = file->get_font_weight(); int font_weight = file->get_font_weight();
int font_stretch = file->get_font_stretch(); 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); score += (20 - Math::abs(font_stretch - stretch) / 10);
if (bool(style & TextServer::FONT_ITALIC) == italic) { if (bool(style & TextServer::FONT_ITALIC) == italic) {
score += 30; score += 30;
@ -3060,7 +3065,7 @@ void SystemFont::_update_base_font() {
file->set_face_index(0, face_indeces[0]); 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 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(); Dictionary ftr = file->get_supported_variation_list();
if (ftr.has(TS->name_to_tag("width"))) { if (ftr.has(TS->name_to_tag("width"))) {
ftr_stretch = stretch; ftr_stretch = stretch;