BLF: Do Not Cache Unused Rendered Glyphs

The loading of a font size or style renders bitmaps of the characters
0-255 and stores them in a cache. But glyphs 128-255 in this cache are
not accessible. What used to be ansi high-bit characters are now multi-
byte UTF-8 sequences.

Therefore this patch reduces the glyph_ascii_table size to 128 and
only caches characters 32-127, the visible portion of ASCII, which
greatly reduces the time to load a font.

See D12189 for more details.

Differential Revision: https://developer.blender.org/D12189

Reviewed by Campbell Barton
This commit is contained in:
Harley Acheson 2021-08-11 13:55:58 -07:00
parent bb487bc2bc
commit cd1bb63159
2 changed files with 3 additions and 2 deletions

View File

@ -317,7 +317,8 @@ static GlyphBLF **blf_font_ensure_ascii_table(FontBLF *font, GlyphCacheBLF *gc)
/* build ascii on demand */
if (glyph_ascii_table['0'] == NULL) {
GlyphBLF *g;
for (uint i = 0; i < 256; i++) {
/* Skip control characters and just cache rendered glyphs for visible ASCII range. */
for (uint i = 32; i < 128; i++) {
g = blf_glyph_search(gc, i);
if (!g) {
FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);

View File

@ -71,7 +71,7 @@ typedef struct GlyphCacheBLF {
ListBase bucket[257];
/* fast ascii lookup */
struct GlyphBLF *glyph_ascii_table[256];
struct GlyphBLF *glyph_ascii_table[128];
/* texture array, to draw the glyphs. */
GPUTexture *texture;