Text3d: avoid calculating the font boundbox scale for every character

This commit is contained in:
Campbell Barton 2013-12-28 19:45:54 +11:00
parent 1aa62605cd
commit 2654b28f04
2 changed files with 11 additions and 8 deletions

@ -42,6 +42,7 @@ struct VFont;
typedef struct VFontData { typedef struct VFontData {
struct GHash *characters; struct GHash *characters;
char name[128]; char name[128];
float scale;
} VFontData; } VFontData;
typedef struct VChar { typedef struct VChar {

@ -65,6 +65,7 @@ static FT_Error err;
static VChar *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 scale = vfd->scale;
const float eps = 0.0001f; const float eps = 0.0001f;
const float eps_sq = eps * eps; const float eps_sq = eps * eps;
/* Blender */ /* Blender */
@ -76,17 +77,9 @@ static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *
FT_GlyphSlot glyph; FT_GlyphSlot glyph;
FT_UInt glyph_index; FT_UInt glyph_index;
FT_Outline ftoutline; FT_Outline ftoutline;
float scale, height;
float dx, dy; float dx, dy;
int j, k, l, m = 0; 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 * 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); 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 */ /* Load characters */
vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve); vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve);