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).
This commit is contained in:
Diego Borghetti 2009-04-23 21:57:41 +00:00
parent 1b95d684af
commit efd1a69d6c
9 changed files with 187 additions and 141 deletions

@ -43,6 +43,12 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size);
void BLF_set(int fontid); void BLF_set(int fontid);
int BLF_get(void); 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_aspect(float aspect);
void BLF_position(float x, float y, float z); void BLF_position(float x, float y, float z);
void BLF_size(int size, int dpi); void BLF_size(int size, int dpi);
@ -74,25 +80,17 @@ void BLF_blur(int size);
void BLF_enable(int option); void BLF_enable(int option);
void BLF_disable(int option); void BLF_disable(int option);
/* Read the .Blanguages file, return 1 on success or 0 if fails. */ /*
int BLF_lang_init(void); * Search the path directory to the locale files, this try all
* the case for Linux, Win and Mac.
/* 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.
*/ */
int BLF_lang_error(void); void BLF_lang_init(void);
/* Return the code string for the specified language code. */ /* Set the current locale. */
char *BLF_lang_find_code(short langid); 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. */ /* Add a path to the font dir paths. */
void BLF_dir_add(const char *path); 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_TEXTURE 0
#define BLF_MODE_BITMAP 1 #define BLF_MODE_BITMAP 1
/* font->type */
#define BLF_FONT_FREETYPE2 0
#define BLF_FONT_INTERNAL 1
#endif /* BLF_API_H */ #endif /* BLF_API_H */

@ -185,7 +185,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
if (!font) { if (!font) {
#ifdef WITH_FREETYPE2 #ifdef WITH_FREETYPE2
if (!mem || !mem_size) { 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); return(-1);
} }
@ -193,7 +193,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
#endif /* WITH_FREETYPE2 */ #endif /* WITH_FREETYPE2 */
if (!font) { if (!font) {
printf("Can't load font, %s from memory!!\n", name); printf("Can't load font: %s from memory!!\n", name);
return(-1); return(-1);
} }
} }
@ -215,6 +215,16 @@ int BLF_get(void)
return(global_font_cur); 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) void BLF_enable(int option)
{ {
FontBLF *font; FontBLF *font;

@ -433,69 +433,6 @@ void blf_glyph_free(GlyphBLF *g)
MEM_freeN(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) int blf_glyph_texture_render(FontBLF *font, GlyphBLF *g, float x, float y)
{ {
GlyphTextureBLF *gt; 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); glBindTexture(GL_TEXTURE_2D, gt->tex);
if (font->blur==3) 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) 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 else
blf_glyph_texture_draw(gt->uv, dx, y1, dx1, y2); blf_texture_draw(gt->uv, dx, y1, dx1, y2);
return(1); return(1);
} }

