[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40321] trunk/blender/source/blender/ blenfont: blf - further shrink drawing functions & some style changes.

Campbell Barton ideasman42 at gmail.com
Sun Sep 18 12:34:14 CEST 2011


Revision: 40321
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40321
Author:   campbellbarton
Date:     2011-09-18 10:34:13 +0000 (Sun, 18 Sep 2011)
Log Message:
-----------
blf - further shrink drawing functions & some style changes.

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/BLF_api.h
    trunk/blender/source/blender/blenfont/intern/blf.c
    trunk/blender/source/blender/blenfont/intern/blf_dir.c
    trunk/blender/source/blender/blenfont/intern/blf_font.c
    trunk/blender/source/blender/blenfont/intern/blf_glyph.c
    trunk/blender/source/blender/blenfont/intern/blf_util.c

Modified: trunk/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_api.h	2011-09-18 09:48:09 UTC (rev 40320)
+++ trunk/blender/source/blender/blenfont/BLF_api.h	2011-09-18 10:34:13 UTC (rev 40321)
@@ -66,7 +66,7 @@
 	| m[3]  m[7]  m[11] m[15] |
 
  */
-void BLF_matrix(int fontid, double *m);
+void BLF_matrix(int fontid, const double m[16]);
 
 /* Draw the string using the default font, size and dpi. */
 void BLF_draw_default(float x, float y, float z, const char *str, size_t len);

Modified: trunk/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf.c	2011-09-18 09:48:09 UTC (rev 40320)
+++ trunk/blender/source/blender/blenfont/intern/blf.c	2011-09-18 10:34:13 UTC (rev 40321)
@@ -78,8 +78,8 @@
 static FontBLF *BLF_get(int fontid)
 {
 	if (fontid >= 0 && fontid < BLF_MAX_FONT)
-		return(global_font[fontid]);
-	return(NULL);
+		return global_font[fontid];
+	return NULL;
 }
 
 int BLF_init(int points, int dpi)
@@ -91,7 +91,7 @@
 
 	global_font_points= points;
 	global_font_dpi= dpi;
-	return(blf_font_init());
+	return blf_font_init();
 }
 
 void BLF_exit(void)
@@ -128,9 +128,9 @@
 	for (i= 0; i < BLF_MAX_FONT; i++) {
 		font= global_font[i];
 		if (font && (!strcmp(font->name, name)))
-			return(i);
+			return i;
 	}
-	return(-1);
+	return -1;
 }
 
 int BLF_load(const char *name)
@@ -140,24 +140,24 @@
 	int i;
 
 	if (!name)
-		return(-1);
+		return -1;
 
 	/* check if we already load this font. */
 	i= blf_search(name);
 	if (i >= 0) {
 		/*font= global_font[i];*/ /*UNUSED*/
-		return(i);
+		return i;
 	}
 
 	if (global_font_num+1 >= BLF_MAX_FONT) {
 		printf("Too many fonts!!!\n");
-		return(-1);
+		return -1;
 	}
 
 	filename= blf_dir_search(name);
 	if (!filename) {
 		printf("Can't find font: %s\n", name);
-		return(-1);
+		return -1;
 	}
 
 	font= blf_font_new(name, filename);
@@ -165,13 +165,13 @@
 
 	if (!font) {
 		printf("Can't load font: %s\n", name);
-		return(-1);
+		return -1;
 	}
 
 	global_font[global_font_num]= font;
 	i= global_font_num;
 	global_font_num++;
-	return(i);
+	return i;
 }
 
 int BLF_load_unique(const char *name)
@@ -181,20 +181,20 @@
 	int i;
 
 	if (!name)
-		return(-1);
+		return -1;
 
 	/* Don't search in the cache!! make a new
 	 * object font, this is for keep fonts threads safe.
 	 */
 	if (global_font_num+1 >= BLF_MAX_FONT) {
 		printf("Too many fonts!!!\n");
-		return(-1);
+		return -1;
 	}
 
 	filename= blf_dir_search(name);
 	if (!filename) {
 		printf("Can't find font: %s\n", name);
-		return(-1);
+		return -1;
 	}
 
 	font= blf_font_new(name, filename);
@@ -202,13 +202,13 @@
 
 	if (!font) {
 		printf("Can't load font: %s\n", name);
-		return(-1);
+		return -1;
 	}
 
 	global_font[global_font_num]= font;
 	i= global_font_num;
 	global_font_num++;
-	return(i);
+	return i;
 }
 
 void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
@@ -226,34 +226,34 @@
 	int i;
 
 	if (!name)
