[Bf-blender-cvs] [2654b28] master: Text3d: avoid calculating the font boundbox scale for every character

Campbell Barton noreply at git.blender.org
Sat Dec 28 09:46:37 CET 2013


Commit: 2654b28f046ea3a444717ebc7f36f9b5ef22f7f1
Author: Campbell Barton
Date:   Sat Dec 28 19:45:54 2013 +1100
https://developer.blender.org/rB2654b28f046ea3a444717ebc7f36f9b5ef22f7f1

Text3d: avoid calculating the font boundbox scale for every character

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

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

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

diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h
index cb41fe4..8a7079b 100644
--- a/source/blender/blenlib/BLI_vfontdata.h
+++ b/source/blender/blenlib/BLI_vfontdata.h
@@ -42,6 +42,7 @@ struct VFont;
 typedef struct VFontData {
 	struct GHash *characters;
 	char name[128];
+	float scale;
 } VFontData;
 
 typedef struct VChar {
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index f9e09ab..43cf6c6 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -65,6 +65,7 @@ static FT_Error err;
 
 static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vfd)
 {
+	const float scale = vfd->scale;
 	const float eps = 0.0001f;
 	const float eps_sq = eps * eps;
 	/* Blender */
@@ -76,17 +77,9 @@ static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *
 	FT_GlyphSlot glyph;
 	FT_UInt glyph_index;
 	FT_Outline ftoutline;
-	float scale, height;
 	float dx, dy;
 	int j, k, l, m = 0;
 
-	/* adjust font size */
-	height = ((double) face->bbox.yMax - (double) face->bbox.yMin);
-	if (height != 0.0f)
-		scale = 1.0f / height;
-	else
-		scale = 1.0f / 1000.0f;
-
 	/*
 	 * Generate the character 3D data
 	 *
@@ -403,6 +396,15 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
 		lcode = charcode = FT_Get_First_Char(face, &glyph_index);
 	}
 
+
+	/* Adjust font size */
+	if (face->bbox.yMax != face->bbox.yMin) {
+		vfd->scale = (float)(1.0 / (double)(face->bbox.yMax - face->bbox.yMin));
+	}
+	else {
+		vfd->scale = 1.0f / 1000.0f;
+	}
+
 	/* Load characters */
 	vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve);




More information about the Bf-blender-cvs mailing list