[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41163] trunk/blender/source/blender: - minor edits to font drawing/utf8, was needlessly casting int/ unsigned int.

Campbell Barton ideasman42 at gmail.com
Fri Oct 21 02:48:02 CEST 2011


Revision: 41163
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41163
Author:   campbellbarton
Date:     2011-10-21 00:48:02 +0000 (Fri, 21 Oct 2011)
Log Message:
-----------
- minor edits to font drawing/utf8, was needlessly casting int/unsigned int.
- also ifdef'd out more smoke function when the modifiers disabled.

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/intern/blf_font.c
    trunk/blender/source/blender/blenfont/intern/blf_internal.h
    trunk/blender/source/blender/blenfont/intern/blf_util.c
    trunk/blender/source/blender/blenkernel/intern/smoke.c
    trunk/blender/source/blender/blenlib/BLI_string_utf8.h
    trunk/blender/source/blender/blenlib/intern/string_utf8.c

Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-10-21 00:01:22 UTC (rev 41162)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c	2011-10-21 00:48:02 UTC (rev 41163)
@@ -129,7 +129,7 @@
 		g= (glyph_ascii_table)[c];                                            \
 		i++;                                                                  \
 	}                                                                         \
-	else if ((c= blf_utf8_next((unsigned char *)(str), &(i)))) {              \
+	else if ((c= blf_utf8_next((str), &(i))) != BLI_UTF8_ERR) {               \
 		if ((g= blf_glyph_search((font)->glyph_cache, c)) == NULL) {          \
 			g= blf_glyph_add(font, FT_Get_Char_Index((font)->face, c), c);    \
 		}                                                                     \
@@ -141,15 +141,20 @@
 	const FT_UInt kern_mode= (has_kerning == 0) ? 0 :                         \
 	                         (((_font)->flags & BLF_KERNING_DEFAULT) ?        \
 	                          ft_kerning_default : FT_KERNING_UNFITTED)       \
-	                                                                          \
 
 
 #define BLF_KERNING_STEP(_font, kern_mode, g_prev, g, delta, pen_x)           \
 {                                                                             \
 	if (g_prev) {                                                             \
 		delta.x= delta.y= 0;                                                  \
-		if (FT_Get_Kerning((_font)->face, g_prev->idx, g->idx, kern_mode, &delta) == 0) \
+		if (FT_Get_Kerning((_font)->face,                                     \
+		                   (g_prev)->idx,                                     \
+		                   (g)->idx,                                          \
+		                   kern_mode,                                         \
+		                   &(delta)) == 0)                                    \
+		{                                                                     \
 			pen_x += delta.x >> 6;                                            \
+		}                                                                     \
 	}                                                                         \
 }                                                                             \
 
@@ -159,7 +164,7 @@
 	GlyphBLF *g, *g_prev= NULL;
 	FT_Vector delta;
 	int pen_x= 0, pen_y= 0;
-	unsigned int i= 0;
+	size_t i= 0;
 	GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 
 	BLF_KERNING_VARS(font, has_kerning, kern_mode);
@@ -170,9 +175,9 @@
 
 		BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
 
-		if (c == 0)      break;
-		if (g == NULL)   continue;
-		if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+		if (c == BLI_UTF8_ERR)  break;
+		if (g == NULL)          continue;
+		if (has_kerning)        BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
 
 		/* do not return this loop if clipped, we want every character tested */
 		blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
@@ -214,7 +219,7 @@
 	GlyphBLF *g, *g_prev= NULL;
 	FT_Vector delta;
 	int pen_x= (int)font->pos[0], pen_y= 0;
-	unsigned int i= 0;
+	size_t i= 0;
 	GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 
 	/* buffer specific vars*/
@@ -235,9 +240,9 @@
 
 		BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
 
-		if (c == 0)      break;
-		if (g == NULL)   continue;
-		if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+		if (c == BLI_UTF8_ERR)  break;
+		if (g == NULL)          continue;
+		if (has_kerning)        BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
 
 		chx= pen_x + ((int)g->pos_x);
 		chy= (int)font->pos[1] + g->height;
@@ -340,7 +345,7 @@
 	GlyphBLF *g, *g_prev= NULL;
 	FT_Vector delta;
 	int pen_x= 0, pen_y= 0;
-	unsigned int i= 0;
+	size_t i= 0;
 	GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
 
 	rctf gbox;
@@ -358,9 +363,9 @@
 
 		BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
 
-		if (c == 0)      break;
-		if (g == NULL)   continue;
-		if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+		if (c == BLI_UTF8_ERR)  break;
+		if (g == NULL)          continue;
+		if (has_kerning)        BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
 
 		gbox.xmin= pen_x;
 		gbox.xmax= pen_x + g->advance;

Modified: trunk/blender/source/blender/blenfont/intern/blf_internal.h
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_internal.h	2011-10-21 00:01:22 UTC (rev 41162)
+++ trunk/blender/source/blender/blenfont/intern/blf_internal.h	2011-10-21 00:48:02 UTC (rev 41163)
@@ -40,7 +40,7 @@
 
 unsigned int blf_next_p2(unsigned int x);
 unsigned int blf_hash(unsigned int val);
-int blf_utf8_next(unsigned char *buf, unsigned int *iindex);
+unsigned int blf_utf8_next(const char *buf, size_t *iindex);
 
 char *blf_dir_search(const char *file);
 char *blf_dir_metrics_search(const char *filename);

Modified: trunk/blender/source/blender/blenfont/intern/blf_util.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_util.c	2011-10-21 00:01:22 UTC (rev 41162)
+++ trunk/blender/source/blender/blenfont/intern/blf_util.c	2011-10-21 00:48:02 UTC (rev 41163)
@@ -37,6 +37,8 @@
 
 #include "blf_internal.h"
 
+#include "BLI_string_utf8.h"
+
 unsigned int blf_next_p2(unsigned int x)
 {
 	x -= 1;
@@ -72,7 +74,7 @@
  * The original name: imlib_font_utf8_get_next
  * more info here: http://docs.enlightenment.org/api/imlib2/html/
  */
-int blf_utf8_next(unsigned char *buf, unsigned int *iindex)
+unsigned int blf_utf8_next(const char *buf, size_t *iindex)
 {
 	/* Reads UTF8 bytes from 'buf', starting at 'index' and
 	 * returns the code point of the next valid code point.
@@ -85,7 +87,7 @@
 
 	d= buf[index++];
 	if (!d)
-		return 0;
+		return BLI_UTF8_ERR;
 
 	while (buf[index] && ((buf[index] & 0xc0) == 0x80))
 		index++;

Modified: trunk/blender/source/blender/blenkernel/intern/smoke.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/smoke.c	2011-10-21 00:01:22 UTC (rev 41162)
+++ trunk/blender/source/blender/blenkernel/intern/smoke.c	2011-10-21 00:48:02 UTC (rev 41163)
@@ -131,15 +131,15 @@
 struct DerivedMesh;
 struct SmokeModifierData;
 
-// forward declerations
+#define TRI_UVOFFSET (1./4.)
+
+#ifdef WITH_SMOKE
+/* forward declerations */
+static void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len);
 static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct);
-void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len);
 static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs);
