#include
#include
#include FT_FREETYPE_H
#define CHARSIZE 32 // 字符位图的大小设为32 * 32
int GetCharBitmap(int iCharSize, unsigned int uiCharCode);
int main(int argc, char** argv)
{
unsigned int uiCharCode = 0x0061; // 字母a的ucs2编码.
GetCharBitmap(CHARSIZE, uiCharCode);
return 0;
}
int GetCharBitmap(int iCharSize, unsigned int uiCharCode)
{
FT_Library ftLibrary;
FT_Error ftError = FT_Init_FreeType(&ftLibrary);
if(ftError)
{
printf("Init freetype library fail!/n");
return -1;
}
FT_Face ftFace;
ftError = FT_New_Face( ftLibrary, "ukai.ttc", 0, &ftFace);
if(ftError == FT_Err_Unknown_File_Format)
{
printf("Error! Could not support this format!/n");
return -1;
}
else if(ftError)
{
printf("Error! Could not open file ukai.ttc!/n");
return -1;
}
ftError = FT_Set_Pixel_Sizes(ftFace, iCharSize, 0);
if(ftError)
{
printf("Set pixel sizes to %d*%d error!/n", iCharSize,iCharSize);
return -1;
}
FT_UInt uiGlyphIndex = FT_Get_Char_Index(ftFace,uiCharCode);
FT_Load_Glyph(ftFace,uiGlyphIndex, FT_LOAD_DEFAULT);
FT_Render_Glyph(ftFace->glyph, FT_RENDER_MODE_MONO);
int iRow = 0, iCol = 0;
for(iRow = 0; iRow < ftFace->glyph->bitmap.rows;iRow++)
{
for(iCol = 0; iCol < ftFace->glyph->bitmap.width;iCol++)
{
if((ftFace->glyph->bitmap.buffer[iRow *ftFace->glyph->bitmap.pitch + iCol/8] & (0xC0 >>(iCol % 8))) == 0)
{
printf("_");
}
else
{
printf("0");
}
}
printf("/n");
}
return 0;
}