-		return(-1);
+		return -1;
 
 	i= blf_search(name);
 	if (i >= 0) {
 		/*font= global_font[i];*/ /*UNUSED*/
-		return(i);
+		return i;
 	}
 
 	if (global_font_num+1 >= BLF_MAX_FONT) {
 		printf("Too many fonts!!!\n");
-		return(-1);
+		return -1;
 	}
 
 	if (!mem || !mem_size) {
 		printf("Can't load font: %s from memory!!\n", name);
-		return(-1);
+		return -1;
 	}
 
 	font= blf_font_new_from_mem(name, mem, mem_size);
 	if (!font) {
 		printf("Can't load font: %s from memory!!\n", name);
-		return(-1);
+		return -1;
 	}
 
 	global_font[global_font_num]= font;
 	i= global_font_num;
 	global_font_num++;
-	return(i);
+	return i;
 }
 
 int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
@@ -262,7 +262,7 @@
 	int i;
 
 	if (!name)
-		return(-1);
+		return -1;
 
 	/*
 	 * Don't search in the cache, make a new object font!
@@ -270,24 +270,24 @@
 	 */
 	if (global_font_num+1 >= BLF_MAX_FONT) {
 		printf("Too many fonts!!!\n");
-		return(-1);
+		return -1;
 	}
 
 	if (!mem || !mem_size) {
 		printf("Can't load font: %s from memory!!\n", name);
-		return(-1);
+		return -1;
 	}
 
 	font= blf_font_new_from_mem(name, mem, mem_size);
 	if (!font) {
 		printf("Can't load font: %s from memory!!\n", name);
-		return(-1);
+		return -1;
 	}
 
 	global_font[global_font_num]= font;
 	i= global_font_num;
 	global_font_num++;
-	return(i);
+	return i;
 }
 
 void BLF_enable(int fontid, int option)
@@ -338,26 +338,25 @@
 	}
 }
 
-void BLF_matrix(int fontid, double *m)
+void BLF_matrix(int fontid, const double m[16])
 {
 	FontBLF *font;
-	int i;
 
 	font= BLF_get(fontid);
 	if (font) {
-		for (i= 0; i < 16; i++)
-			font->m[i]= m[i];
+		memcpy(font->m, m, sizeof(font->m));
 	}
 }
 
 void BLF_position(int fontid, float x, float y, float z)
 {
 	FontBLF *font;
-	float remainder;
-	float xa, ya, za;
 
 	font= BLF_get(fontid);
 	if (font) {
+		float xa, ya, za;
+		float remainder;
+
 		if (font->flags & BLF_ASPECT) {
 			xa= font->aspect[0];
 			ya= font->aspect[1];
@@ -546,8 +545,8 @@
 
 	font= BLF_get(fontid);
 	if (font && font->glyph_cache)
-		return(blf_font_width(font, str));
-	return(0.0f);
+		return blf_font_width(font, str);
+	return 0.0f;
 }
 
 float BLF_fixed_width(int fontid)
@@ -562,19 +561,16 @@
 
 float BLF_width_default(const char *str)
 {
-	float width;
-
 	if (global_font_default == -1)
 		global_font_default= blf_search("default");
 
 	if (global_font_default == -1) {
 		printf("Error: Can't found default font!!\n");
-		return(0.0f);
+		return 0.0f;
 	}
 
 	BLF_size(global_font_default, global_font_points, global_font_dpi);
-	width= BLF_width(global_font_default, str);
-	return(width);
+	return BLF_width(global_font_default, str);
 }
 
 float BLF_height(int fontid, const char *str)
@@ -583,8 +579,8 @@
 
 	font= BLF_get(fontid);
 	if (font && font->glyph_cache)
-		return(blf_font_height(font, str));
-	return(0.0f);
+		return blf_font_height(font, str);
+	return 0.0f;
 }
 
 float BLF_height_max(int fontid)
@@ -593,8 +589,8 @@
 
 	font= BLF_get(fontid);
 	if (font && font->glyph_cache)
-		return(font->glyph_cache->max_glyph_height);
-	return(0.0f);
+		return font->glyph_cache->max_glyph_height;
+	return 0.0f;
 }
 
 float BLF_width_max(int fontid)
@@ -602,11 +598,10 @@
 	FontBLF *font;
 
 	font= BLF_get(fontid);
-	if (font) {
-		if(font->glyph_cache)
-			return(font->glyph_cache->max_glyph_width);
+	if (font && font->glyph_cache) {
+		return font->glyph_cache->max_glyph_width;
 	}
-	return(0.0f);
+	return 0.0f;
 }
 
 float BLF_descender(int fontid)
@@ -614,11 +609,10 @@
 	FontBLF *font;
 
 	font= BLF_get(fontid);
-	if (font) {
-		if(font->glyph_cache)
-			return(font->glyph_cache->descender);
+	if (font && font->glyph_cache) {
+		return font->glyph_cache->descender;
 	}
-	return(0.0f);
+	return 0.0f;
 }
 
 float BLF_ascender(int fontid)
