From 100313db6ecec36ad0c8e5b8a8d11bd170ff9349 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 17 Sep 2011 10:45:20 +0000 Subject: Speedup for font drawing, every letter was character was calling: glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex); ... with shadow enabled glGetFloatv(GL_CURRENT_COLOR, color) was called twice per character as well. Now only call glGetFloatv(GL_CURRENT_COLOR, ...) once per string and only when drawing with shadow or blur, texture bind is stored in the font. Gives 8% overall FPS speedup when displaying heavy UI in my test. --- source/blender/blenfont/intern/blf.c | 7 ++ source/blender/blenfont/intern/blf_glyph.c | 95 +++++++++++++--------- .../blender/blenfont/intern/blf_internal_types.h | 8 +- 3 files changed, 69 insertions(+), 41 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index fc812d652b3..577697de594 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -486,6 +486,13 @@ static void blf_draw__start(FontBLF *font) if (font->flags & BLF_ROTATION) glRotatef(font->angle, 0.0f, 0.0f, 1.0f); + + if(font->shadow || font->blur) + glGetFloatv(GL_CURRENT_COLOR, font->orig_col); + + /* always bind the texture for the first glyph */ + font->tex_bind_state= -1; + } static void blf_draw__end(void) diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 9b39cb65cba..7a1fa8c80b0 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -185,7 +185,7 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc) memset((void *)buf, 0, tot_mem); glGenTextures(1, &gc->textures[gc->cur_tex]); - glBindTexture(GL_TEXTURE_2D, gc->textures[gc->cur_tex]); + glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state= gc->textures[gc->cur_tex])); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -326,23 +326,25 @@ static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, floa } -static void blf_texture5_draw(float uv[2][2], float x1, float y1, float x2, float y2) +static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2) { - float soft[25]= { - 1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f, - 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, - 2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f, - 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, - 1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f}; + float soft[25]= {1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f, + 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, + 2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f, + 1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f, + 1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f}; float color[4], *fp= soft; int dx, dy; - - glGetFloatv(GL_CURRENT_COLOR, color); + + color[0]= shadow_col[0]; + color[1]= shadow_col[1]; + color[2]= shadow_col[2]; for(dx=-2; dx<3; dx++) { for(dy=-2; dy<3; dy++, fp++) { - glColor4f(color[0], color[1], color[2], fp[0]*color[3]); + color[3]= *(fp) * shadow_col[3]; + glColor4fv(color); blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); } } @@ -350,17 +352,23 @@ static void blf_texture5_draw(float uv[2][2], float x1, float y1, float x2, floa glColor4fv(color); } -static void blf_texture3_draw(float uv[2][2], float x1, float y1, float x2, float y2) +static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2) { - float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 4/16.0f, 2/16.0f, 1/16.0f, 2/16.0f, 1/16.0f}; + float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f, + 2/16.0f,4/16.0f, 2/16.0f, + 1/16.0f, 2/16.0f, 1/16.0f}; + float color[4], *fp= soft; int dx, dy; - - glGetFloatv(GL_CURRENT_COLOR, color); - + + color[0]= shadow_col[0]; + color[1]= shadow_col[1]; + color[2]= shadow_col[2]; + for(dx=-1; dx<2; dx++) { for(dy=-1; dy<2; dy++, fp++) { - glColor4f(color[0], color[1], color[2], fp[0]*color[3]); + color[3]= *(fp) * shadow_col[3]; + glColor4fv(color); blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); } } @@ -370,18 +378,15 @@ static void blf_texture3_draw(float uv[2][2], float x1, float y1, float x2, floa int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) { - GlyphCacheBLF *gc; - GLint cur_tex; float dx, dx1; float y1, y2; float xo, yo; - float color[4]; if ((!g->width) || (!g->height)) return(1); if (g->build_tex == 0) { - gc= font->glyph_cache; + GlyphCacheBLF *gc= font->glyph_cache; if (font->max_tex_size == -1) glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size); @@ -453,22 +458,27 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) return(0); } - glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex); - if (cur_tex != g->tex) - glBindTexture(GL_TEXTURE_2D, g->tex); + if (font->tex_bind_state != g->tex) { + glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state= g->tex)); + } if (font->flags & BLF_SHADOW) { - glGetFloatv(GL_CURRENT_COLOR, color); - glColor4fv(font->shadow_col); - - if (font->shadow == 3) - blf_texture3_draw(g->uv, dx, y1, dx1, y2); - else if (font->shadow == 5) - blf_texture5_draw(g->uv, dx, y1, dx1, y2); - else - blf_texture_draw(g->uv, dx, y1, dx1, y2); - glColor4fv(color); + switch(font->shadow) { + case 3: + blf_texture3_draw(font->shadow_col, g->uv, dx, y1, dx1, y2); + break; + case 5: + blf_texture5_draw(font->shadow_col, g->uv, dx, y1, dx1, y2); + break; + default: + glColor4fv(font->shadow_col); + blf_texture_draw(g->uv, dx, y1, dx1, y2); + break; + } + + glColor4fv(font->orig_col); + x= xo; y= yo; @@ -478,12 +488,17 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) y2= y + g->pos_y - g->height; } - if (font->blur==3) - blf_texture3_draw(g->uv, dx, y1, dx1, y2); - else if (font->blur==5) - blf_texture5_draw(g->uv, dx, y1, dx1, y2); - else - blf_texture_draw(g->uv, dx, y1, dx1, y2); + switch(font->blur) { + case 3: + blf_texture3_draw(font->orig_col, g->uv, dx, y1, dx1, y2); + break; + case 5: + blf_texture5_draw(font->orig_col, g->uv, dx, y1, dx1, y2); + break; + default: + blf_texture_draw(g->uv, dx, y1, dx1, y2); + break; + } return(1); } diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 9840e6446ef..1450ad39ad8 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -161,7 +161,10 @@ typedef struct FontBLF { /* shadow color. */ float shadow_col[4]; - + + /* store color here when drawing shadow or blur. */ + float orig_col[4]; + /* Multiplied this matrix with the current one before * draw the text! see blf_draw__start. */ @@ -179,6 +182,9 @@ typedef struct FontBLF { /* max texture size. */ int max_tex_size; + /* current opengl texture bind, avoids calling glGet */ + int tex_bind_state; + /* font options. */ int flags; -- cgit v1.2.3 From 249b41762a98b5e357cc32e0ba0cb673fc0c6225 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 09:48:09 +0000 Subject: blf code - no functional changes. - remove saniy checks from blf_font.c, the callers now check instead. - move duplicate code into defines (may move into static functions). - move kerning checks into const values set at the start of the function, rather then checking on every character. --- source/blender/blenfont/intern/blf.c | 29 ++--- source/blender/blenfont/intern/blf_font.c | 196 ++++++++++-------------------- source/blender/blenfont/intern/blf_lang.c | 5 - 3 files changed, 74 insertions(+), 156 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 577697de594..07291fbb3e3 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -505,7 +505,7 @@ 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 +515,7 @@ 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(); @@ -536,7 +536,7 @@ void BLF_width_and_height(int fontid, const char *str, float *width, float *heig FontBLF *font; font= BLF_get(fontid); - if (font) + if (font && font->glyph_cache) blf_font_width_and_height(font, str, width, height); } @@ -545,7 +545,7 @@ float BLF_width(int fontid, const char *str) FontBLF *font; font= BLF_get(fontid); - if (font) + if (font && font->glyph_cache) return(blf_font_width(font, str)); return(0.0f); } @@ -555,9 +555,9 @@ float BLF_fixed_width(int fontid) FontBLF *font; 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) @@ -582,7 +582,7 @@ float BLF_height(int fontid, const char *str) FontBLF *font; font= BLF_get(fontid); - if (font) + if (font && font->glyph_cache) return(blf_font_height(font, str)); return(0.0f); } @@ -592,10 +592,8 @@ float BLF_height_max(int fontid) FontBLF *font; 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); } @@ -741,9 +739,8 @@ 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; - - font= BLF_get(fontid); - if (font) + FontBLF *font= BLF_get(fontid); + if (font && font->glyph_cache && (font->b_fbuf || font->b_cbuf)) { blf_font_buffer(font, str); + } } diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 3bec7dd2626..c1674052fb1 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -136,6 +136,22 @@ 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) { @@ -143,18 +159,14 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len) GlyphBLF *g, *g_prev; FT_Vector delta; int pen_x, pen_y; - int has_kerning, st; unsigned int i; - GlyphBLF **glyph_ascii_table; + GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; - if (!font->glyph_cache) - return; - glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + BLF_KERNING_VARS(font, has_kerning, kern_mode); i= 0; pen_x= 0; pen_y= 0; - has_kerning= FT_HAS_KERNING(font->face); g_prev= NULL; blf_font_ensure_ascii_table(font); @@ -163,25 +175,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); @@ -198,39 +194,19 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len) GlyphBLF *g, *g_prev; FT_Vector delta; int pen_x, pen_y; - int has_kerning, st; - GlyphBLF **glyph_ascii_table; + GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; - if (!font->glyph_cache) - return; - glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + BLF_KERNING_VARS(font, has_kerning, kern_mode); pen_x= 0; pen_y= 0; - has_kerning= FT_HAS_KERNING(font->face); g_prev= NULL; 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,6 +216,7 @@ 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; @@ -248,18 +225,15 @@ void blf_font_buffer(FontBLF *font, const char *str) GlyphBLF *g, *g_prev; FT_Vector delta; float a, *fbuf; - int pen_x, y, x; - int has_kerning, st, chx, chy; + int pen_x, pen_y, y, x; + int chx, chy; unsigned int i; - GlyphBLF **glyph_ascii_table; + GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; + + BLF_KERNING_VARS(font, has_kerning, kern_mode); - 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; @@ -270,29 +244,12 @@ void blf_font_buffer(FontBLF *font, const char *str) 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; @@ -394,14 +351,13 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) unsigned int c; GlyphBLF *g, *g_prev; FT_Vector delta; - rctf gbox; int pen_x, pen_y; - int has_kerning, st; unsigned int i; GlyphBLF **glyph_ascii_table; - if (!font->glyph_cache) - return; + rctf gbox; + + BLF_KERNING_VARS(font, has_kerning, kern_mode); box->xmin= 32000.0f; box->xmax= -32000.0f; @@ -411,7 +367,6 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) i= 0; pen_x= 0; pen_y= 0; - has_kerning= FT_HAS_KERNING(font->face); g_prev= NULL; blf_font_ensure_ascii_table(font); @@ -421,25 +376,9 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) 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; @@ -473,20 +412,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,9 +431,6 @@ 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 @@ -511,9 +445,6 @@ 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 @@ -525,22 +456,17 @@ float blf_font_height(FontBLF *font, const char *str) 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); + 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; + } + } - /* if we don't find the glyph. */ - if (!g) - return 0.0f; - return g->advance; } 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 -- cgit v1.2.3 From 53845a37d9d33703e18236212ee3ef52982a6247 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 10:34:13 +0000 Subject: blf - further shrink drawing functions & some style changes. --- source/blender/blenfont/BLF_api.h | 2 +- source/blender/blenfont/intern/blf.c | 113 +++++++++++++---------------- source/blender/blenfont/intern/blf_dir.c | 26 +++---- source/blender/blenfont/intern/blf_font.c | 91 +++++++++-------------- source/blender/blenfont/intern/blf_glyph.c | 30 ++++---- source/blender/blenfont/intern/blf_util.c | 8 +- 6 files changed, 120 insertions(+), 150 deletions(-) (limited to 'source/blender/blenfont') 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 07291fbb3e3..743dcadae99 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -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,13 +202,13 @@ 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) @@ -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,24 +270,24 @@ 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) @@ -338,26 +338,25 @@ 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; 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; 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]; @@ -546,8 +545,8 @@ float BLF_width(int fontid, const char *str) font= BLF_get(fontid); if (font && font->glyph_cache) - return(blf_font_width(font, str)); - return(0.0f); + return blf_font_width(font, str); + return 0.0f; } float BLF_fixed_width(int fontid) @@ -562,19 +561,16 @@ float BLF_fixed_width(int fontid) 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) @@ -583,8 +579,8 @@ float BLF_height(int fontid, const char *str) font= BLF_get(fontid); if (font && font->glyph_cache) - return(blf_font_height(font, str)); - return(0.0f); + return blf_font_height(font, str); + return 0.0f; } float BLF_height_max(int fontid) @@ -593,8 +589,8 @@ float BLF_height_max(int fontid) font= BLF_get(fontid); if (font && font->glyph_cache) - return(font->glyph_cache->max_glyph_height); - return(0.0f); + return font->glyph_cache->max_glyph_height; + return 0.0f; } float BLF_width_max(int fontid) @@ -602,11 +598,10 @@ float BLF_width_max(int fontid) FontBLF *font; 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) @@ -614,11 +609,10 @@ float BLF_descender(int fontid) FontBLF *font; 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) @@ -626,28 +620,25 @@ float BLF_ascender(int fontid) FontBLF *font; 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) diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index fd874d991ea..d5d9969c421 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 (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 c1674052fb1..92c68ccb85b 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) @@ -156,19 +156,14 @@ static void blf_font_ensure_ascii_table(FontBLF *font) 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; - unsigned int i; + int pen_x= 0, pen_y= 0; + unsigned int i= 0; GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; BLF_KERNING_VARS(font, has_kerning, kern_mode); - i= 0; - pen_x= 0; - pen_y= 0; - g_prev= NULL; - blf_font_ensure_ascii_table(font); while (str[i] && i < len) { @@ -190,18 +185,14 @@ 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 pen_x= 0, pen_y= 0; GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; BLF_KERNING_VARS(font, has_kerning, kern_mode); - pen_x= 0; - pen_y= 0; - g_prev= NULL; - blf_font_ensure_ascii_table(font); while ((c= *(str++)) && len--) { @@ -219,27 +210,24 @@ 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; - float a, *fbuf; - int pen_x, pen_y, y, x; - int chx, chy; - unsigned int i; + int pen_x= (int)font->pos[0], pen_y= 0; + unsigned int i= 0; GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; - BLF_KERNING_VARS(font, has_kerning, kern_mode); + /* 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; - i= 0; - pen_x= (int)font->pos[0]; - 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); @@ -349,10 +337,10 @@ 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, pen_y; - unsigned int i; + int pen_x= 0, pen_y= 0; + unsigned int i= 0; GlyphBLF **glyph_ascii_table; rctf gbox; @@ -364,11 +352,6 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) box->ymin= 32000.0f; box->ymax= -32000.0f; - i= 0; - pen_x= 0; - pen_y= 0; - g_prev= NULL; - blf_font_ensure_ascii_table(font); glyph_ascii_table= font->glyph_cache->glyph_ascii_table; @@ -385,15 +368,11 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) 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; @@ -437,7 +416,7 @@ float blf_font_width(FontBLF *font, const char *str) 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) @@ -451,7 +430,7 @@ float blf_font_height(FontBLF *font, const char *str) 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) @@ -537,7 +516,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); @@ -545,7 +524,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); @@ -557,7 +536,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) @@ -579,7 +558,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); @@ -587,11 +566,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_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; } -- cgit v1.2.3 From b17a62d1b37a5a38d9e8a37680ee11d66b8a327b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 18 Sep 2011 11:25:50 +0000 Subject: replace strnlen with BLI_strnlen & some style changes. --- source/blender/blenfont/intern/blf.c | 142 +++++++++++++++--------------- source/blender/blenfont/intern/blf_dir.c | 2 +- source/blender/blenfont/intern/blf_font.c | 3 +- 3 files changed, 72 insertions(+), 75 deletions(-) (limited to 'source/blender/blenfont') diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 743dcadae99..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 ***** @@ -213,11 +213,11 @@ int BLF_load_unique(const char *name) 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) @@ -292,45 +292,44 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size) 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; @@ -340,9 +339,8 @@ void BLF_aspect(int fontid, float x, float y, float z) void BLF_matrix(int fontid, const double m[16]) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); if (font) { memcpy(font->m, m, sizeof(font->m)); } @@ -350,9 +348,8 @@ void BLF_matrix(int fontid, const double m[16]) void BLF_position(int fontid, float x, float y, float z) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); if (font) { float xa, ya, za; float remainder; @@ -400,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) @@ -455,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) @@ -504,6 +501,7 @@ static void blf_draw__end(void) void BLF_draw(int fontid, const char *str, size_t len) { FontBLF *font= BLF_get(fontid); + if (font && font->glyph_cache) { blf_draw__start(font); blf_font_draw(font, str, len); @@ -514,6 +512,7 @@ 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 && font->glyph_cache) { blf_draw__start(font); blf_font_draw_ascii(font, str, len); @@ -523,39 +522,41 @@ 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 && font->glyph_cache) + 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); - font= BLF_get(fontid); - if (font && font->glyph_cache) + if (font && font->glyph_cache) { return blf_font_width(font, str); + } + return 0.0f; } float BLF_fixed_width(int fontid) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); - if (font && font->glyph_cache) + if (font && font->glyph_cache) { return blf_font_fixed_width(font); + } + return 0.0f; } @@ -575,54 +576,56 @@ float BLF_width_default(const char *str) float BLF_height(int fontid, const char *str) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); - if (font && font->glyph_cache) + if (font && font->glyph_cache) { return blf_font_height(font, str); + } + return 0.0f; } float BLF_height_max(int fontid) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); - if (font && font->glyph_cache) + if (font && font->glyph_cache) { return font->glyph_cache->max_glyph_height; + } + return 0.0f; } float BLF_width_max(int fontid) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); if (font && font->glyph_cache) { return font->glyph_cache->max_glyph_width; } + return 0.0f; } float BLF_descender(int fontid) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); if (font && font->glyph_cache) { return font->glyph_cache->descender; } + return 0.0f; } float BLF_ascender(int fontid) { - FontBLF *font; + FontBLF *font= BLF_get(fontid); - font= BLF_get(fontid); if (font && font->glyph_cache) { return font->glyph_cache->ascender; } + return 0.0f; } @@ -643,18 +646,17 @@ float BLF_height_default(const char *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; @@ -665,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; @@ -678,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; @@ -692,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; @@ -703,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; @@ -717,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; @@ -731,6 +728,7 @@ 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= BLF_get(fontid); + 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 d5d9969c421..1c99af0c7a9 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -188,7 +188,7 @@ char *blf_dir_metrics_search(const char *filename) mfile= BLI_strdup(filename); s= strrchr(mfile, '.'); if (s) { - if (strnlen(s, 4) < 4) { + if (BLI_strnlen(s, 4) < 4) { MEM_freeN(mfile); return NULL; } diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 92c68ccb85b..f3f3b759e5c 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -341,7 +341,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) FT_Vector delta; int pen_x= 0, pen_y= 0; unsigned int i= 0; - GlyphBLF **glyph_ascii_table; + GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table; rctf gbox; @@ -353,7 +353,6 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) box->ymax= -32000.0f; blf_font_ensure_ascii_table(font); - glyph_ascii_table= font->glyph_cache->glyph_ascii_table; while (str[i]) { -- cgit v1.2.3