[Bf-blender-cvs] [1a91b8b] master: Fix for 3d fonts loading the character of the string terminator.

Campbell Barton noreply at git.blender.org
Sat Dec 28 09:08:57 CET 2013


Commit: 1a91b8bd5d6ad6a2a4fa62ae7719da01741849f4
Author: Campbell Barton
Date:   Sat Dec 28 19:04:03 2013 +1100
https://developer.blender.org/rB1a91b8bd5d6ad6a2a4fa62ae7719da01741849f4

Fix for 3d fonts loading the character of the string terminator.

also remove redundant call to wcslen and ensure FT_Init_FreeType runs
once the font loads.

===================================================================

M	source/blender/blenkernel/intern/font.c
M	source/blender/blenlib/BLI_vfontdata.h
M	source/blender/blenlib/intern/freetypefont.c

===================================================================

diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 0839ed8..40da6e0 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -524,10 +524,7 @@ struct CharTrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int
 	utf8len = BLI_strlen_utf8(cu->str);
 	mem = MEM_mallocN(((utf8len + 1) * sizeof(wchar_t)), "convertedmem");
 
-	BLI_strncpy_wchar_from_utf8(mem, cu->str, utf8len + 1);
-
-	/* Count the wchar_t string length */
-	slen = wcslen(mem);
+	slen = BLI_strncpy_wchar_from_utf8(mem, cu->str, utf8len + 1);
 
 	if (cu->ulheight == 0.0f)
 		cu->ulheight = 0.05f;
@@ -597,20 +594,19 @@ makebreak:
 		
 		if (vfont == NULL) break;
 
-		che = find_vfont_char(vfd, ascii);
+		if (i != slen) {
+			che = find_vfont_char(vfd, ascii);
 
-		/*
-		 * The character wasn't in the current curve base so load it
-		 * But if the font is built-in then do not try loading since
-		 * whole font is in the memory already
-		 */
-		if (che == NULL && BKE_vfont_is_builtin(vfont) == FALSE) {
-			BLI_vfontchar_from_freetypefont(vfont, ascii);
+			/*
+			 * The character wasn't in the current curve base so load it
+			 * But if the font is built-in then do not try loading since
+			 * whole font is in the memory already
+			 */
+			if (che == NULL && BKE_vfont_is_builtin(vfont) == false) {
+				che = BLI_vfontchar_from_freetypefont(vfont, ascii);
+			}
 		}
 
-		/* Try getting the character again from the list */
-		che = find_vfont_char(vfd, ascii);
-
 		/* No VFont found */
 		if (vfont == NULL) {
 			if (mem)
diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h
index 9130061..cb41fe4 100644
--- a/source/blender/blenlib/BLI_vfontdata.h
+++ b/source/blender/blenlib/BLI_vfontdata.h
@@ -52,7 +52,7 @@ typedef struct VChar {
 
 VFontData *BLI_vfontdata_from_freetypefont(struct PackedFile *pf);
 
-int BLI_vfontchar_from_freetypefont(struct VFont *vfont, unsigned long character);
+VChar *BLI_vfontchar_from_freetypefont(struct VFont *vfont, unsigned long character);
 
 #endif
 
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index 9cd0bf0..f9e09ab 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -63,7 +63,7 @@ static FT_Library library;
 static FT_Error err;
 
 
-static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vfd)
+static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vfd)
 {
 	const float eps = 0.0001f;
 	const float eps_sq = eps * eps;
@@ -287,11 +287,17 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
 		}
 		if (npoints) MEM_freeN(npoints);
 		if (onpoints) MEM_freeN(onpoints);
+
+		return che;
 	}
+
+	return NULL;
 }
 
-static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
+static VChar *objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
 {
+	VChar *che;
+
 	/* Freetype2 */
 	FT_Face face;
 
@@ -302,18 +308,20 @@ static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode)
 		                         vfont->temp_pf->size,
 		                         0,
 		                         &face);
-		if (err) return FALSE;
+		if (err) {
+			return NULL;
+		}
 	}
 	else {
 		err = TRUE;
-		return FALSE;
+		return NULL;
 	}
-		
+
 	/* Read the char */
-	freetypechar_to_vchar(face, charcode, vfont->data);
-	
+	che = freetypechar_to_vchar(face, charcode, vfont->data);
+
 	/* And everything went ok */
-	return TRUE;
+	return che;
 }
 
 
@@ -508,28 +516,26 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf)
 	return vfd;
 }
 
-int BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
+VChar *BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character)
 {
-	int success = FALSE;
+	VChar *che = NULL;
 
-	if (!vfont) return FALSE;
+	if (!vfont) return NULL;
 
 	/* Init Freetype */
 	err = FT_Init_FreeType(&library);
 	if (err) {
 		/* XXX error("Failed to load the Freetype font library"); */
-		return 0;
+		return NULL;
 	}
 
 	/* Load the character */
-	success = objchr_to_ftvfontdata(vfont, character);
-	if (success == FALSE) return FALSE;
+	che = objchr_to_ftvfontdata(vfont, character);
 
 	/* Free Freetype */
 	FT_Done_FreeType(library);
 
-	/* Ahh everything ok */
-	return TRUE;
+	return che;
 }
 
 #if 0




More information about the Bf-blender-cvs mailing list