diff options
author | Peter Kim <pk15950@gmail.com> | 2022-09-08 07:00:12 +0300 |
---|---|---|
committer | Peter Kim <pk15950@gmail.com> | 2022-09-08 07:00:12 +0300 |
commit | 00dcfdf916c69672210b006e62d966f1bc2fbeb7 (patch) | |
tree | 0cbb1b91fe26c750197126085b74224a795a103c /source/blender/blenfont/intern/blf_thumbs.c | |
parent | a39532670f6b668da7be5810fb1f844b82feeba3 (diff) | |
parent | d5934974219135102f364f57c45a8b1465e2b8d9 (diff) |
Merge branch 'master' into xr-devxr-dev
Diffstat (limited to 'source/blender/blenfont/intern/blf_thumbs.c')
-rw-r--r-- | source/blender/blenfont/intern/blf_thumbs.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c index a75072f854f..bafa927a440 100644 --- a/source/blender/blenfont/intern/blf_thumbs.c +++ b/source/blender/blenfont/intern/blf_thumbs.c @@ -32,26 +32,34 @@ void BLF_thumb_preview(const char *filepath, const char **draw_str, const char **i18n_draw_str, - const unsigned char draw_str_lines, + const uchar draw_str_lines, const float font_color[4], const int font_size, - unsigned char *buf, - int w, - int h, - int channels) + uchar *buf, + const int w, + const int h, + const int channels) { - const unsigned int dpi = 72; + const uint dpi = 72; const int font_size_min = 6; int font_size_curr; /* shrink 1/th each line */ int font_shrink = 4; - FontBLF *font; + /* While viewing thumbnails in font directories this function can be called simultaneously from a + * greater number of threads than we want the FreeType cache to keep open at a time. Therefore + * pass own FT_Library to font creation so that it is not managed by the FreeType cache system. + */ - /* Create a new blender font obj and fill it with default values */ - font = blf_font_new("thumb_font", filepath); + FT_Library ft_library = NULL; + if (FT_Init_FreeType(&ft_library) != FT_Err_Ok) { + return; + } + + FontBLF *font = blf_font_new_ex("thumb_font", filepath, NULL, 0, ft_library); if (!font) { printf("Info: Can't load font '%s', no preview possible\n", filepath); + FT_Done_FreeType(ft_library); return; } @@ -87,7 +95,7 @@ void BLF_thumb_preview(const char *filepath, font->pos[1] -= (int)((float)blf_font_ascender(font) * 1.1f); /* We fallback to default english strings in case not enough chars are available in current - * font for given translated string (useful in non-latin i18n context, like Chinese, + * font for given translated string (useful in non-Latin i18n context, like Chinese, * since many fonts will then show nothing but ugly 'missing char' in their preview). * Does not handle all cases, but much better than nothing. */ @@ -102,4 +110,5 @@ void BLF_thumb_preview(const char *filepath, blf_draw_buffer__end(); blf_font_free(font); + FT_Done_FreeType(ft_library); } |