diff options
author | Harley Acheson <harley.acheson@gmail.com> | 2022-02-05 05:32:32 +0300 |
---|---|---|
committer | Harley Acheson <harley.acheson@gmail.com> | 2022-02-05 05:32:32 +0300 |
commit | 835dd950467fe5215911a81485393fb6ce3a03cd (patch) | |
tree | 94d2a6eaeb4f8cbb755ef31b92b417117d461889 /source/blender/blenfont/intern/blf_font.c | |
parent | b1cee3619062124497c73a24c3d87853f544c5f1 (diff) |
BLF: Cleanup blf_glyph_cache_find & blf_font_size
Removes unnecessary calls to blf_glyph_cache_find, simplifies
blf_font_size, and reduces calls to it. blf_glyph_cache_new
and blf_glyph_cache_find made static.
See D13374 for more details.
Differential Revision: https://developer.blender.org/D13374
Reviewed by Campbell Barton
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index da533820d72..c1410447de6 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -1342,35 +1342,25 @@ void blf_font_free(FontBLF *font) /** \name Font Configure * \{ */ -void blf_font_size(FontBLF *font, float size, unsigned int dpi) +bool blf_font_size(FontBLF *font, float size, unsigned int dpi) { - blf_glyph_cache_acquire(font); - /* FreeType uses fixed-point integers in 64ths. */ FT_F26Dot6 ft_size = lroundf(size * 64.0f); - /* Adjust our size to be on even 64ths. */ + /* Adjust our new size to be on even 64ths. */ size = (float)ft_size / 64.0f; - GlyphCacheBLF *gc = blf_glyph_cache_find(font, size, dpi); - if (gc && (font->size == size && font->dpi == dpi)) { - /* Optimization: do not call FT_Set_Char_Size if size did not change. */ - } - else { - const FT_Error err = FT_Set_Char_Size(font->face, 0, ft_size, dpi, dpi); - if (err) { - /* FIXME: here we can go through the fixed size and choice a close one */ - printf("The current font don't support the size, %f and dpi, %u\n", size, dpi); - } - else { + if (font->size != size || font->dpi != dpi) { + if (FT_Set_Char_Size(font->face, 0, ft_size, dpi, dpi) == 0) { font->size = size; font->dpi = dpi; - if (gc == NULL) { - blf_glyph_cache_new(font); - } + } + else { + printf("The current font does not support the size, %f and dpi, %u\n", size, dpi); + return false; } } - blf_glyph_cache_release(font); + return true; } /** \} */ |