diff options
author | Diego Borghetti <bdiego@gmail.com> | 2009-04-24 01:57:41 +0400 |
---|---|---|
committer | Diego Borghetti <bdiego@gmail.com> | 2009-04-24 01:57:41 +0400 |
commit | efd1a69d6c12d97594c93857365547a56e6792e9 (patch) | |
tree | bf509b370b103c2b6db14a318f79dcf361030da5 /source | |
parent | 1b95d684afd7153a16ebb6d9af16b60b56fc1159 (diff) |
Move texture draw to blf_util.c, now both font used it.
A little cleanup on the internal font, it's possible load the old
bmfont with: BLF_load_mem(name, NULL, 0) where name can be: helv,
helvb or scr.
Note that the internal font also support both draw, texture and bitmap,
by default always used texture.
Remove some old lang function that I left there and don't exist any more
because the locale are now in the RNA.
Small changes to Style's, so if we build without freetype2 by default
go back to the internal font, this is a little ugly (and have the old
problem of scale) but now blender always show text (need work a little
more there).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 36 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 14 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 69 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal.c | 108 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal.h | 4 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal_types.h | 8 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_lang.c | 7 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_util.c | 63 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 19 |
9 files changed, 187 insertions, 141 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index adf9742cc9f..510ff550acc 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -43,6 +43,12 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size); void BLF_set(int fontid); int BLF_get(void); +/* + * Return the font type, can be freetype2 or internal, -1 if + * some error happen (no current font). + */ +int BLF_type_get(void); + void BLF_aspect(float aspect); void BLF_position(float x, float y, float z); void BLF_size(int size, int dpi); @@ -74,25 +80,17 @@ void BLF_blur(int size); void BLF_enable(int option); void BLF_disable(int option); -/* Read the .Blanguages file, return 1 on success or 0 if fails. */ -int BLF_lang_init(void); - -/* Free the memory allocate for the .Blanguages. */ -void BLF_lang_exit(void); - -/* Set the current Language. */ -void BLF_lang_set(int id); - -/* Return a string with all the Language available. */ -char *BLF_lang_pup(void); - -/* Return the number of invalid lines in the .Blanguages file, - * zero means no error found. +/* + * Search the path directory to the locale files, this try all + * the case for Linux, Win and Mac. */ -int BLF_lang_error(void); +void BLF_lang_init(void); -/* Return the code string for the specified language code. */ -char *BLF_lang_find_code(short langid); +/* Set the current locale. */ +void BLF_lang_set(const char *); + +/* Set the current encoding name. */ +void BLF_lang_encoding_name(const char *str); /* Add a path to the font dir paths. */ void BLF_dir_add(const char *path); @@ -114,4 +112,8 @@ void BLF_dir_free(char **dirs, int count); #define BLF_MODE_TEXTURE 0 #define BLF_MODE_BITMAP 1 +/* font->type */ +#define BLF_FONT_FREETYPE2 0 +#define BLF_FONT_INTERNAL 1 + #endif /* BLF_API_H */ diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index e5c1e675294..e43d7905cf9 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -185,7 +185,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size) if (!font) { #ifdef WITH_FREETYPE2 if (!mem || !mem_size) { - printf("Can't load font, %s from memory!!\n", name); + printf("Can't load font: %s from memory!!\n", name); return(-1); } @@ -193,7 +193,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size) #endif /* WITH_FREETYPE2 */ if (!font) { - printf("Can't load font, %s from memory!!\n", name); + printf("Can't load font: %s from memory!!\n", name); return(-1); } } @@ -215,6 +215,16 @@ int BLF_get(void) return(global_font_cur); } +int BLF_type_get(void) +{ + FontBLF *font; + + font= global_font[global_font_cur]; + if (font) + return(font->type); + return(-1); +} + void BLF_enable(int option) { FontBLF *font; diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index bdec76e01ff..510204b0f51 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -433,69 +433,6 @@ void blf_glyph_free(GlyphBLF *g) MEM_freeN(g); } -static void blf_glyph_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2) -{ - - glBegin(GL_QUADS); - glTexCoord2f(uv[0][0], uv[0][1]); - glVertex2f(dx, y1); - - glTexCoord2f(uv[0][0], uv[1][1]); - glVertex2f(dx, y2); - - glTexCoord2f(uv[1][0], uv[1][1]); - glVertex2f(dx1, y2); - - glTexCoord2f(uv[1][0], uv[0][1]); - glVertex2f(dx1, y1); - glEnd(); - -} - -static void blf_glyph_texture5_draw(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 color[4], *fp= soft; - int dx, dy; - - glGetFloatv(GL_CURRENT_COLOR, color); - - for(dx=-2; dx<3; dx++) { - for(dy=-2; dy<3; dy++, fp++) { - glColor4f(color[0], color[1], color[2], fp[0]*color[3]); - blf_glyph_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); - } - } - - glColor4fv(color); -} - -static void blf_glyph_texture3_draw(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 color[4], *fp= soft; - int dx, dy; - - glGetFloatv(GL_CURRENT_COLOR, color); - - for(dx=-1; dx<2; dx++) { - for(dy=-1; dy<2; dy++, fp++) { - glColor4f(color[0], color[1], color[2], fp[0]*color[3]); - blf_glyph_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); - } - } - - glColor4fv(color); -} - - - int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y) { GlyphTextureBLF *gt; @@ -525,11 +462,11 @@ int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y) glBindTexture(GL_TEXTURE_2D, gt->tex); if (font->blur==3) - blf_glyph_texture3_draw(gt->uv, dx, y1, dx1, y2); + blf_texture3_draw(gt->uv, dx, y1, dx1, y2); else if (font->blur==5) - blf_glyph_texture5_draw(gt->uv, dx, y1, dx1, y2); + blf_texture5_draw(gt->uv, dx, y1, dx1, y2); else - blf_glyph_texture_draw(gt->uv, dx, y1, dx1, y2); + blf_texture_draw(gt->uv, dx, y1, dx1, y2); return(1); } diff --git a/source/blender/blenfont/intern/blf_internal.c b/source/blender/blenfont/intern/blf_internal.c index bc569e3d080..414ec5abead 100644 --- a/source/blender/blenfont/intern/blf_internal.c +++ b/source/blender/blenfont/intern/blf_internal.c @@ -141,7 +141,58 @@ int blf_internal_get_texture(FontBLF *font) void blf_internal_size(FontBLF *font, int size, int dpi) { - return; + /* dpi don't work here and size is limit to: + * helv: 10, 12 + * helvb: 8, 10, 12 + * scr: 12, 14, 15 + */ + font->dpi= dpi; + + if (font->size != size) { + if (!strcmp(font->name, "helv")) { + if (size == 12) { + font->engine= (void *)&blf_font_helv12; + font->size= 12; + } + else { + font->engine= (void *)&blf_font_helv10; + font->size= 10; + } + } + else if (!strcmp(font->name, "helvb")) { + if (size == 10) { + font->engine= (void *)&blf_font_helvb10; + font->size= 10; + } + else if (size == 12) { + font->engine= (void *)&blf_font_helvb12; + font->size= 12; + } + else { + font->engine= (void *)&blf_font_helvb8; + font->size= 8; + } + } + else { /* scr */ + if (size == 14) { + font->engine= (void *)&blf_font_scr14; + font->size= 14; + } + else if (size == 15) { + font->engine= (void *)&blf_font_scr15; + font->size= 15; + } + else { + font->engine= (void *)&blf_font_scr12; + font->size= 12; + } + } + + if (font->mode == BLF_MODE_TEXTURE) { + if (blf_internal_get_texture(font) != 0) + printf("Can't create texture font!!\n"); + } + } } void blf_internal_texture_draw(FontBLF *font, char *str) @@ -149,7 +200,8 @@ void blf_internal_texture_draw(FontBLF *font, char *str) FontDataBLF *data; CharDataBLF *cd; unsigned char c; - float pos, cell_x, cell_y, x, y, z; + float pos, x, y; + float uv[2][2]; int base_line; GLint cur_tex; float dx, dx1, dy, dy1; @@ -159,7 +211,6 @@ void blf_internal_texture_draw(FontBLF *font, char *str) pos= 0; x= 0.0f; y= 0.0f; - z= 0.0f; glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex); if (cur_tex != data->texid) @@ -169,8 +220,10 @@ void blf_internal_texture_draw(FontBLF *font, char *str) cd= &data->chars[c]; if (cd->data_offset != -1) { - cell_x= (c%16)/16.0; - cell_y= (c/16)/16.0; + uv[0][0]= ((c%16)/16.0) + 1.0/16.0; + uv[0][1]= (c/16)/16.0; + uv[1][0]= (c%16)/16.0; + uv[1][1]= ((c/16)/16.0) + 1.0/16.0; dx= x + pos + 16.0; dx1= x + pos + 0.0; @@ -189,19 +242,12 @@ void blf_internal_texture_draw(FontBLF *font, char *str) goto next_tex_char; } - glBegin(GL_QUADS); - glTexCoord2f(cell_x + 1.0/16.0, cell_y); - glVertex3f(dx, dy, z); - - glTexCoord2f(cell_x + 1.0/16.0, cell_y + 1.0/16.0); - glVertex3f(dx, dy1, z); - - glTexCoord2f(cell_x, cell_y + 1.0/16.0); - glVertex3f(dx1, dy1, z); - - glTexCoord2f(cell_x, cell_y); - glVertex3f(dx1, dy, z); - glEnd(); + if (font->blur == 3) + blf_texture3_draw(uv, dx, dy, dx1, dy1); + else if (font->blur == 5) + blf_texture5_draw(uv, dx, dy, dx1, dy1); + else + blf_texture_draw(uv, dx, dy, dx1, dy1); } next_tex_char: pos += cd->advance; @@ -328,39 +374,19 @@ FontBLF *blf_internal_new(char *name) font->name= BLI_strdup(name); font->filename= NULL; - if (!strcmp(name, "helv10")) { + if (!strcmp(name, "helv")) { font->engine= (void *)&blf_font_helv10; font->size= 10; } #ifndef BLF_INTERNAL_MINIMAL - else if (!strcmp(name, "helv12")) { - font->engine= (void *)&blf_font_helv12; - font->size= 12; - } - else if (!strcmp(name, "helvb8")) { + else if (!strcmp(name, "helvb")) { font->engine= (void *)&blf_font_helvb8; font->size= 8; } - else if (!strcmp(name, "helvb10")) { - font->engine= (void *)&blf_font_helvb10; - font->size= 10; - } - else if (!strcmp(name, "helvb12")) { - font->engine= (void *)&blf_font_helvb12; - font->size= 12; - } - else if (!strcmp(name, "scr12")) { + else if (!strcmp(name, "scr")) { font->engine= (void *)&blf_font_scr12; font->size= 12; } - else if (!strcmp(name, "scr14")) { - font->engine= (void *)&blf_font_scr14; - font->size= 14; - } - else if (!strcmp(name, "scr15")) { - font->engine= (void *)&blf_font_scr15; - font->size= 15; - } #endif else font->engine= NULL; diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 87d5938db9c..a042eefb4d9 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -32,6 +32,10 @@ unsigned int blf_next_p2(unsigned int x); unsigned int blf_hash(unsigned int val); int blf_utf8_next(unsigned char *buf, int *iindex); +void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2); +void blf_texture5_draw(float uv[2][2], float x1, float y1, float x2, float y2); +void blf_texture3_draw(float uv[2][2], float x1, float y1, float x2, float y2); + char *blf_dir_search(const char *file); int blf_dir_split(const char *str, char *file, int *size); diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index cf42dc69f77..da2d3c17f79 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -223,12 +223,4 @@ typedef struct DirBLF { char *path; } DirBLF; -/* font->clip_mode */ -#define BLF_CLIP_DISABLE 0 -#define BLF_CLIP_OUT 1 - -/* font->type */ -#define BLF_FONT_FREETYPE2 0 -#define BLF_FONT_INTERNAL 1 - #endif /* BLF_INTERNAL_TYPES_H */ diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index c871435ff0f..024172d6db4 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -107,7 +107,7 @@ void BLF_lang_init(void) } } -void BLF_lang_set(char *str) +void BLF_lang_set(const char *str) { #if defined (_WIN32) || defined(__APPLE__) char envstr[12]; @@ -140,14 +140,13 @@ void BLF_lang_set(char *str) setlocale(LC_NUMERIC, "C"); #endif - + textdomain(DOMAIN_NAME); bindtextdomain(DOMAIN_NAME, global_messagepath); /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */ - textdomain(DOMAIN_NAME); strcpy(global_language, str); } -void BLF_lang_encoding(char *str) +void BLF_lang_encoding(const char *str) { strcpy(global_encoding_name, str); /* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */ diff --git a/source/blender/blenfont/intern/blf_util.c b/source/blender/blenfont/intern/blf_util.c index a4ccbedc38b..8de6aea754b 100644 --- a/source/blender/blenfont/intern/blf_util.c +++ b/source/blender/blenfont/intern/blf_util.c @@ -30,6 +30,8 @@ #include <stdlib.h> #include <string.h> +#include "BIF_gl.h" + unsigned int blf_next_p2(unsigned int x) { @@ -129,3 +131,64 @@ int blf_utf8_next(unsigned char *buf, int *iindex) *iindex= index; return(r); } + +void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2) +{ + + glBegin(GL_QUADS); + glTexCoord2f(uv[0][0], uv[0][1]); + glVertex2f(dx, y1); + + glTexCoord2f(uv[0][0], uv[1][1]); + glVertex2f(dx, y2); + + glTexCoord2f(uv[1][0], uv[1][1]); + glVertex2f(dx1, y2); + + glTexCoord2f(uv[1][0], uv[0][1]); + glVertex2f(dx1, y1); + glEnd(); + +} + +void blf_texture5_draw(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 color[4], *fp= soft; + int dx, dy; + + glGetFloatv(GL_CURRENT_COLOR, color); + + for(dx=-2; dx<3; dx++) { + for(dy=-2; dy<3; dy++, fp++) { + glColor4f(color[0], color[1], color[2], fp[0]*color[3]); + blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); + } + } + + glColor4fv(color); +} + +void blf_texture3_draw(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 color[4], *fp= soft; + int dx, dy; + + glGetFloatv(GL_CURRENT_COLOR, color); + + for(dx=-1; dx<2; dx++) { + for(dy=-1; dy<2; dy++, fp++) { + glColor4f(color[0], color[1], color[2], fp[0]*color[3]); + blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy); + } + } + + glColor4fv(color); +} diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 99702097329..87e70523870 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -165,7 +165,11 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str) xofs= rect->xmax - rect->xmin - BLF_width(str); /* clip is very strict, so we give it some space */ - BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+4, rect->ymax+4); + if (BLF_type_get() == BLF_FONT_INTERNAL) + BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+8, rect->ymax+4); + else + BLF_clipping(rect->xmin-4, rect->ymin-4, rect->xmax+4, rect->ymax+4); + BLF_enable(BLF_CLIPPING); if(fs->shadow) @@ -229,12 +233,21 @@ void uiStyleInit(void) if(font->blf_id == -1) font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); } - + + if (font->blf_id == -1) { + /* when all fail, we go back to the internal font. */ + font->blf_id= BLF_load_mem("helv", NULL, 0); + } + if (font->blf_id == -1) printf("uiStyleInit error, no fonts available\n"); else { BLF_set(font->blf_id); - BLF_size(11, U.dpi); /* ? just for speed to initialize? */ + /* ? just for speed to initialize? + * Yes but only if we used the freetype2 library, + * this build the glyph cache and create the texture. + */ + BLF_size(11, U.dpi); BLF_size(12, U.dpi); BLF_size(14, U.dpi); } |