[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40320] trunk/blender/source/blender/ blenfont/intern: blf code - no functional changes.
Campbell Barton
ideasman42 at gmail.com
Sun Sep 18 11:48:09 CEST 2011
Revision: 40320
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40320
Author: campbellbarton
Date: 2011-09-18 09:48:09 +0000 (Sun, 18 Sep 2011)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/blenfont/intern/blf.c
trunk/blender/source/blender/blenfont/intern/blf_font.c
trunk/blender/source/blender/blenfont/intern/blf_lang.c
Modified: trunk/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf.c 2011-09-18 09:46:47 UTC (rev 40319)
+++ trunk/blender/source/blender/blenfont/intern/blf.c 2011-09-18 09:48:09 UTC (rev 40320)
@@ -505,7 +505,7 @@
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_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 @@
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 @@
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 @@
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 @@
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 @@
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_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);
+ }
}
Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c 2011-09-18 09:46:47 UTC (rev 40319)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c 2011-09-18 09:48:09 UTC (rev 40320)
@@ -136,25 +136,37 @@
} \
+#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;
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,26 +175,10 @@
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == 0)
- break;
+ if (c == 0) break;
+ if (g == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
- /* 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;
- }
-
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
@@ -198,40 +194,20 @@
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 ((g= glyph_ascii_table[c]) == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
- /* 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;
- }
-
/* 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 @@
}
}
+/* Sanity checks are done by BLF_draw_buffer() */
void blf_font_buffer(FontBLF *font, const char *str)
{
unsigned char *cbuf;
@@ -248,18 +225,15 @@
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;
- if (!font->glyph_cache || (!font->b_fbuf && !font->b_cbuf))
- return;
- glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
-
+ BLF_KERNING_VARS(font, has_kerning, kern_mode);
+
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,30 +244,13 @@
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 (c == 0) break;
+ if (g == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
- /* 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;
- }
-
chx= pen_x + ((int)g->pos_x);
chy= (int)font->pos[1] + g->height;
@@ -394,15 +351,14 @@
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;
box->ymin= 32000.0f;
@@ -411,7 +367,6 @@
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,26 +376,10 @@
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (c == 0)
- break;
+ if (c == 0) break;
+ if (g == NULL) continue;
+ if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
- /* 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;
- }
-
gbox.xmin= pen_x;
gbox.xmax= pen_x + g->advance;
gbox.ymin= g->box.ymin + pen_y;
@@ -473,20 +412,18 @@
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 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 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_fixed_width(FontBLF *font)
{
- GlyphBLF *g;
- FT_UInt glyph_index;
- unsigned int 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 (!font->glyph_cache)
- return 0.0f;
+ /* if we don't find the glyph. */
+ if (!g) {
+ 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);
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list