@@ -626,28 +620,25 @@
 	FontBLF *font;
 
 	font= BLF_get(fontid);
-	if (font) {
-		if(font->glyph_cache)
-			return(font->glyph_cache->ascender);
+	if (font && font->glyph_cache) {
+		return font->glyph_cache->ascender;
 	}
-	return(0.0f);
+	return 0.0f;
 }
 
 float BLF_height_default(const char *str)
 {
-	float height;
-
 	if (global_font_default == -1)
 		global_font_default= blf_search("default");
 
 	if (global_font_default == -1) {
 		printf("Error: Can't found default font!!\n");
-		return(0.0f);
+		return 0.0f;
 	}
 
 	BLF_size(global_font_default, global_font_points, global_font_dpi);
-	height= BLF_height(global_font_default, str);
-	return(height);
+
+	return BLF_height(global_font_default, str);
 }
 
 void BLF_rotation(int fontid, float angle)

Modified: trunk/blender/source/blender/blenfont/intern/blf_dir.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_dir.c	2011-09-18 09:48:09 UTC (rev 40320)
+++ trunk/blender/source/blender/blenfont/intern/blf_dir.c	2011-09-18 10:34:13 UTC (rev 40321)
@@ -62,10 +62,10 @@
 	p= global_font_dir.first;
 	while (p) {
 		if (BLI_path_cmp(p->path, path) == 0)
-			return(p);
+			return p;
 		p= p->next;
 	}
-	return(NULL);
+	return NULL;
 }
 
 void BLF_dir_add(const char *path)
@@ -102,7 +102,7 @@
 	
 	count= BLI_countlist(&global_font_dir);
 	if (!count)
-		return(NULL);
+		return NULL;
 	
 	dirs= (char **)MEM_mallocN(sizeof(char *) * count, "BLF_dir_get");
 	p= global_font_dir.first;
@@ -113,7 +113,7 @@
 		p= p->next;
 	}
 	*ndir= i;
-	return(dirs);
+	return dirs;
 }
 
 void BLF_dir_free(char **dirs, int count)
@@ -147,8 +147,8 @@
 		if (BLI_exist(file))
 			s= BLI_strdup(file);
 	}
-	
-	return(s);
+
+	return s;
 }
 
 #if 0 // UNUSED
@@ -171,9 +171,9 @@
 		file[i+4]= '\0';
 		s++;
 		*size= atoi(s);
-		return(1);
+		return 1;
 	}
-	return(0);
+	return 0;
 }
 #endif
 
@@ -188,9 +188,9 @@
 	mfile= BLI_strdup(filename);
 	s= strrchr(mfile, '.');
 	if (s) {
-		if (strlen(s) < 4) {
+		if (strnlen(s, 4) < 4) {
 			MEM_freeN(mfile);
-			return(NULL);
+			return NULL;
 		}
 		s++;
 		s[0]= 'a';
@@ -199,14 +199,14 @@
 
 		/* first check .afm */
 		if (BLI_exist(s))
-			return(s);
+			return s;
 
 		/* and now check .pfm */
 		s[0]= 'p';
 
 		if (BLI_exist(s))
-			return(s);
+			return s;
 	}
 	MEM_freeN(mfile);
-	return(NULL);
+	return NULL;
 }

Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-09-18 09:48:09 UTC (rev 40320)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-09-18 10:34:13 UTC (rev 40321)
@@ -62,7 +62,7 @@
 
 int blf_font_init(void)
 {
-	return(FT_Init_FreeType(&ft_lib));
+	return FT_Init_FreeType(&ft_lib);
 }
 
 void blf_font_exit(void)
@@ -156,19 +156,14 @@
 void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
 {
 	unsigned int c;
-	GlyphBLF *g, *g_prev;
+	GlyphBLF *g, *g_prev= NULL;
 	FT_Vector delta;
-	int pen_x, pen_y;
-	unsigned int i;
+	int pen_x= 0, pen_y= 0;
+	unsigned int i= 0;
 	GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 
 	BLF_KERNING_VARS(font, has_kerning, kern_mode);
 
-	i= 0;
-	pen_x= 0;
-	pen_y= 0;
-	g_prev= NULL;
-
 	blf_font_ensure_ascii_table(font);
 
 	while (str[i] && i < len) {
@@ -190,18 +185,14 @@
 /* faster version of blf_font_draw, ascii only for view dimensions */
 void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len)
 {
-	char c;
-	GlyphBLF *g, *g_prev;
+	unsigned char c;
+	GlyphBLF *g, *g_prev= NULL;
 	FT_Vector delta;
-	int pen_x, pen_y;
+	int pen_x= 0, pen_y= 0;
 	GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list