マルチプラットフォーム ライブラリでこの素晴らしいバージョンの freetype 2を使用しようとしています。Android ではまだテストしていませんが、win32 でコンパイルしてテストしてみました。エラーなしで問題なくコンパイルされますが、ライブラリが TT_CMap の「データ」(常に不良ポインター) メンバーを読み取ろうとすると、常にクラッシュします。それが発生する関数は、フォント ファイルのみに依存します。つまり、1 つのフォントが 1 つの場所に依存します。Windows、MacOS X、および Android のさまざまな ttd フォントを試してみましたが、セグメンテーション違反が発生する位置にのみ影響します。たとえば、標準ウィンドウの arial.ttf フォントの任意の文字のインデックスを取得しようとすると、常にここでクラッシュします。
static FT_UInt tt_cmap4_char_map_binary( TT_CMap cmap, FT_UInt32* pcharcode, FT_Bool next )
{
[...]
p = cmap->data + 6;
num_segs2 = FT_PAD_FLOOR( TT_PEEK_USHORT( p ), 2 );
[...]
cmap->data が無効なポインタであるためです。
私のテストコードは次のようになります。
int error = 0;
// Initialize freetype library first
error = FT_Init_FreeType( &ft_lib );
if ( error ) {
ODF(("Unable to init freetype library! Error code is %d.\n", error));
return false;
}
// Load font file into the memory buffer
iMemBuff faceFileBuff;
if (igelLoadResource(iString("Data/arial.ttf"), faceFileBuff) != ROR_Success) {
ODF(("ERROR: Unable to open font file!\n"));
return false;
}
// Init font
error = FT_New_Memory_Face( ft_lib, (FT_Byte*)faceFileBuff.GetPtr(), faceFileBuff.GetSize(), 0, &ft_face );
if ( error == FT_Err_Unknown_File_Format ) {
ODF(("ERROR: the font file could be opened and read, but it appears that its font format is unsupported.\n"));
return false;
} else if ( error ) {
ODF(("ERROR: %d error code means that the font file could not be opened or read, or simply that it is broken...\n", error));
return false;
}
// Setup font metrics
error = FT_Set_Pixel_Sizes( ft_face, 0, 16 );
// error = FT_Set_Char_Size(ft_face, 0, 16*64, 300, 300 );
if ( error ) {
ODF(("ERROR: Unable to set char/pixel size! Error code %d.\n", error));
return false;
}
sint32 ox = 0, oy = 0;
int error = 0;
FT_GlyphSlot slot = ft_face->glyph; // a small shortcut
for (uint32 cc=0; cc<text.StringSize(); ++cc) {
// Find the character 'a' index
int glyph_index = FT_Get_Char_Index( ft_face, text.CStr()[cc] );
// Load glyph
error = FT_Load_Glyph( ft_face, glyph_index, FT_LOAD_DEFAULT );
if ( error ) {
ODF(("ERROR: Unable to load face from the font! Error code %d.\n", error));
continue;
}
// Render the glyph
error = FT_Render_Glyph( ft_face->glyph, FT_RENDER_MODE_NORMAL );
if ( error ) {
ODF(("ERROR: Unable to render glyph! Error code %d.\n", error));
continue;
}
// Draw the glyph to our target surface
ComposeGlyph(image, &slot->bitmap, ox + slot->bitmap_left, oy + slot->bitmap_top);
ox += slot->advance.x >> 6;
}
そして、任意の文字で FT_Get_Char_Index を呼び出すとクラッシュします...
何か案が?