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.
This commit is contained in:
Campbell Barton 2013-12-28 19:04:03 +11:00
parent 961d0409c8
commit 1a91b8bd5d
3 changed files with 34 additions and 32 deletions

View File

@ -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)

View File

@ -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

View File

@ -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