From 5ae220af0611785ca94d758e793fece296eca92b Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Fri, 13 Dec 2024 01:29:53 +0100 Subject: [PATCH] Fix #131743: Consistent Fallback Font Search Order Currently when a character is requested that is not found in the selected font we first look in other fonts that are already loaded that include some of the requested Unicode range. If not found in any of those we then look in unloaded fonts. But multiple fonts often have overlapping coverage, so this means you can sometimes get a character from different fonts depending on the order they are requested. Since the design of that character could differ, this can lead to visual changes. This PR changes the fallback search to do so in a consistent order, not favoring loaded or unloaded. This does not lead to any measurable performance changes in testing. Pull Request: https://projects.blender.org/blender/blender/pulls/131812 --- source/blender/blenfont/intern/blf_glyph.cc | 24 +++------------------ 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/source/blender/blenfont/intern/blf_glyph.cc b/source/blender/blenfont/intern/blf_glyph.cc index d27a8d16fca..95ce1707e1d 100644 --- a/source/blender/blenfont/intern/blf_glyph.cc +++ b/source/blender/blenfont/intern/blf_glyph.cc @@ -794,11 +794,11 @@ static FT_UInt blf_glyph_index_from_charcode(FontBLF **font, const uint charcode return 0; } - /* First look in currently-loaded cached fonts that match the coverage bit. Super fast. */ + /* First look in fonts that match the coverage bit. */ int coverage_bit = blf_charcode_to_coverage_bit(charcode); for (int i = 0; i < BLF_MAX_FONT; i++) { FontBLF *f = global_font[i]; - if (!f || f == *font || !(f->face) || !(f->flags & BLF_DEFAULT) || + if (!f || f == *font || !(f->flags & BLF_DEFAULT) || (!((*font)->flags & BLF_MONOSPACED) && (f->flags & BLF_MONOSPACED)) || f->flags & BLF_LAST_RESORT) { @@ -813,25 +813,7 @@ static FT_UInt blf_glyph_index_from_charcode(FontBLF **font, const uint charcode } } - /* Next look only in unloaded fonts that match the coverage bit. */ - for (int i = 0; i < BLF_MAX_FONT; i++) { - FontBLF *f = global_font[i]; - if (!f || f == *font || (f->face) || !(f->flags & BLF_DEFAULT) || - (!((*font)->flags & BLF_MONOSPACED) && (f->flags & BLF_MONOSPACED)) || - f->flags & BLF_LAST_RESORT) - { - continue; - } - if (coverage_bit < 0 || blf_font_has_coverage_bit(f, coverage_bit)) { - glyph_index = blf_get_char_index(f, charcode); - if (glyph_index) { - *font = f; - return glyph_index; - } - } - } - - /* Last look in anything else. Also check if we have a last-resort font. */ + /* Next look in the rest. Also check if we have a last-resort font. */ FontBLF *last_resort = nullptr; for (int i = 0; i < BLF_MAX_FONT; i++) { FontBLF *f = global_font[i];