From 749a9083318f7d59999c1f3ce891db658e089772 Mon Sep 17 00:00:00 2001 From: Diego Borghetti Date: Fri, 8 May 2009 19:47:40 +0000 Subject: Cleanup blendfont. Now that we only work with Freetype2, I don't see any point to keep wrapping the functions. Also remove the reference code, it's something that we don't go to used. --- source/blender/blenfont/intern/blf.c | 30 +++++------ source/blender/blenfont/intern/blf_font.c | 60 +++++++++------------- source/blender/blenfont/intern/blf_glyph.c | 40 ++++++--------- source/blender/blenfont/intern/blf_internal.h | 6 +++ .../blender/blenfont/intern/blf_internal_types.h | 15 +----- 5 files changed, 63 insertions(+), 88 deletions(-) (limited to 'source/blender/blenfont/intern') diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index d49ca0bd0ac..c9728c51fe5 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -95,8 +95,8 @@ void BLF_exit(void) for (i= 0; i < global_font_num; i++) { font= global_font[i]; - if(font && font->free) - (*font->free)(font); + if (font) + blf_font_free(font); } blf_font_exit(); @@ -128,8 +128,6 @@ int BLF_load(char *name) i= blf_search(name); if (i >= 0) { font= global_font[i]; - font->ref++; - printf("Increment reference (%d): %s\n", font->ref, name); return(i); } @@ -169,8 +167,6 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size) i= blf_search(name); if (i >= 0) { font= global_font[i]; - font->ref++; - printf("Increment reference (%d): %s\n", font->ref, name); return(i); } @@ -268,8 +264,8 @@ void BLF_size(int size, int dpi) FontBLF *font; font= global_font[global_font_cur]; - if (font && font->size_set) - (*font->size_set)(font, size, dpi); + if (font) + blf_font_size(font, size, dpi); } void BLF_blur(int size) @@ -326,7 +322,7 @@ void BLF_draw(char *str) */ font= global_font[global_font_cur]; - if (font && font->draw) { + if (font) { if (font->mode == BLF_MODE_BITMAP) { glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT); glPushAttrib(GL_ENABLE_BIT); @@ -335,7 +331,7 @@ void BLF_draw(char *str) glDisable(GL_BLEND); glRasterPos3f(font->pos[0], font->pos[1], font->pos[2]); - (*font->draw)(font, str); + blf_font_draw(font, str); glPopAttrib(); glPopClientAttrib(); @@ -352,7 +348,7 @@ void BLF_draw(char *str) if (font->flags & BLF_ROTATION) glRotatef(font->angle, 0.0f, 0.0f, 1.0f); - (*font->draw)(font, str); + blf_font_draw(font, str); glPopMatrix(); glDisable(GL_BLEND); @@ -366,8 +362,8 @@ void BLF_boundbox(char *str, rctf *box) FontBLF *font; font= global_font[global_font_cur]; - if (font && font->boundbox_get) - (*font->boundbox_get)(font, str, box); + if (font) + blf_font_boundbox(font, str, box); } float BLF_width(char *str) @@ -375,8 +371,8 @@ float BLF_width(char *str) FontBLF *font; font= global_font[global_font_cur]; - if (font && font->width_get) - return((*font->width_get)(font, str)); + if (font) + return(blf_font_width(font, str)); return(0.0f); } @@ -418,8 +414,8 @@ float BLF_height(char *str) FontBLF *font; font= global_font[global_font_cur]; - if (font && font->height_get) - return((*font->height_get)(font, str)); + if (font) + return(blf_font_height(font, str)); return(0.0f); } diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 02b21264115..ac13387b92a 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -72,7 +72,7 @@ void blf_font_size(FontBLF *font, int size, int dpi) GlyphCacheBLF *gc; FT_Error err; - err= FT_Set_Char_Size((FT_Face)font->engine, 0, (size * 64), dpi, dpi); + err= FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi); if (err) { /* FIXME: here we can go through the fixed size and choice a close one */ printf("The current font don't support the size, %d and dpi, %d\n", size, dpi); @@ -99,7 +99,6 @@ void blf_font_draw(FontBLF *font, char *str) unsigned int c; GlyphBLF *g, *g_prev; FT_Vector delta; - FT_Face face; FT_UInt glyph_index, g_prev_index; int pen_x, pen_y; int i, has_kerning; @@ -107,11 +106,10 @@ void blf_font_draw(FontBLF *font, char *str) if (!font->glyph_cache) return; - face= (FT_Face)font->engine; i= 0; pen_x= 0; pen_y= 0; - has_kerning= FT_HAS_KERNING(face); + has_kerning= FT_HAS_KERNING(font->face); g_prev= NULL; g_prev_index= 0; @@ -120,7 +118,7 @@ void blf_font_draw(FontBLF *font, char *str) if (c == 0) break; - glyph_index= FT_Get_Char_Index(face, c); + 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); @@ -144,7 +142,7 @@ void blf_font_draw(FontBLF *font, char *str) delta.x= 0; delta.y= 0; - FT_Get_Kerning(face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta); + FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta); pen_x += delta.x >> 6; } @@ -163,7 +161,6 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box) GlyphBLF *g, *g_prev; FT_Vector delta; FT_UInt glyph_index, g_prev_index; - FT_Face face; rctf gbox; int pen_x, pen_y; int i, has_kerning; @@ -171,7 +168,6 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box) if (!font->glyph_cache) return; - face= (FT_Face)font->engine; box->xmin= 32000.0f; box->xmax= -32000.0f; box->ymin= 32000.0f; @@ -180,7 +176,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box) i= 0; pen_x= 0; pen_y= 0; - has_kerning= FT_HAS_KERNING(face); + has_kerning= FT_HAS_KERNING(font->face); g_prev= NULL; g_prev_index= 0; @@ -189,7 +185,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box) if (c == 0) break; - glyph_index= FT_Get_Char_Index(face, c); + 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); @@ -213,7 +209,7 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box) delta.x= 0; delta.y= 0; - FT_Get_Kerning(face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta); + FT_Get_Kerning(font->face, g_prev_index, glyph_index, FT_KERNING_UNFITTED, &delta); pen_x += delta.x >> 6; } @@ -278,7 +274,7 @@ void blf_font_free(FontBLF *font) blf_glyph_cache_free(gc); } - FT_Done_Face((FT_Face)font->engine); + FT_Done_Face(font->face); if (font->filename) MEM_freeN(font->filename); if (font->name) @@ -289,7 +285,6 @@ void blf_font_free(FontBLF *font) void blf_font_fill(FontBLF *font) { font->mode= BLF_MODE_TEXTURE; - font->ref= 1; font->aspect= 1.0f; font->pos[0]= 0.0f; font->pos[1]= 0.0f; @@ -305,37 +300,32 @@ void blf_font_fill(FontBLF *font) font->cache.first= NULL; font->cache.last= NULL; font->glyph_cache= NULL; + font->blur= 0; 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) + font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new"); + err= FT_New_Face(global_ft_lib, filename, 0, &font->face); + if (err) { + MEM_freeN(font); return(NULL); + } - err= FT_Select_Charmap(face, ft_encoding_unicode); + err= FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { printf("Can't set the unicode character map!\n"); - FT_Done_Face(face); + FT_Done_Face(font->face); + MEM_freeN(font); 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); } @@ -344,24 +334,24 @@ 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) + font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new_from_mem"); + err= FT_New_Memory_Face(global_ft_lib, mem, mem_size, 0, &font->face); + if (err) { + MEM_freeN(font); return(NULL); + } - err= FT_Select_Charmap(face, ft_encoding_unicode); + err= FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { printf("Can't set the unicode character map!\n"); - FT_Done_Face(face); + FT_Done_Face(font->face); + MEM_freeN(font); 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; - font->blur= 0; blf_font_fill(font); return(font); } diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 551db2cdaa9..142d2145ab2 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -72,10 +72,8 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi) GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) { GlyphCacheBLF *gc; - FT_Face face; int i; - face= (FT_Face)font->engine; gc= (GlyphCacheBLF *)MEM_mallocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new"); gc->next= NULL; gc->prev= NULL; @@ -94,23 +92,23 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) gc->y_offs= 0; gc->pad= 3; - gc->num_glyphs= face->num_glyphs; - gc->rem_glyphs= face->num_glyphs; - gc->ascender= ((float)face->size->metrics.ascender) / 64.0f; - gc->descender= ((float)face->size->metrics.descender) / 64.0f; + gc->num_glyphs= font->face->num_glyphs; + gc->rem_glyphs= font->face->num_glyphs; + gc->ascender= ((float)font->face->size->metrics.ascender) / 64.0f; + gc->descender= ((float)font->face->size->metrics.descender) / 64.0f; - if (FT_IS_SCALABLE(face)) { - gc->max_glyph_width= (float)((face->bbox.xMax - face->bbox.xMin) * - (((float)face->size->metrics.x_ppem) / - ((float)face->units_per_EM))); + if (FT_IS_SCALABLE(font->face)) { + gc->max_glyph_width= (float)((font->face->bbox.xMax - font->face->bbox.xMin) * + (((float)font->face->size->metrics.x_ppem) / + ((float)font->face->units_per_EM))); - gc->max_glyph_height= (float)((face->bbox.yMax - face->bbox.yMin) * - (((float)face->size->metrics.y_ppem) / - ((float)face->units_per_EM))); + gc->max_glyph_height= (float)((font->face->bbox.yMax - font->face->bbox.yMin) * + (((float)font->face->size->metrics.y_ppem) / + ((float)font->face->units_per_EM))); } else { - gc->max_glyph_width= ((float)face->size->metrics.max_advance) / 64.0f; - gc->max_glyph_height= ((float)face->size->metrics.height) / 64.0f; + gc->max_glyph_width= ((float)font->face->size->metrics.max_advance) / 64.0f; + gc->max_glyph_height= ((float)font->face->size->metrics.height) / 64.0f; } gc->p2_width= 0; @@ -197,7 +195,6 @@ GlyphBLF *blf_glyph_texture_add(FontBLF *font, FT_UInt index, unsigned int c) GlyphCacheBLF *gc; GlyphBLF *g; GlyphTextureBLF *gt; - FT_Face face; FT_Error err; FT_Bitmap bitmap; FT_BBox bbox; @@ -216,13 +213,12 @@ GlyphBLF *blf_glyph_texture_add(FontBLF *font, FT_UInt index, unsigned int c) else do_new= 1; - face= (FT_Face)font->engine; - err= FT_Load_Glyph(face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); + err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); if (err) return(NULL); /* get the glyph. */ - slot= face->glyph; + slot= font->face->glyph; err= FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); if (err || slot->format != FT_GLYPH_FORMAT_BITMAP) @@ -311,7 +307,6 @@ GlyphBLF *blf_glyph_bitmap_add(FontBLF *font, FT_UInt index, unsigned int c) GlyphCacheBLF *gc; GlyphBLF *g; GlyphBitmapBLF *gt; - FT_Face face; FT_Error err; FT_Bitmap bitmap; FT_BBox bbox; @@ -333,13 +328,12 @@ GlyphBLF *blf_glyph_bitmap_add(FontBLF *font, FT_UInt index, unsigned int c) else do_new= 1; - face= (FT_Face)font->engine; - err= FT_Load_Glyph(face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); + err= FT_Load_Glyph(font->face, index, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP); if (err) return(NULL); /* get the glyph. */ - slot= face->glyph; + slot= font->face->glyph; err= FT_Render_Glyph(slot, FT_RENDER_MODE_MONO); if (err || slot->format != FT_GLYPH_FORMAT_BITMAP) diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index af49dda0023..da213622766 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -40,6 +40,12 @@ void blf_font_exit(void); 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_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); +void blf_font_free(FontBLF *font); GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi); GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font); diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 9d762a7e155..1c55499b568 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -143,9 +143,6 @@ typedef struct FontBLF { /* draw mode, texture or bitmap. */ int mode; - /* reference count. */ - int ref; - /* aspect ratio or scale. */ float aspect; @@ -182,16 +179,8 @@ typedef struct FontBLF { /* current glyph cache, size and dpi. */ GlyphCacheBLF *glyph_cache; - /* 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 *); + /* freetype2 face. */ + FT_Face face; } FontBLF; typedef struct DirBLF { -- cgit v1.2.3