@ -141,7 +141,58 @@ int blf_internal_get_texture(FontBLF *font)
void blf_internal_size(FontBLF *font, int size, int dpi) 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) void blf_internal_texture_draw(FontBLF *font, char *str)
@ -149,7 +200,8 @@ void blf_internal_texture_draw(FontBLF *font, char *str)
FontDataBLF *data; FontDataBLF *data;
CharDataBLF *cd; CharDataBLF *cd;
unsigned char c; unsigned char c;
float pos, cell_x, cell_y, x, y, z; float pos, x, y;
float uv[2][2];
int base_line; int base_line;
GLint cur_tex; GLint cur_tex;
float dx, dx1, dy, dy1; float dx, dx1, dy, dy1;
@ -159,7 +211,6 @@ void blf_internal_texture_draw(FontBLF *font, char *str)
pos= 0; pos= 0;
x= 0.0f; x= 0.0f;
y= 0.0f; y= 0.0f;
z= 0.0f;
glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex); glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex);
if (cur_tex != data->texid) if (cur_tex != data->texid)
@ -169,8 +220,10 @@ void blf_internal_texture_draw(FontBLF *font, char *str)
cd= &data->chars[c]; cd= &data->chars[c];
if (cd->data_offset != -1) { if (cd->data_offset != -1) {
cell_x= (c%16)/16.0; uv[0][0]= ((c%16)/16.0) + 1.0/16.0;
cell_y= (c/16)/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; dx= x + pos + 16.0;
dx1= x + pos + 0.0; dx1= x + pos + 0.0;
@ -189,19 +242,12 @@ void blf_internal_texture_draw(FontBLF *font, char *str)
goto next_tex_char; goto next_tex_char;
} }
glBegin(GL_QUADS); if (font->blur == 3)
glTexCoord2f(cell_x + 1.0/16.0, cell_y); blf_texture3_draw(uv, dx, dy, dx1, dy1);
glVertex3f(dx, dy, z); else if (font->blur == 5)
blf_texture5_draw(uv, dx, dy, dx1, dy1);
glTexCoord2f(cell_x + 1.0/16.0, cell_y + 1.0/16.0); else
glVertex3f(dx, dy1, z); blf_texture_draw(uv, dx, dy, dx1, dy1);
glTexCoord2f(cell_x, cell_y + 1.0/16.0);
glVertex3f(dx1, dy1, z);
glTexCoord2f(cell_x, cell_y);
glVertex3f(dx1, dy, z);
glEnd();
} }
next_tex_char: next_tex_char:
pos += cd->advance; pos += cd->advance;
@ -328,39 +374,19 @@ FontBLF *blf_internal_new(char *name)
font->name= BLI_strdup(name); font->name= BLI_strdup(name);
font->filename= NULL; font->filename= NULL;
if (!strcmp(name, "helv10")) { if (!strcmp(name, "helv")) {
font->engine= (void *)&blf_font_helv10; font->engine= (void *)&blf_font_helv10;
font->size= 10; font->size= 10;
} }
#ifndef BLF_INTERNAL_MINIMAL #ifndef BLF_INTERNAL_MINIMAL
else if (!strcmp(name, "helv12")) { else if (!strcmp(name, "helvb")) {
font->engine= (void *)&blf_font_helv12;
font->size= 12;
}
else if (!strcmp(name, "helvb8")) {
font->engine= (void *)&blf_font_helvb8; font->engine= (void *)&blf_font_helvb8;
font->size= 8; font->size= 8;
} }
else if (!strcmp(name, "helvb10")) { else if (!strcmp(name, "scr")) {
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")) {
font->engine= (void *)&blf_font_scr12; font->engine= (void *)&blf_font_scr12;
font->size= 12; 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 #endif
else else
font->engine= NULL; font->engine= NULL;

@ -32,6 +32,10 @@ unsigned int blf_next_p2(unsigned int x);
unsigned int blf_hash(unsigned int val); unsigned int blf_hash(unsigned int val);
int blf_utf8_next(unsigned char *buf, int *iindex); 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); char *blf_dir_search(const char *file);
int blf_dir_split(const char *str, char *file, int *size); int blf_dir_split(const char *str, char *file, int *size);

@ -223,12 +223,4 @@ typedef struct DirBLF {
char *path; char *path;
} DirBLF; } 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 */ #endif /* BLF_INTERNAL_TYPES_H */

@ -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__) #if defined (_WIN32) || defined(__APPLE__)
char envstr[12]; char envstr[12];
@ -140,14 +140,13 @@ void BLF_lang_set(char *str)
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
#endif #endif
textdomain(DOMAIN_NAME);
bindtextdomain(DOMAIN_NAME, global_messagepath); bindtextdomain(DOMAIN_NAME, global_messagepath);
/* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */ /* bind_textdomain_codeset(DOMAIN_NAME, global_encoding_name); */
textdomain(DOMAIN_NAME);
strcpy(global_language, str); strcpy(global_language, str);
} }
void BLF_lang_encoding(char *str) void BLF_lang_encoding(const char *str)
{ {
strcpy(global_encoding_name, str); strcpy(global_encoding_name, str);
/* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */ /* bind_textdomain_codeset(DOMAIN_NAME, encoding_name); */

@ -30,6 +30,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "BIF_gl.h"
unsigned int blf_next_p2(unsigned int x) unsigned int blf_next_p2(unsigned int x)
{ {
@ -129,3 +131,64 @@ int blf_utf8_next(unsigned char *buf, int *iindex)
*iindex= index; *iindex= index;
return(r); 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);
}

@ -165,7 +165,11 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str)
xofs= rect->xmax - rect->xmin - BLF_width(str); xofs= rect->xmax - rect->xmin - BLF_width(str);
/* clip is very strict, so we give it some space */ /* 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); BLF_enable(BLF_CLIPPING);
if(fs->shadow) if(fs->shadow)
@ -229,12 +233,21 @@ void uiStyleInit(void)
if(font->blf_id == -1) if(font->blf_id == -1)
font->blf_id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); 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) if (font->blf_id == -1)
printf("uiStyleInit error, no fonts available\n"); printf("uiStyleInit error, no fonts available\n");
else { else {
BLF_set(font->blf_id); 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(12, U.dpi);
BLF_size(14, U.dpi); BLF_size(14, U.dpi);
} }