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')
-rw-r--r--source/blender/blenfont/BLF_api.h2
-rw-r--r--source/blender/blenfont/intern/blf.c268
-rw-r--r--source/blender/blenfont/intern/blf_dir.c26
-rw-r--r--source/blender/blenfont/intern/blf_font.c282
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c30
-rw-r--r--source/blender/blenfont/intern/blf_lang.c5
-rw-r--r--source/blender/blenfont/intern/blf_util.c8
7 files changed, 253 insertions, 368 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index 57f8c83eda6..00943ace05c 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -66,7 +66,7 @@ void BLF_size(int fontid, int size, int dpi);
| m[3] m[7] m[11] m[15] |
*/
-void BLF_matrix(int fontid, double *m);
+void BLF_matrix(int fontid, const double m[16]);
/* Draw the string using the default font, size and dpi. */
void BLF_draw_default(float x, float y, float z, const char *str, size_t len);
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 577697de594..cccecd00bf7 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -6,7 +6,7 @@
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,7 +20,7 @@
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
- *
+ *
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
@@ -78,8 +78,8 @@ int blf_mono_font_render= -1;
static FontBLF *BLF_get(int fontid)
{
if (fontid >= 0 && fontid < BLF_MAX_FONT)
- return(global_font[fontid]);
- return(NULL);
+ return global_font[fontid];
+ return NULL;
}
int BLF_init(int points, int dpi)
@@ -91,7 +91,7 @@ int BLF_init(int points, int dpi)
global_font_points= points;
global_font_dpi= dpi;
- return(blf_font_init());
+ return blf_font_init();
}
void BLF_exit(void)
@@ -128,9 +128,9 @@ static int blf_search(const char *name)
for (i= 0; i < BLF_MAX_FONT; i++) {
font= global_font[i];
if (font && (!strcmp(font->name, name)))
- return(i);
+ return i;
}
- return(-1);
+ return -1;
}
int BLF_load(const char *name)
@@ -140,24 +140,24 @@ int BLF_load(const char *name)
int i;
if (!name)
- return(-1);
+ return -1;
/* check if we already load this font. */
i= blf_search(name);
if (i >= 0) {
/*font= global_font[i];*/ /*UNUSED*/
- return(i);
+ return i;
}
if (global_font_num+1 >= BLF_MAX_FONT) {
printf("Too many fonts!!!\n");
- return(-1);
+ return -1;
}
filename= blf_dir_search(name);
if (!filename) {
printf("Can't find font: %s\n", name);
- return(-1);
+ return -1;
}
font= blf_font_new(name, filename);
@@ -165,13 +165,13 @@ int BLF_load(const char *name)
if (!font) {
printf("Can't load font: %s\n", name);
- return(-1);
+ return -1;
}
global_font[global_font_num]= font;
i= global_font_num;
global_font_num++;
- return(i);
+ return i;
}
int BLF_load_unique(const char *name)
@@ -181,20 +181,20 @@ int BLF_load_unique(const char *name)
int i;
if (!name)
- return(-1);
+ return -1;
/* Don't search in the cache!! make a new
* object font, this is for keep fonts threads safe.
*/
if (global_font_num+1 >= BLF_MAX_FONT) {
printf("Too many fonts!!!\n");
- return(-1);
+ return -1;
}
filename= blf_dir_search(name);
if (!filename) {
printf("Can't find font: %s\n", name);
- return(-1);
+ return -1;
}
font= blf_font_new(name, filename);
@@ -202,22 +202,22 @@ int BLF_load_unique(const char *name)
if (!font) {
printf("Can't load font: %s\n", name);
- return(-1);
+ return -1;
}
global_font[global_font_num]= font;
i= global_font_num;
global_font_num++;
- return(i);
+ return i;
}
void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font) {
blf_font_attach_from_mem(font, mem, mem_size);
+ }
}
int BLF_load_mem(const char *name, unsigned char *mem, int mem_size)
@@ -226,34 +226,34 @@ int BLF_load_mem(const char *name, unsigned char *mem, int mem_size)
int i;
if (!name)
- return(-1);
+ return -1;
i= blf_search(name);
if (i >= 0) {
/*font= global_font[i];*/ /*UNUSED*/
- return(i);
+ return i;
}
if (global_font_num+1 >= BLF_MAX_FONT) {
printf("Too many fonts!!!\n");
- return(-1);
+ return -1;
}
if (!mem || !mem_size) {
printf("Can't load font: %s from memory!!\n", name);
- return(-1);
+ return -1;
}
font= blf_font_new_from_mem(name, mem, mem_size);
if (!font) {
printf("Can't load font: %s from memory!!\n", name);
- return(-1);
+ return -1;
}
global_font[global_font_num]= font;
i= global_font_num;
global_font_num++;
- return(i);
+ return i;
}
int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
@@ -262,7 +262,7 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
int i;
if (!name)
- return(-1);
+ return -1;
/*
* Don't search in the cache, make a new object font!
@@ -270,67 +270,66 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
*/
if (global_font_num+1 >= BLF_MAX_FONT) {
printf("Too many fonts!!!\n");
- return(-1);
+ return -1;
}
if (!mem || !mem_size) {
printf("Can't load font: %s from memory!!\n", name);
- return(-1);
+ return -1;
}
font= blf_font_new_from_mem(name, mem, mem_size);
if (!font) {
printf("Can't load font: %s from memory!!\n", name);
- return(-1);
+ return -1;
}
global_font[global_font_num]= font;
i= global_font_num;
global_font_num++;
- return(i);
+ return i;
}
void BLF_enable(int fontid, int option)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font) {
font->flags |= option;
+ }
}
void BLF_disable(int fontid, int option)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font) {
font->flags &= ~option;
+ }
}
void BLF_enable_default(int option)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(global_font_default);
- font= BLF_get(global_font_default);
- if (font)
+ if (font) {
font->flags |= option;
+ }
}
void BLF_disable_default(int option)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(global_font_default);
- font= BLF_get(global_font_default);
- if (font)
+ if (font) {
font->flags &= ~option;
+ }
}
void BLF_aspect(int fontid, float x, float y, float z)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
font->aspect[0]= x;
font->aspect[1]= y;
@@ -338,26 +337,23 @@ void BLF_aspect(int fontid, float x, float y, float z)
}
}
-void BLF_matrix(int fontid, double *m)
+void BLF_matrix(int fontid, const double m[16])
{
- FontBLF *font;
- int i;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
- for (i= 0; i < 16; i++)
- font->m[i]= m[i];
+ memcpy(font->m, m, sizeof(font->m));
}
}
void BLF_position(int fontid, float x, float y, float z)
{
- FontBLF *font;
- float remainder;
- float xa, ya, za;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
+ float xa, ya, za;
+ float remainder;
+
if (font->flags & BLF_ASPECT) {
xa= font->aspect[0];
ya= font->aspect[1];
@@ -401,20 +397,20 @@ void BLF_position(int fontid, float x, float y, float z)
void BLF_size(int fontid, int size, int dpi)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font) {
blf_font_size(font, size, dpi);
+ }
}
void BLF_blur(int fontid, int size)
{
- FontBLF *font;
-
- font= BLF_get(fontid);
- if (font)
+ FontBLF *font= BLF_get(fontid);
+
+ if (font) {
font->blur= size;
+ }
}
void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
@@ -456,11 +452,11 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
void BLF_rotation_default(float angle)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(global_font_default);
- font= BLF_get(global_font_default);
- if (font)
+ if (font) {
font->angle= angle;
+ }
}
static void blf_draw__start(FontBLF *font)
@@ -505,7 +501,8 @@ static void blf_draw__end(void)
void BLF_draw(int fontid, const char *str, size_t len)
{
FontBLF *font= BLF_get(fontid);
- if (font) {
+
+ if (font && font->glyph_cache) {
blf_draw__start(font);
blf_font_draw(font, str, len);
blf_draw__end();
@@ -515,7 +512,8 @@ void BLF_draw(int fontid, const char *str, size_t len)
void BLF_draw_ascii(int fontid, const char *str, size_t len)
{
FontBLF *font= BLF_get(fontid);
- if (font) {
+
+ if (font && font->glyph_cache) {
blf_draw__start(font);
blf_font_draw_ascii(font, str, len);
blf_draw__end();
@@ -524,148 +522,141 @@ void BLF_draw_ascii(int fontid, const char *str, size_t len)
void BLF_boundbox(int fontid, const char *str, rctf *box)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font) {
blf_font_boundbox(font, str, box);
+ }
}
void BLF_width_and_height(int fontid, const char *str, float *width, float *height)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font && font->glyph_cache) {
blf_font_width_and_height(font, str, width, height);
+ }
}
float BLF_width(int fontid, const char *str)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
+
+ if (font && font->glyph_cache) {
+ return blf_font_width(font, str);
+ }
- font= BLF_get(fontid);
- if (font)
- return(blf_font_width(font, str));
- return(0.0f);
+ return 0.0f;
}
float BLF_fixed_width(int fontid)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
- return(blf_font_fixed_width(font));
- return(0.0f);
+ if (font && font->glyph_cache) {
+ return blf_font_fixed_width(font);
+ }
+
+ return 0.0f;
}
float BLF_width_default(const char *str)
{
- float width;
-
if (global_font_default == -1)
global_font_default= blf_search("default");
if (global_font_default == -1) {
printf("Error: Can't found default font!!\n");
- return(0.0f);
+ return 0.0f;
}
BLF_size(global_font_default, global_font_points, global_font_dpi);
- width= BLF_width(global_font_default, str);
- return(width);
+ return BLF_width(global_font_default, str);
}
float BLF_height(int fontid, const char *str)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
+
+ if (font && font->glyph_cache) {
+ return blf_font_height(font, str);
+ }
- font= BLF_get(fontid);
- if (font)
- return(blf_font_height(font, str));
- return(0.0f);
+ return 0.0f;
}
float BLF_height_max(int fontid)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font) {
- if(font->glyph_cache)
- return(font->glyph_cache->max_glyph_height);
+ if (font && font->glyph_cache) {
+ return font->glyph_cache->max_glyph_height;
}
- return(0.0f);
+
+ return 0.0f;
}
float BLF_width_max(int fontid)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font) {
- if(font->glyph_cache)
- return(font->glyph_cache->max_glyph_width);
+ if (font && font->glyph_cache) {
+ return font->glyph_cache->max_glyph_width;
}
- return(0.0f);
+
+ return 0.0f;
}
float BLF_descender(int fontid)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font) {
- if(font->glyph_cache)
- return(font->glyph_cache->descender);
+ if (font && font->glyph_cache) {
+ return font->glyph_cache->descender;
}
- return(0.0f);
+
+ return 0.0f;
}
float BLF_ascender(int fontid)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font) {
- if(font->glyph_cache)
- return(font->glyph_cache->ascender);
+ if (font && font->glyph_cache) {
+ return font->glyph_cache->ascender;
}
- return(0.0f);
+
+ return 0.0f;
}
float BLF_height_default(const char *str)
{
- float height;
-
if (global_font_default == -1)
global_font_default= blf_search("default");
if (global_font_default == -1) {
printf("Error: Can't found default font!!\n");
- return(0.0f);
+ return 0.0f;
}
BLF_size(global_font_default, global_font_points, global_font_dpi);
- height= BLF_height(global_font_default, str);
- return(height);
+
+ return BLF_height(global_font_default, str);
}
void BLF_rotation(int fontid, float angle)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font) {
font->angle= angle;
+ }
}
void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
font->clip_rec.xmin= xmin;
font->clip_rec.ymin= ymin;
@@ -676,9 +667,8 @@ void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(global_font_default);
- font= BLF_get(global_font_default);
if (font) {
font->clip_rec.xmin= xmin;
font->clip_rec.ymin= ymin;
@@ -689,9 +679,8 @@ void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
font->shadow= level;
font->shadow_col[0]= r;
@@ -703,9 +692,8 @@ void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
void BLF_shadow_offset(int fontid, int x, int y)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
font->shadow_x= x;
font->shadow_y= y;
@@ -714,9 +702,8 @@ void BLF_shadow_offset(int fontid, int x, int y)
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
font->b_fbuf= fbuf;
font->b_cbuf= cbuf;
@@ -728,9 +715,8 @@ void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int
void BLF_buffer_col(int fontid, float r, float g, float b, float a)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
if (font) {
font->b_col[0]= r;
font->b_col[1]= g;
@@ -741,9 +727,9 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a)
void BLF_draw_buffer(int fontid, const char *str)
{
- FontBLF *font;
+ FontBLF *font= BLF_get(fontid);
- font= BLF_get(fontid);
- if (font)
+ if (font && font->glyph_cache && (font->b_fbuf || font->b_cbuf)) {
blf_font_buffer(font, str);
+ }
}
diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c
index fd874d991ea..1c99af0c7a9 100644
--- a/source/blender/blenfont/intern/blf_dir.c
+++ b/source/blender/blenfont/intern/blf_dir.c
@@ -62,10 +62,10 @@ static DirBLF *blf_dir_find(const char *path)
p= global_font_dir.first;
while (p) {
if (BLI_path_cmp(p->path, path) == 0)
- return(p);
+ return p;
p= p->next;
}
- return(NULL);
+ return NULL;
}
void BLF_dir_add(const char *path)
@@ -102,7 +102,7 @@ char **BLF_dir_get(int *ndir)
count= BLI_countlist(&global_font_dir);
if (!count)
- return(NULL);
+ return NULL;
dirs= (char **)MEM_mallocN(sizeof(char *) * count, "BLF_dir_get");
p= global_font_dir.first;
@@ -113,7 +113,7 @@ char **BLF_dir_get(int *ndir)
p= p->next;
}
*ndir= i;
- return(dirs);
+ return dirs;
}
void BLF_dir_free(char **dirs, int count)
@@ -147,8 +147,8 @@ char *blf_dir_search(const char *file)
if (BLI_exist(file))
s= BLI_strdup(file);
}
-
- return(s);
+
+ return s;
}
#if 0 // UNUSED
@@ -171,9 +171,9 @@ int blf_dir_split(const char *str, char *file, int *size)
file[i+4]= '\0';
s++;
*size= atoi(s);
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
#endif
@@ -188,9 +188,9 @@ char *blf_dir_metrics_search(const char *filename)
mfile= BLI_strdup(filename);
s= strrchr(mfile, '.');
if (s) {
- if (strlen(s) < 4) {
+ if (BLI_strnlen(s, 4) < 4) {
MEM_freeN(mfile);
- return(NULL);
+ return NULL;
}
s++;
s[0]= 'a';
@@ -199,14 +199,14 @@ char *blf_dir_metrics_search(const char *filename)
/* first check .afm */
if (BLI_exist(s))
- return(s);
+ return s;
/* and now check .pfm */
s[0]= 'p';
if (BLI_exist(s))
- return(s);
+ return s;
}
MEM_freeN(mfile);
- return(NULL);
+ return NULL;
}
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 3bec7dd2626..f3f3b759e5c 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -62,7 +62,7 @@ static FT_Library ft_lib;
int blf_font_init(void)
{
- return(FT_Init_FreeType(&ft_lib));
+ return FT_Init_FreeType(&ft_lib);
}
void blf_font_exit(void)
@@ -136,26 +136,33 @@ static void blf_font_ensure_ascii_table(FontBLF *font)
} \
+#define BLF_KERNING_VARS(_font, _has_kerning, _kern_mode) \
+ const short has_kerning= FT_HAS_KERNING((_font)->face); \
+ const FT_UInt kern_mode= (has_kerning == 0) ? 0 : \
+ (((_font)->flags & BLF_KERNING_DEFAULT) ? \
+ ft_kerning_default : FT_KERNING_UNFITTED) \
+ \
+
+
+#define BLF_KERNING_STEP(_font, kern_mode, g_prev, g, delta, pen_x) \
+{ \
+ if (g_prev) { \
+ delta.x= delta.y= 0; \
+ if (FT_Get_Kerning((_font)->face, g_prev->idx, g->idx, kern_mode, &delta) == 0) \
+ pen_x += delta.x >> 6; \
+ } \
+} \
void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
{
unsigned int c;
- GlyphBLF *g, *g_prev;
+ GlyphBLF *g, *g_prev= NULL;
FT_Vector delta;
- int pen_x, pen_y;
- int has_kerning, st;
- unsigned int i;
- GlyphBLF **glyph_ascii_table;
-
- if (!font->glyph_cache)
- return;
- glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
+ int pen_x= 0, pen_y= 0;
+ unsigned int i= 0;
+ GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
- i= 0;
- pen_x= 0;
- pen_y= 0;
- has_kerning= FT_HAS_KERNING(font->face);
- g_prev= NULL;
+ BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
@@ -163,25 +170,9 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == 0)
- break;
-
- /* if we don't found a glyph, skip it. */
- if (!g)
- continue;
-
- if (has_kerning && g_prev) {
- delta.x= 0;
- delta.y= 0;
-
- if (font->flags & BLF_KERNING_DEFAULT)
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, ft_kerning_default, &delta);
- else
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, FT_KERNING_UNFITTED, &delta);
-
- if (st == 0)
- pen_x += delta.x >> 6;
- }
+ if (c == 0) break;
+ if (g == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
@@ -194,43 +185,19 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
/* faster version of blf_font_draw, ascii only for view dimensions */
void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len)
{
- char c;
- GlyphBLF *g, *g_prev;
+ unsigned char c;
+ GlyphBLF *g, *g_prev= NULL;
FT_Vector delta;
- int pen_x, pen_y;
- int has_kerning, st;
- GlyphBLF **glyph_ascii_table;
-
- if (!font->glyph_cache)
- return;
- glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
+ int pen_x= 0, pen_y= 0;
+ GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
- pen_x= 0;
- pen_y= 0;
- has_kerning= FT_HAS_KERNING(font->face);
- g_prev= NULL;
+ BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
while ((c= *(str++)) && len--) {
- g= glyph_ascii_table[c];
-
- /* if we don't found a glyph, skip it. */
- if (!g)
- continue;
-
- if (has_kerning && g_prev) {
- delta.x= 0;
- delta.y= 0;
-
- if (font->flags & BLF_KERNING_DEFAULT)
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, ft_kerning_default, &delta);
- else
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, FT_KERNING_UNFITTED, &delta);
-
- if (st == 0)
- pen_x += delta.x >> 6;
- }
+ if ((g= glyph_ascii_table[c]) == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
@@ -240,59 +207,37 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len)
}
}
+/* Sanity checks are done by BLF_draw_buffer() */
void blf_font_buffer(FontBLF *font, const char *str)
{
- unsigned char *cbuf;
unsigned int c;
- unsigned char b_col_char[4];
- GlyphBLF *g, *g_prev;
+ GlyphBLF *g, *g_prev= NULL;
FT_Vector delta;
+ int pen_x= (int)font->pos[0], pen_y= 0;
+ unsigned int i= 0;
+ GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
+
+ /* buffer spesific vars*/
+ const unsigned char b_col_char[4]= {font->b_col[0] * 255,
+ font->b_col[1] * 255,
+ font->b_col[2] * 255,
+ font->b_col[3] * 255};
+ unsigned char *cbuf;
+ int chx, chy;
+ int y, x;
float a, *fbuf;
- int pen_x, y, x;
- int has_kerning, st, chx, chy;
- unsigned int i;
- GlyphBLF **glyph_ascii_table;
- if (!font->glyph_cache || (!font->b_fbuf && !font->b_cbuf))
- return;
- glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
-
- i= 0;
- pen_x= (int)font->pos[0];
- has_kerning= FT_HAS_KERNING(font->face);
- g_prev= NULL;
-
- b_col_char[0]= font->b_col[0] * 255;
- b_col_char[1]= font->b_col[1] * 255;
- b_col_char[2]= font->b_col[2] * 255;
- b_col_char[3]= font->b_col[3] * 255;
+ BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
while (str[i]) {
- int pen_y;
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == 0)
- break;
-
- /* if we don't found a glyph, skip it. */
- if (!g)
- continue;
-
- if (has_kerning && g_prev) {
- delta.x= 0;
- delta.y= 0;
-
- if (font->flags & BLF_KERNING_DEFAULT)
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, ft_kerning_default, &delta);
- else
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, FT_KERNING_UNFITTED, &delta);
-
- if (st == 0)
- pen_x += delta.x >> 6;
- }
+ if (c == 0) break;
+ if (g == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
chx= pen_x + ((int)g->pos_x);
chy= (int)font->pos[1] + g->height;
@@ -392,69 +337,41 @@ void blf_font_buffer(FontBLF *font, const char *str)
void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
{
unsigned int c;
- GlyphBLF *g, *g_prev;
+ GlyphBLF *g, *g_prev= NULL;
FT_Vector delta;
+ int pen_x= 0, pen_y= 0;
+ unsigned int i= 0;
+ GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
+
rctf gbox;
- int pen_x, pen_y;
- int has_kerning, st;
- unsigned int i;
- GlyphBLF **glyph_ascii_table;
- if (!font->glyph_cache)
- return;
+ BLF_KERNING_VARS(font, has_kerning, kern_mode);
box->xmin= 32000.0f;
box->xmax= -32000.0f;
box->ymin= 32000.0f;
box->ymax= -32000.0f;
- i= 0;
- pen_x= 0;
- pen_y= 0;
- has_kerning= FT_HAS_KERNING(font->face);
- g_prev= NULL;
-
blf_font_ensure_ascii_table(font);
- glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
while (str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == 0)
- break;
-
- /* if we don't found a glyph, skip it. */
- if (!g)
- continue;
-
- if (has_kerning && g_prev) {
- delta.x= 0;
- delta.y= 0;
-
- if (font->flags & BLF_KERNING_DEFAULT)
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, ft_kerning_default, &delta);
- else
- st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, FT_KERNING_UNFITTED, &delta);
-
- if (st == 0)
- pen_x += delta.x >> 6;
- }
+ if (c == 0) break;
+ if (g == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
gbox.xmin= pen_x;
gbox.xmax= pen_x + g->advance;
gbox.ymin= g->box.ymin + pen_y;
gbox.ymax= g->box.ymax + pen_y;
- if (gbox.xmin < box->xmin)
- box->xmin= gbox.xmin;
- if (gbox.ymin < box->ymin)
- box->ymin= gbox.ymin;
+ if (gbox.xmin < box->xmin) box->xmin= gbox.xmin;
+ if (gbox.ymin < box->ymin) box->ymin= gbox.ymin;
- if (gbox.xmax > box->xmax)
- box->xmax= gbox.xmax;
- if (gbox.ymax > box->ymax)
- box->ymax= gbox.ymax;
+ if (gbox.xmax > box->xmax) box->xmax= gbox.xmax;
+ if (gbox.ymax > box->ymax) box->ymax= gbox.ymax;
pen_x += g->advance;
g_prev= g;
@@ -473,20 +390,18 @@ void blf_font_width_and_height(FontBLF *font, const char *str, float *width, flo
float xa, ya;
rctf box;
- if (font->glyph_cache) {
- if (font->flags & BLF_ASPECT) {
- xa= font->aspect[0];
- ya= font->aspect[1];
- }
- else {
- xa= 1.0f;
- ya= 1.0f;
- }
-
- blf_font_boundbox(font, str, &box);
- *width= ((box.xmax - box.xmin) * xa);
- *height= ((box.ymax - box.ymin) * ya);
+ if (font->flags & BLF_ASPECT) {
+ xa= font->aspect[0];
+ ya= font->aspect[1];
+ }
+ else {
+ xa= 1.0f;
+ ya= 1.0f;
}
+
+ blf_font_boundbox(font, str, &box);
+ *width= ((box.xmax - box.xmin) * xa);
+ *height= ((box.ymax - box.ymin) * ya);
}
float blf_font_width(FontBLF *font, const char *str)
@@ -494,16 +409,13 @@ float blf_font_width(FontBLF *font, const char *str)
float xa;
rctf box;
- if (!font->glyph_cache)
- return(0.0f);
-
if (font->flags & BLF_ASPECT)
xa= font->aspect[0];
else
xa= 1.0f;
blf_font_boundbox(font, str, &box);
- return((box.xmax - box.xmin) * xa);
+ return (box.xmax - box.xmin) * xa;
}
float blf_font_height(FontBLF *font, const char *str)
@@ -511,36 +423,28 @@ float blf_font_height(FontBLF *font, const char *str)
float ya;
rctf box;
- if (!font->glyph_cache)
- return(0.0f);
-
if (font->flags & BLF_ASPECT)
ya= font->aspect[1];
else
ya= 1.0f;
blf_font_boundbox(font, str, &box);
- return((box.ymax - box.ymin) * ya);
+ return (box.ymax - box.ymin) * ya;
}
float blf_font_fixed_width(FontBLF *font)
{
- GlyphBLF *g;
- FT_UInt glyph_index;
- unsigned int c = ' ';
-
- if (!font->glyph_cache)
- return 0.0f;
-
- glyph_index= FT_Get_Char_Index(font->face, c);
- g= blf_glyph_search(font->glyph_cache, c);
- if (!g)
- g= blf_glyph_add(font, glyph_index, c);
-
- /* if we don't find the glyph. */
- if (!g)
- return 0.0f;
-
+ const unsigned int c = ' ';
+ GlyphBLF *g= blf_glyph_search(font->glyph_cache, c);
+ if (!g) {
+ g= blf_glyph_add(font, FT_Get_Char_Index(font->face, c), c);
+
+ /* if we don't find the glyph. */
+ if (!g) {
+ return 0.0f;
+ }
+ }
+
return g->advance;
}
@@ -611,7 +515,7 @@ FontBLF *blf_font_new(const char *name, const char *filename)
err= FT_New_Face(ft_lib, filename, 0, &font->face);
if (err) {
MEM_freeN(font);
- return(NULL);
+ return NULL;
}
err= FT_Select_Charmap(font->face, ft_encoding_unicode);
@@ -619,7 +523,7 @@ FontBLF *blf_font_new(const char *name, const char *filename)
printf("Can't set the unicode character map!\n");
FT_Done_Face(font->face);
MEM_freeN(font);
- return(NULL);
+ return NULL;
}
mfile= blf_dir_metrics_search(filename);
@@ -631,7 +535,7 @@ FontBLF *blf_font_new(const char *name, const char *filename)
font->name= BLI_strdup(name);
font->filename= BLI_strdup(filename);
blf_font_fill(font);
- return(font);
+ return font;
}
void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_size)
@@ -653,7 +557,7 @@ FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_siz
err= FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face);
if (err) {
MEM_freeN(font);
- return(NULL);
+ return NULL;
}
err= FT_Select_Charmap(font->face, ft_encoding_unicode);
@@ -661,11 +565,11 @@ FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_siz
printf("Can't set the unicode character map!\n");
FT_Done_Face(font->face);
MEM_freeN(font);
- return(NULL);
+ return NULL;
}
font->name= BLI_strdup(name);
font->filename= NULL;
blf_font_fill(font);
- return(font);
+ return font;
}
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 7a1fa8c80b0..b661005b50b 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -64,10 +64,10 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi)
p= (GlyphCacheBLF *)font->cache.first;
while (p) {
if (p->size == size && p->dpi == dpi)
- return(p);
+ return p;
p= p->next;
}
- return(NULL);
+ return NULL;
}
/* Create a new glyph cache for the current size and dpi. */
@@ -114,7 +114,7 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
gc->p2_height= 0;
BLI_addhead(&font->cache, gc);
- return(gc);
+ return gc;
}
void blf_glyph_cache_clear(FontBLF *font)
@@ -204,10 +204,10 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
p= gc->bucket[key].first;
while (p) {
if (p->c == c)
- return(p);
+ return p;
p= p->next;
}
- return(NULL);
+ return NULL;
}
GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
@@ -222,14 +222,14 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
g= blf_glyph_search(font->glyph_cache, c);
if (g)
- return(g);
+ return g;
if (sharp)
err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_MONO);
else
err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); /* Sure about NO_* flags? */
if (err)
- return(NULL);
+ return NULL;
/* get the glyph. */
slot= font->face->glyph;
@@ -248,7 +248,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
}
if (err || slot->format != FT_GLYPH_FORMAT_BITMAP)
- return(NULL);
+ return NULL;
g= (GlyphBLF *)MEM_mallocN(sizeof(GlyphBLF), "blf_glyph_add");
g->next= NULL;
@@ -294,7 +294,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
key= blf_hash(g->c);
BLI_addhead(&(font->glyph_cache->bucket[key]), g);
- return(g);
+ return g;
}
void blf_glyph_free(GlyphBLF *g)
@@ -383,7 +383,7 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
float xo, yo;
if ((!g->width) || (!g->height))
- return(1);
+ return 1;
if (g->build_tex == 0) {
GlyphCacheBLF *gc= font->glyph_cache;
@@ -449,13 +449,13 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
if (font->flags & BLF_CLIPPING) {
if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y1 + font->pos[1]))
- return(0);
+ return 0;
if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y2 + font->pos[1]))
- return(0);
+ return 0;
if (!BLI_in_rctf(&font->clip_rec, dx1 + font->pos[0], y2 + font->pos[1]))
- return(0);
+ return 0;
if (!BLI_in_rctf(&font->clip_rec, dx1 + font->pos[0], y1 + font->pos[1]))
- return(0);
+ return 0;
}
if (font->tex_bind_state != g->tex) {
@@ -500,5 +500,5 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
break;
}
- return(1);
+ return 1;
}
diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c
index e7f9d1746ad..80951899040 100644
--- a/source/blender/blenfont/intern/blf_lang.c
+++ b/source/blender/blenfont/intern/blf_lang.c
@@ -51,11 +51,6 @@
#include "BLI_string.h"
#include "BLI_path_util.h"
-
-#ifdef __APPLE__
-
-#endif
-
#define DOMAIN_NAME "blender"
#define SYSTEM_ENCODING_DEFAULT "UTF-8"
#define FONT_SIZE_DEFAULT 12
diff --git a/source/blender/blenfont/intern/blf_util.c b/source/blender/blenfont/intern/blf_util.c
index edd23ac1ba6..cfe77887674 100644
--- a/source/blender/blenfont/intern/blf_util.c
+++ b/source/blender/blenfont/intern/blf_util.c
@@ -46,7 +46,7 @@ unsigned int blf_next_p2(unsigned int x)
x |= (x >> 2);
x |= (x >> 1);
x += 1;
- return(x);
+ return x;
}
unsigned int blf_hash(unsigned int val)
@@ -60,7 +60,7 @@ unsigned int blf_hash(unsigned int val)
key ^= (key >> 13);
key += ~(key << 9);
key ^= (key >> 17);
- return(key % 257);
+ return key % 257;
}
/*
@@ -85,7 +85,7 @@ int blf_utf8_next(unsigned char *buf, unsigned int *iindex)
d= buf[index++];
if (!d)
- return(0);
+ return 0;
while (buf[index] && ((buf[index] & 0xc0) == 0x80))
index++;
@@ -124,5 +124,5 @@ int blf_utf8_next(unsigned char *buf, unsigned int *iindex)
r |= (d4 & 0x3f);
}
*iindex= index;
- return(r);
+ return r;
}