Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenfont/intern/blf.c')
-rw-r--r--source/blender/blenfont/intern/blf.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 36475321d4c..9d9cc51ebcc 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -22,6 +22,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
+#include "BLI_string.h"
#include "BLI_threads.h"
#include "BLF_api.h"
@@ -98,7 +99,7 @@ bool blf_font_id_is_valid(int fontid)
static int blf_search(const char *name)
{
for (int i = 0; i < BLF_MAX_FONT; i++) {
- FontBLF *font = global_font[i];
+ const FontBLF *font = global_font[i];
if (font && (STREQ(font->name, name))) {
return i;
}
@@ -483,7 +484,7 @@ void BLF_batch_draw_end(void)
g_batch.enabled = false;
}
-static void blf_draw_gl__start(FontBLF *font)
+static void blf_draw_gl__start(const FontBLF *font)
{
/*
* The pixmap alignment hack is handle
@@ -511,7 +512,7 @@ static void blf_draw_gl__start(FontBLF *font)
}
}
-static void blf_draw_gl__end(FontBLF *font)
+static void blf_draw_gl__end(const FontBLF *font)
{
if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) != 0) {
GPU_matrix_pop();
@@ -885,12 +886,21 @@ void BLF_draw_buffer(int fontid, const char *str, const size_t str_len)
char *BLF_display_name_from_file(const char *filepath)
{
- FontBLF *font = blf_font_new("font_name", filepath);
- if (!font) {
- return NULL;
+ /* While listing 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 open
+ * with own FT_Library object and use FreeType calls directly to avoid any contention. */
+ char *name = NULL;
+ FT_Library ft_library;
+ if (FT_Init_FreeType(&ft_library) == FT_Err_Ok) {
+ FT_Face face;
+ if (FT_New_Face(ft_library, filepath, 0, &face) == FT_Err_Ok) {
+ if (face->family_name) {
+ name = BLI_sprintfN("%s %s", face->family_name, face->style_name);
+ }
+ FT_Done_Face(face);
+ }
+ FT_Done_FreeType(ft_library);
}
- char *name = blf_display_name(font);
- blf_font_free(font);
return name;
}