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.c105
1 files changed, 66 insertions, 39 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index a1fcc17ca3f..d4f5be617fd 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"
@@ -62,8 +63,6 @@ int BLF_init(void)
global_font[i] = NULL;
}
- BLF_default_dpi(72);
-
return blf_font_init();
}
@@ -98,8 +97,8 @@ 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];
- if (font && (STREQ(font->name, name))) {
+ const FontBLF *font = global_font[i];
+ if (font && STREQ(font->name, name)) {
return i;
}
}
@@ -118,11 +117,11 @@ static int blf_search_available(void)
return -1;
}
-bool BLF_has_glyph(int fontid, unsigned int unicode)
+bool BLF_has_glyph(int fontid, uint unicode)
{
FontBLF *font = blf_get(fontid);
if (font) {
- return FT_Get_Char_Index(font->face, unicode) != FT_Err_Ok;
+ return blf_get_char_index(font, unicode) != FT_Err_Ok;
}
return false;
}
@@ -163,6 +162,14 @@ int BLF_load_unique(const char *name)
}
FontBLF *font = blf_font_new(name, filepath);
+
+ /* XXX: Temporarily disable kerning in our main font. Kerning had been accidentally removed from
+ * our font in 3.1. In 3.4 we disable kerning here in the new version to keep spacing the same
+ * (T101506). Enable again later with change of font, placement, or rendering - Harley. */
+ if (font && BLI_str_endswith(filepath, BLF_DEFAULT_PROPORTIONAL_FONT)) {
+ font->face_flags &= ~FT_FACE_FLAG_KERNING;
+ }
+
MEM_freeN(filepath);
if (!font) {
@@ -175,7 +182,7 @@ int BLF_load_unique(const char *name)
return i;
}
-void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
+void BLF_metrics_attach(int fontid, uchar *mem, int mem_size)
{
FontBLF *font = blf_get(fontid);
@@ -184,7 +191,7 @@ void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
}
}
-int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size)
+int BLF_load_mem(const char *name, const uchar *mem, int mem_size)
{
int i = blf_search(name);
if (i >= 0) {
@@ -194,7 +201,7 @@ int BLF_load_mem(const char *name, const unsigned char *mem, int mem_size)
return BLF_load_mem_unique(name, mem, mem_size);
}
-int BLF_load_mem_unique(const char *name, const unsigned char *mem, int mem_size)
+int BLF_load_mem_unique(const char *name, const uchar *mem, int mem_size)
{
/*
* Don't search in the cache, make a new object font!
@@ -227,7 +234,7 @@ void BLF_unload(const char *name)
for (int i = 0; i < BLF_MAX_FONT; i++) {
FontBLF *font = global_font[i];
- if (font && (STREQ(font->name, name))) {
+ if (font && STREQ(font->name, name)) {
BLI_assert(font->reference_count > 0);
font->reference_count--;
@@ -360,12 +367,12 @@ void BLF_position(int fontid, float x, float y, float z)
}
}
-void BLF_size(int fontid, float size, int dpi)
+void BLF_size(int fontid, float size)
{
FontBLF *font = blf_get(fontid);
if (font) {
- blf_font_size(font, size, dpi);
+ blf_font_size(font, size);
}
}
@@ -380,7 +387,7 @@ void BLF_blur(int fontid, int size)
}
#endif
-void BLF_color4ubv(int fontid, const unsigned char rgba[4])
+void BLF_color4ubv(int fontid, const uchar rgba[4])
{
FontBLF *font = blf_get(fontid);
@@ -392,7 +399,7 @@ void BLF_color4ubv(int fontid, const unsigned char rgba[4])
}
}
-void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha)
+void BLF_color3ubv_alpha(int fontid, const uchar rgb[3], uchar alpha)
{
FontBLF *font = blf_get(fontid);
@@ -404,13 +411,12 @@ void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char a
}
}
-void BLF_color3ubv(int fontid, const unsigned char rgb[3])
+void BLF_color3ubv(int fontid, const uchar rgb[3])
{
BLF_color3ubv_alpha(fontid, rgb, 255);
}
-void BLF_color4ub(
- int fontid, unsigned char r, unsigned char g, unsigned char b, unsigned char alpha)
+void BLF_color4ub(int fontid, uchar r, uchar g, uchar b, uchar alpha)
{
FontBLF *font = blf_get(fontid);
@@ -422,7 +428,7 @@ void BLF_color4ub(
}
}
-void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b)
+void BLF_color3ub(int fontid, uchar r, uchar g, uchar b)
{
FontBLF *font = blf_get(fontid);
@@ -483,7 +489,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 +517,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();
@@ -565,32 +571,45 @@ int BLF_draw_mono(int fontid, const char *str, const size_t str_len, int cwidth)
return columns;
}
-void BLF_boundbox_foreach_glyph_ex(int fontid,
- const char *str,
- size_t str_len,
- BLF_GlyphBoundsFn user_fn,
- void *user_data,
- struct ResultBLF *r_info)
+void BLF_boundbox_foreach_glyph(
+ int fontid, const char *str, size_t str_len, BLF_GlyphBoundsFn user_fn, void *user_data)
{
FontBLF *font = blf_get(fontid);
- BLF_RESULT_CHECK_INIT(r_info);
-
if (font) {
if (font->flags & BLF_WORD_WRAP) {
/* TODO: word-wrap support. */
BLI_assert(0);
}
else {
- blf_font_boundbox_foreach_glyph(font, str, str_len, user_fn, user_data, r_info);
+ blf_font_boundbox_foreach_glyph(font, str, str_len, user_fn, user_data);
}
}
}
-void BLF_boundbox_foreach_glyph(
- int fontid, const char *str, const size_t str_len, BLF_GlyphBoundsFn user_fn, void *user_data)
+size_t BLF_str_offset_from_cursor_position(int fontid,
+ const char *str,
+ size_t str_len,
+ int location_x)
{
- BLF_boundbox_foreach_glyph_ex(fontid, str, str_len, user_fn, user_data, NULL);
+ FontBLF *font = blf_get(fontid);
+ if (font) {
+ return blf_str_offset_from_cursor_position(font, str, str_len, location_x);
+ }
+ return 0;
+}
+
+bool BLF_str_offset_to_glyph_bounds(int fontid,
+ const char *str,
+ size_t str_offset,
+ rcti *glyph_bounds)
+{
+ FontBLF *font = blf_get(fontid);
+ if (font) {
+ blf_str_offset_to_glyph_bounds(font, str, str_offset, glyph_bounds);
+ return true;
+ }
+ return false;
}
size_t BLF_width_to_strlen(
@@ -815,7 +834,7 @@ void BLF_shadow_offset(int fontid, int x, int y)
void BLF_buffer(int fontid,
float *fbuf,
- unsigned char *cbuf,
+ uchar *cbuf,
int w,
int h,
int nch,
@@ -885,12 +904,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;
}
@@ -902,7 +930,6 @@ void BLF_state_print(int fontid)
printf("fontid %d %p\n", fontid, (void *)font);
printf(" name: '%s'\n", font->name);
printf(" size: %f\n", font->size);
- printf(" dpi: %u\n", font->dpi);
printf(" pos: %d %d %d\n", UNPACK3(font->pos));
printf(" aspect: (%d) %.6f %.6f %.6f\n",
(font->flags & BLF_ROTATION) != 0,