And another commit to cleanup a little, this is the last,
next commit add internal font and we can go ahead and remove ftfont and bmfont.
This commit is contained in:
@@ -58,7 +58,6 @@
|
||||
#include "blf_internal_types.h"
|
||||
#include "blf_internal.h"
|
||||
|
||||
#ifdef WITH_FREETYPE2
|
||||
|
||||
/* Max number of font in memory.
|
||||
* Take care that now every font have a glyph cache per size/dpi,
|
||||
@@ -76,41 +75,33 @@ int global_font_num= 0;
|
||||
/* Current font. */
|
||||
int global_font_cur= 0;
|
||||
|
||||
#endif /* WITH_FREETYPE2 */
|
||||
|
||||
int BLF_init(void)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
int i;
|
||||
|
||||
for (i= 0; i < BLF_MAX_FONT; i++)
|
||||
global_font[i]= NULL;
|
||||
|
||||
return(blf_font_init());
|
||||
#else
|
||||
return(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLF_exit(void)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
int i;
|
||||
|
||||
for (i= 0; i < global_font_num; i++) {
|
||||
font= global_font[i];
|
||||
if(font)
|
||||
blf_font_free(font);
|
||||
if(font && font->free)
|
||||
(*font->free)(font);
|
||||
}
|
||||
|
||||
blf_font_exit();
|
||||
#endif
|
||||
}
|
||||
|
||||
int blf_search(char *name)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
int i;
|
||||
|
||||
@@ -119,13 +110,11 @@ int blf_search(char *name)
|
||||
if (font && (!strcmp(font->name, name)))
|
||||
return(i);
|
||||
}
|
||||
#endif
|
||||
return(-1);
|
||||
}
|
||||
|
||||
int BLF_load(char *name)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
char *filename;
|
||||
int i;
|
||||
@@ -153,6 +142,7 @@ int BLF_load(char *name)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
#ifdef WITH_FREETYPE2
|
||||
font= blf_font_new(name, filename);
|
||||
MEM_freeN(filename);
|
||||
|
||||
@@ -165,14 +155,13 @@ int BLF_load(char *name)
|
||||
i= global_font_num;
|
||||
global_font_num++;
|
||||
return(i);
|
||||
#else
|
||||
return(-1);
|
||||
#endif /* WITH_FREETYPE2 */
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
int i;
|
||||
|
||||
@@ -192,6 +181,7 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
#ifdef WITH_FREETYPE2
|
||||
font= blf_font_new_from_mem(name, mem, mem_size);
|
||||
if (!font) {
|
||||
printf("Can't load font, %s from memory!!\n", name);
|
||||
@@ -202,55 +192,45 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size)
|
||||
i= global_font_num;
|
||||
global_font_num++;
|
||||
return(i);
|
||||
#else
|
||||
return(-1);
|
||||
#endif /* WITH_FREETYPE2 */
|
||||
return(-1);
|
||||
}
|
||||
|
||||
void BLF_set(int fontid)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
if (fontid >= 0 && fontid < BLF_MAX_FONT)
|
||||
global_font_cur= fontid;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLF_enable(int option)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font)
|
||||
font->flags |= option;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLF_disable(int option)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font)
|
||||
font->flags &= ~option;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLF_aspect(float aspect)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font)
|
||||
font->aspect= aspect;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLF_position(float x, float y, float z)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
float remainder;
|
||||
|
||||
@@ -276,27 +256,23 @@ void BLF_position(float x, float y, float z)
|
||||
font->pos[1]= y;
|
||||
font->pos[2]= z;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLF_size(int size, int dpi)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font)
|
||||
blf_font_size(font, size, dpi);
|
||||
#endif
|
||||
if (font && font->size_set)
|
||||
(*font->size_set)(font, size, dpi);
|
||||
}
|
||||
|
||||
void BLF_draw(char *str)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font && font->glyph_cache) {
|
||||
if (font && font->draw && font->glyph_cache) {
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@@ -308,64 +284,54 @@ void BLF_draw(char *str)
|
||||
if (font->flags & BLF_ROTATION)
|
||||
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
blf_font_draw(font, str);
|
||||
(*font->draw)(font, str);
|
||||
|
||||
glPopMatrix();
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
#endif /* WITH_FREETYPE2 */
|
||||
}
|
||||
|
||||
void BLF_boundbox(char *str, rctf *box)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font && font->glyph_cache)
|
||||
blf_font_boundbox(font, str, box);
|
||||
#endif
|
||||
if (font && font->boundbox_get && font->glyph_cache)
|
||||
(*font->boundbox_get)(font, str, box);
|
||||
}
|
||||
|
||||
float BLF_width(char *str)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font && font->glyph_cache)
|
||||
return(blf_font_width(font, str));
|
||||
#endif
|
||||
if (font && font->width_get && font->glyph_cache)
|
||||
return((*font->width_get)(font, str));
|
||||
return(0.0f);
|
||||
}
|
||||
|
||||
float BLF_height(char *str)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font && font->glyph_cache)
|
||||
return(blf_font_height(font, str));
|
||||
#endif
|
||||
if (font && font->height_get && font->glyph_cache)
|
||||
return((*font->height_get)(font, str));
|
||||
return(0.0f);
|
||||
}
|
||||
|
||||
void BLF_rotation(float angle)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font)
|
||||
font->angle= angle;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLF_clipping(float xmin, float ymin, float xmax, float ymax)
|
||||
{
|
||||
#ifdef WITH_FREETYPE2
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
@@ -375,5 +341,4 @@ void BLF_clipping(float xmin, float ymin, float xmax, float ymax)
|
||||
font->clip_rec.xmax= xmax;
|
||||
font->clip_rec.ymax= ymax;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -73,78 +73,6 @@ void blf_font_exit(void)
|
||||
FT_Done_FreeType(global_ft_lib);
|
||||
}
|
||||
|
||||
void blf_font_fill(FontBLF *font)
|
||||
{
|
||||
font->type= BLF_FONT_FREETYPE2;
|
||||
font->ref= 1;
|
||||
font->aspect= 1.0f;
|
||||
font->pos[0]= 0.0f;
|
||||
font->pos[1]= 0.0f;
|
||||
font->angle= 0.0f;
|
||||
Mat4One(font->mat);
|
||||
font->clip_rec.xmin= 0.0f;
|
||||
font->clip_rec.xmax= 0.0f;
|
||||
font->clip_rec.ymin= 0.0f;
|
||||
font->clip_rec.ymax= 0.0f;
|
||||
font->flags= 0;
|
||||
font->dpi= 0;
|
||||
font->size= 0;
|
||||
font->cache.first= NULL;
|
||||
font->cache.last= NULL;
|
||||
font->glyph_cache= NULL;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);
|
||||
}
|
||||
|
||||
FontBLF *blf_font_new(char *name, char *filename)
|
||||
{
|
||||
FontBLF *font;
|
||||
FT_Error err;
|
||||
FT_Face face;
|
||||
|
||||
err= FT_New_Face(global_ft_lib, filename, 0, &face);
|
||||
if (err)
|
||||
return(NULL);
|
||||
|
||||
err= FT_Select_Charmap(face, ft_encoding_unicode);
|
||||
if (err) {
|
||||
printf("Can't set the unicode character map!\n");
|
||||
FT_Done_Face(face);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
|
||||
font->name= BLI_strdup(name);
|
||||
font->filename= BLI_strdup(filename);
|
||||
font->engine= (void *)face;
|
||||
blf_font_fill(font);
|
||||
return(font);
|
||||
}
|
||||
|
||||
FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size)
|
||||
{
|
||||
FontBLF *font;
|
||||
FT_Error err;
|
||||
FT_Face face;
|
||||
|
||||
err= FT_New_Memory_Face(global_ft_lib, mem, mem_size, 0, &face);
|
||||
if (err)
|
||||
return(NULL);
|
||||
|
||||
err= FT_Select_Charmap(face, ft_encoding_unicode);
|
||||
if (err) {
|
||||
printf("Can't set the unicode character map!\n");
|
||||
FT_Done_Face(face);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new_from_mem");
|
||||
font->name= BLI_strdup(name);
|
||||
font->filename= NULL;
|
||||
font->engine= (void *)face;
|
||||
blf_font_fill(font);
|
||||
return(font);
|
||||
}
|
||||
|
||||
void blf_font_size(FontBLF *font, int size, int dpi)
|
||||
{
|
||||
GlyphCacheBLF *gc;
|
||||
@@ -331,4 +259,94 @@ void blf_font_free(FontBLF *font)
|
||||
MEM_freeN(font);
|
||||
}
|
||||
|
||||
void blf_font_fill(FontBLF *font)
|
||||
{
|
||||
font->type= BLF_FONT_FREETYPE2;
|
||||
font->ref= 1;
|
||||
font->aspect= 1.0f;
|
||||
font->pos[0]= 0.0f;
|
||||
font->pos[1]= 0.0f;
|
||||
font->angle= 0.0f;
|
||||
Mat4One(font->mat);
|
||||
font->clip_rec.xmin= 0.0f;
|
||||
font->clip_rec.xmax= 0.0f;
|
||||
font->clip_rec.ymin= 0.0f;
|
||||
font->clip_rec.ymax= 0.0f;
|
||||
font->flags= 0;
|
||||
font->dpi= 0;
|
||||
font->size= 0;
|
||||
font->cache.first= NULL;
|
||||
font->cache.last= NULL;
|
||||
font->glyph_cache= NULL;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);
|
||||
|
||||
font->size_set= blf_font_size;
|
||||
font->draw= blf_font_draw;
|
||||
font->boundbox_get= blf_font_boundbox;
|
||||
font->width_get= blf_font_width;
|
||||
font->height_get= blf_font_height;
|
||||
font->free= blf_font_free;
|
||||
}
|
||||
|
||||
FontBLF *blf_font_new(char *name, char *filename)
|
||||
{
|
||||
FontBLF *font;
|
||||
FT_Error err;
|
||||
FT_Face face;
|
||||
|
||||
err= FT_New_Face(global_ft_lib, filename, 0, &face);
|
||||
if (err)
|
||||
return(NULL);
|
||||
|
||||
err= FT_Select_Charmap(face, ft_encoding_unicode);
|
||||
if (err) {
|
||||
printf("Can't set the unicode character map!\n");
|
||||
FT_Done_Face(face);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new");
|
||||
font->name= BLI_strdup(name);
|
||||
font->filename= BLI_strdup(filename);
|
||||
font->engine= (void *)face;
|
||||
blf_font_fill(font);
|
||||
return(font);
|
||||
}
|
||||
|
||||
FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size)
|
||||
{
|
||||
FontBLF *font;
|
||||
FT_Error err;
|
||||
FT_Face face;
|
||||
|
||||
err= FT_New_Memory_Face(global_ft_lib, mem, mem_size, 0, &face);
|
||||
if (err)
|
||||
return(NULL);
|
||||
|
||||
err= FT_Select_Charmap(face, ft_encoding_unicode);
|
||||
if (err) {
|
||||
printf("Can't set the unicode character map!\n");
|
||||
FT_Done_Face(face);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new_from_mem");
|
||||
font->name= BLI_strdup(name);
|
||||
font->filename= NULL;
|
||||
font->engine= (void *)face;
|
||||
blf_font_fill(font);
|
||||
return(font);
|
||||
}
|
||||
|
||||
#else /* !WITH_FREETYPE2 */
|
||||
|
||||
int blf_font_init(void)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
void blf_font_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* WITH_FREETYPE2 */
|
||||
|
||||
@@ -35,21 +35,14 @@ int blf_utf8_next(unsigned char *buf, int *iindex);
|
||||
char *blf_dir_search(const char *file);
|
||||
int blf_dir_split(const char *str, char *file, int *size);
|
||||
|
||||
#ifdef WITH_FREETYPE2
|
||||
|
||||
int blf_font_init(void);
|
||||
void blf_font_exit(void);
|
||||
|
||||
#ifdef WITH_FREETYPE2
|
||||
|
||||
FontBLF *blf_font_new(char *name, char *filename);
|
||||
FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size);
|
||||
|
||||
void blf_font_free(FontBLF *font);
|
||||
void blf_font_size(FontBLF *font, int size, int dpi);
|
||||
void blf_font_draw(FontBLF *font, char *str);
|
||||
void blf_font_boundbox(FontBLF *font, char *str, rctf *box);
|
||||
float blf_font_width(FontBLF *font, char *str);
|
||||
float blf_font_height(FontBLF *font, char *str);
|
||||
|
||||
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi);
|
||||
GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font);
|
||||
void blf_glyph_cache_free(GlyphCacheBLF *gc);
|
||||
|
||||
@@ -161,6 +161,14 @@ typedef struct FontBLF {
|
||||
|
||||
/* engine data. */
|
||||
void *engine;
|
||||
|
||||
/* engine functions. */
|
||||
void (*size_set)(struct FontBLF *, int, int);
|
||||
void (*draw)(struct FontBLF *, char *);
|
||||
void (*boundbox_get)(struct FontBLF *, char *, rctf *);
|
||||
float (*width_get)(struct FontBLF *, char *);
|
||||
float (*height_get)(struct FontBLF *, char *);
|
||||
void (*free)(struct FontBLF *);
|
||||
} FontBLF;
|
||||
|
||||
typedef struct DirBLF {
|
||||
|
||||
Reference in New Issue
Block a user