24,856
社区成员
发帖
与我相关
我的任务
分享
FT_Library pFTLib = NULL;
FT_Face pFTFace = NULL;
FT_Error error = 0;
// Init FreeType Lib to manage memory
error = FT_Init_FreeType(&pFTLib);
if (error) {
pFTLib = 0;
printf(" There is some error when Init Library ");
return -1;
}
// create font face from font file
error = FT_New_Face(pFTLib, "/home/alex/download/方正细等线.ttf", 0,
&pFTFace);
charCodeStart = 0x4e38;
charCodeEnd = 0x4e4b;
if (!error) {
FT_Set_Pixel_Sizes(pFTFace, 14, 14);
FT_Glyph glyph;
for (charCode = charCodeStart; charCode <= charCodeEnd; charCode++){
// load glyph for the character
FT_Load_Glyph(pFTFace, FT_Get_Char_Index(pFTFace, charCode), FT_LOAD_DEFAULT);
error = FT_Get_Glyph(pFTFace -> glyph, &glyph);
if (!error) {
// convert glyph to bitmap with 256 gray
FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1);
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph) glyph;
FT_Bitmap *bitmap = &bitmap_glyph -> bitmap;
for (i = 0; i < bitmap->rows; ++i) {
for (j = left; j < bitmap->width + left; ++j) {
printf("%c", bitmap->buffer[i * bitmap->width + j] ? '*'
: ' ');
}
}
// free glyph
FT_Done_Glyph(glyph);
glyph = NULL;
}
}
// free face
FT_Done_Face(pFTFace);
pFTFace = NULL;
} else {
printf("Loading the ttf file failed!\n");
printf("error code is %d\n", error);
return 0;
}
// free FreeType Lib
FT_Done_FreeType(pFTLib);
pFTLib = NULL;