Mon 11 Sep 2017 08:33:51 PM UTC, original submission:
I've been trying to get a truetype font to display with 2.8 for the past few days and I've run into an annoying bug. It seems that FT_Get_Char_Index doesn't work as expected, returning 0 for every char, and I think I've discovered why.
In FT_Get_Char_Index the call is done like so:
result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode );
Where cmap is defined as an FT_CMap like so:
FT_CMap cmap = FT_CMAP( face->charmap );
The TT function that gets called to do the lookup in ttcmap.c is
FT_CALLBACK_DEF( FT_UInt )
tt_cmap4_char_index( TT_CMap cmap,
FT_UInt32 char_code )
This expects a TT_CMap not an FT_CMap. The conversion seems to still be allowed, but looking at both structs, there's no way that this conversion can work properly. As such, in the binary search that the TT code does, the p pointer for the data is well off into memory it shouldn't be.
I've included the font I've been using for diagnostic and I've been calling the code like so:
// activate the size and create the glyph
THOR_LOG("Activating size: faceHeight %d, numGlyphs %d", (size)->face->height, (size)->face->num_glyphs);
FT_Error error = FT_Activate_Size(*size);
if (error) {
LOG("Could not activate size to get character data for character '%c', got error %#02x.", character, error);
return &FontCharacter::NULL_CHARACTER;
}
error = FT_Load_Char(face, character, FT_LOAD_DEFAULT);
if (error) {
LOG("Could not load glyph '%c', got error %#02x.", character, error);
return &FontCharacter::NULL_CHARACTER;
}
error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
if (error) {
LOG("Could not render glyph '%c', got error %#02x.", character, error);
return &FontCharacter::NULL_CHARACTER;
}
|