diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-28 12:45:54 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-28 12:45:54 +0400 |
commit | 2654b28f046ea3a444717ebc7f36f9b5ef22f7f1 (patch) | |
tree | 56dc15d7c666bc54413c35f8278487b948710fb7 /source | |
parent | 1aa62605cdf7c43085c9d1db606b2c0c460e9897 (diff) |
Text3d: avoid calculating the font boundbox scale for every character
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_vfontdata.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/freetypefont.c | 18 |
2 files changed, 11 insertions, 8 deletions
diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h index cb41fe488db..8a7079b6c5f 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 f9e09abef54..43cf6c665c2 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); |