Fix for T53332: BFont 43 Inaccessible Glyphs

Preloading of BFont (default for 3D Text Objects) glyphs will not load
any with a character code greater than 256, resulting in 43 characters
that are inaccessible. This patch corrects that preloading code.

See D16122 for more details

Differential Revision: https://developer.blender.org/D16122

Reviewed by Campbell Barton
This commit is contained in:
2022-10-06 10:35:36 -07:00
parent c592bff047
commit be8ee05dcb

View File

@@ -270,9 +270,6 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
{
/* Variables */
FT_Face face;
const FT_ULong charcode_reserve = 256;
FT_ULong charcode = 0, lcode;
FT_UInt glyph_index;
VFontData *vfd;
/* load the freetype font */
@@ -305,9 +302,6 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
return NULL;
}
/* Extract the first 256 character from TTF */
lcode = charcode = FT_Get_First_Char(face, &glyph_index);
/* Blender default BFont is not "complete". */
const bool complete_font = (face->ascender != 0) && (face->descender != 0) &&
(face->ascender != face->descender);
@@ -335,21 +329,19 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf)
vfd->scale = 1.0f / 1000.0f;
}
/* Load characters */
vfd->characters = BLI_ghash_int_new_ex(__func__, charcode_reserve);
/* Load the first 256 glyphs. */
while (charcode < charcode_reserve) {
/* Generate the font data */
freetypechar_to_vchar(face, charcode, vfd);
const FT_ULong preload_count = 256;
vfd->characters = BLI_ghash_int_new_ex(__func__, preload_count);
/* Next glyph */
FT_ULong charcode = 0;
FT_UInt glyph_index;
for (int i = 0; i < preload_count; i++) {
charcode = FT_Get_Next_Char(face, charcode, &glyph_index);
/* Check that we won't start infinite loop */
if (charcode <= lcode) {
if (!charcode || !glyph_index) {
break;
}
lcode = charcode;
freetypechar_to_vchar(face, charcode, vfd);
}
return vfd;