[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40157] trunk/blender/source/blender/ blenfont/intern: fix for changing font sizes with recent utf8 speedup

Campbell Barton ideasman42 at gmail.com
Mon Sep 12 11:12:34 CEST 2011


Revision: 40157
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40157
Author:   campbellbarton
Date:     2011-09-12 09:12:34 +0000 (Mon, 12 Sep 2011)
Log Message:
-----------
fix for changing font sizes with recent utf8 speedup

Modified Paths:
--------------
    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_internal_types.h

Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-09-12 08:27:21 UTC (rev 40156)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-09-12 09:12:34 UTC (rev 40157)
@@ -100,7 +100,8 @@
 static void blf_font_ensure_ascii_table(FontBLF *font)
 {
 	/* build ascii on demand */
-	if(font->glyph_ascii_table['0']==NULL) {
+	if(font->glyph_cache->glyph_ascii_table['0']==NULL) {
+		GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 		GlyphBLF *g;
 		unsigned int i;
 		for(i=0; i<256; i++) {
@@ -109,7 +110,7 @@
 				FT_UInt glyph_index= FT_Get_Char_Index(font->face, i);
 				g= blf_glyph_add(font, glyph_index, i);
 			}
-			font->glyph_ascii_table[i]= g;
+			glyph_ascii_table[i]= g;
 		}
 	}
 }
@@ -122,9 +123,9 @@
 /* Note,
  * blf_font_ensure_ascii_table(font); must be called before this macro */
 
-#define BLF_UTF8_NEXT_FAST(font, g, str, i, c)                                \
+#define BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table)             \
 	if(((c)= (str)[i]) < 0x80) {                                              \
-		g= (font)->glyph_ascii_table[c];                                      \
+		g= glyph_ascii_table[c];                                              \
 		i++;                                                                  \
 	}                                                                         \
 	else if ((c= blf_utf8_next((unsigned char *)(str), &(i)))) {              \
@@ -143,9 +144,11 @@
 	int pen_x, pen_y;
 	int has_kerning, st;
 	unsigned int i;
+	GlyphBLF **glyph_ascii_table;
 
 	if (!font->glyph_cache)
 		return;
+	glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 
 	i= 0;
 	pen_x= 0;
@@ -157,7 +160,7 @@
 
 	while (str[i] && i < len) {
 
-		BLF_UTF8_NEXT_FAST(font, g, str, i, c);
+		BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
 
 		if (c == 0)
 			break;
@@ -195,9 +198,11 @@
 	FT_Vector delta;
 	int pen_x, pen_y;
 	int has_kerning, st;
+	GlyphBLF **glyph_ascii_table;
 
 	if (!font->glyph_cache)
 		return;
+	glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 
 	pen_x= 0;
 	pen_y= 0;
@@ -207,7 +212,7 @@
 	blf_font_ensure_ascii_table(font);
 
 	while ((c= *(str++)) && len--) {
-		g= font->glyph_ascii_table[c];
+		g= font->glyph_cache->glyph_ascii_table[c];
 
 		/* if we don't found a glyph, skip it. */
 		if (!g)
@@ -245,9 +250,11 @@
 	int pen_x, y, x;
 	int has_kerning, st, chx, chy;
 	unsigned int i;
+	GlyphBLF **glyph_ascii_table;
 
 	if (!font->glyph_cache || (!font->b_fbuf && !font->b_cbuf))
 		return;
+	glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 	
 	i= 0;
 	pen_x= (int)font->pos[0];
@@ -264,7 +271,7 @@
 	while (str[i]) {
 		int pen_y;
 
-		BLF_UTF8_NEXT_FAST(font, g, str, i, c);
+		BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
 
 		if (c == 0)
 			break;
@@ -390,9 +397,11 @@
 	int pen_x, pen_y;
 	int has_kerning, st;
 	unsigned int i;
+	GlyphBLF **glyph_ascii_table;
 
 	if (!font->glyph_cache)
 		return;
+	glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 
 	box->xmin= 32000.0f;
 	box->xmax= -32000.0f;
@@ -409,7 +418,7 @@
 
 	while (str[i]) {
 
-		BLF_UTF8_NEXT_FAST(font, g, str, i, c);
+		BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
 
 		if (c == 0)
 			break;
@@ -589,8 +598,6 @@
 	font->b_col[2]= 0;
 	font->b_col[3]= 0;
 	font->ft_lib= ft_lib;
-
-	memset(font->glyph_ascii_table, 0, sizeof(font->glyph_ascii_table));
 }
 
 FontBLF *blf_font_new(const char *name, const char *filename)

Modified: trunk/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2011-09-12 08:27:21 UTC (rev 40156)
+++ trunk/blender/source/blender/blenfont/intern/blf_glyph.c	2011-09-12 09:12:34 UTC (rev 40157)
@@ -74,7 +74,6 @@
 GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
 {
 	GlyphCacheBLF *gc;
-	int i;
 
 	gc= (GlyphCacheBLF *)MEM_mallocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
 	gc->next= NULL;
@@ -82,10 +81,8 @@
 	gc->size= font->size;
 	gc->dpi= font->dpi;
 
-	for (i= 0; i < 257; i++) {
-		gc->bucket[i].first= NULL;
-		gc->bucket[i].last= NULL;
-	}
+	memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table));
+	memset(gc->bucket, 0, sizeof(gc->bucket));
 
 	gc->textures= (GLuint *)malloc(sizeof(GLuint)*256);
 	gc->ntex= 256;
@@ -136,7 +133,9 @@
 		}
 	}
 
-	memset(font->glyph_ascii_table, 0, sizeof(font->glyph_ascii_table));
+	if(font->glyph_cache) {
+		memset(font->glyph_cache->glyph_ascii_table, 0, sizeof(font->glyph_cache->glyph_ascii_table));
+	}
 }
 
 void blf_glyph_cache_free(GlyphCacheBLF *gc)

Modified: trunk/blender/source/blender/blenfont/intern/blf_internal_types.h
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_internal_types.h	2011-09-12 08:27:21 UTC (rev 40156)
+++ trunk/blender/source/blender/blenfont/intern/blf_internal_types.h	2011-09-12 09:12:34 UTC (rev 40157)
@@ -46,6 +46,9 @@
 	/* and the glyphs. */
 	ListBase bucket[257];
 
+	/* fast ascii lookup */
+	struct GlyphBLF *glyph_ascii_table[256];
+
 	/* texture array, to draw the glyphs. */
 	GLuint *textures;
 
@@ -184,9 +187,6 @@
 
 	/* current glyph cache, size and dpi. */
 	GlyphCacheBLF *glyph_cache;
-	
-	/* fast ascii lookip */
-	GlyphBLF *glyph_ascii_table[256];
 
 	/* freetype2 lib handle. */
 	FT_Library ft_lib;




More information about the Bf-blender-cvs mailing list