-
-#define TRI_UVOFFSET (1./4.)
-
+#else /* WITH_SMOKE */
 /* Stubs to use when smoke is disabled */
-#ifndef WITH_SMOKE
 struct WTURBULENCE *smoke_turbulence_init(int *UNUSED(res), int UNUSED(amplify), int UNUSED(noisetype)) { return NULL; }
 struct FLUID_3D *smoke_init(int *UNUSED(res), float *UNUSED(p0)) { return NULL; }
 void smoke_free(struct FLUID_3D *UNUSED(fluid)) {}
@@ -148,9 +148,9 @@
 void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity), int *UNUSED(border_colli)) {}
 long long smoke_get_mem_req(int UNUSED(xres), int UNUSED(yres), int UNUSED(zres), int UNUSED(amplify)) { return 0; }
 void smokeModifier_do(SmokeModifierData *UNUSED(smd), Scene *UNUSED(scene), Object *UNUSED(ob), DerivedMesh *UNUSED(dm)) {}
-#endif // WITH_SMOKE
+#endif /* WITH_SMOKE */
 
-
+#ifdef WITH_SMOKE
 static int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, DerivedMesh *dm)
 {
 	if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain && !smd->domain->fluid)
@@ -455,7 +455,7 @@
 }
 
 /*! init triangle divisions */
-void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFace *faces, int numfaces, int numtris, int **tridivs, float cell_len) 
+static void calcTriangleDivs(Object *ob, MVert *verts, int UNUSED(numverts), MFace *faces, int numfaces, int numtris, int **tridivs, float cell_len)
 {
 	// mTriangleDivs1.resize( faces.size() );
 	// mTriangleDivs2.resize( faces.size() );
@@ -554,6 +554,8 @@
 	}
 }
 
+#endif /* WITH_SMOKE */
+
 static void smokeModifier_freeDomain(SmokeModifierData *smd)
 {
 	if(smd->domain)
@@ -1659,4 +1661,4 @@
 	}
 }
 
-#endif // WITH_SMOKE
+#endif /* WITH_SMOKE */

Modified: trunk/blender/source/blender/blenlib/BLI_string_utf8.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string_utf8.h	2011-10-21 00:01:22 UTC (rev 41162)
+++ trunk/blender/source/blender/blenlib/BLI_string_utf8.h	2011-10-21 00:48:02 UTC (rev 41163)
@@ -53,7 +53,8 @@
 size_t       BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxcpy);
 size_t       BLI_strncpy_wchar_from_utf8(wchar_t *dst, const char *src, const size_t maxcpy);
 
-#define BLI_STRING_MAX_UTF8 6
+#define      BLI_UTF8_MAX 6
+#define      BLI_UTF8_ERR ((unsigned int)-1)
 
 #ifdef __cplusplus
 }

Modified: trunk/blender/source/blender/blenlib/intern/string_utf8.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string_utf8.c	2011-10-21 00:01:22 UTC (rev 41162)
+++ trunk/blender/source/blender/blenlib/intern/string_utf8.c	2011-10-21 00:48:02 UTC (rev 41163)
@@ -246,7 +246,7 @@
 	while(*src_c && len < maxcpy) {
 		size_t step= 0;
 		unsigned int unicode= BLI_str_utf8_as_unicode_and_size(src_c, &step);
-		if (unicode != (unsigned int)-1) {
+		if (unicode != BLI_UTF8_ERR) {
 			*dst_w= (wchar_t)unicode;
 			src_c += step;
 		}
@@ -331,7 +331,7 @@
 
   UTF8_COMPUTE (c, mask, len);
   if (len == -1)
-    return (unsigned int)-1;
+    return BLI_UTF8_ERR;
   UTF8_GET (result, p, i, mask, len);
 
   return result;
@@ -346,7 +346,7 @@
 
 	UTF8_COMPUTE (c, mask, len);
 	if (len == -1)
-		return (unsigned int)-1;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list