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:
authorCampbell Barton <ideasman42@gmail.com>2011-09-18 14:34:13 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-09-18 14:34:13 +0400
commit53845a37d9d33703e18236212ee3ef52982a6247 (patch)
tree06f89615df2b2411bee99032e711210cfdc9bdef /source/blender/blenfont/intern/blf_font.c
parent249b41762a98b5e357cc32e0ba0cb673fc0c6225 (diff)
blf - further shrink drawing functions & some style changes.
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r--source/blender/blenfont/intern/blf_font.c91
1 files changed, 35 insertions, 56 deletions
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;
}