[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19176] branches/blender2.5/blender/source /blender/blenfont/intern: And another commit to cleanup a little, this is the last,

Diego Borghetti bdiego at gmail.com
Mon Mar 2 22:02:39 CET 2009


Revision: 19176
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19176
Author:   bdiego
Date:     2009-03-02 22:02:39 +0100 (Mon, 02 Mar 2009)

Log Message:
-----------
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.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h
    branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf.c	2009-03-02 20:18:29 UTC (rev 19175)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf.c	2009-03-02 21:02:39 UTC (rev 19176)
@@ -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 @@
 /* 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 @@
 		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 @@
 		return(-1);
 	}
 
+#ifdef WITH_FREETYPE2
 	font= blf_font_new(name, filename);
 	MEM_freeN(filename);
 
@@ -165,14 +155,13 @@
 	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 @@
 		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 @@
 	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 @@
 		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 @@
 		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 @@
 		font->clip_rec.xmax= xmax;
 		font->clip_rec.ymax= ymax;
 	}
-#endif
 }

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c	2009-03-02 20:18:29 UTC (rev 19175)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_font.c	2009-03-02 21:02:39 UTC (rev 19176)
@@ -73,78 +73,6 @@
 	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 @@
 	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 */

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h	2009-03-02 20:18:29 UTC (rev 19175)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal.h	2009-03-02 21:02:39 UTC (rev 19176)
@@ -35,21 +35,14 @@
 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);

Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
===================================================================

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list