t+0x1ea): undefined reference to `FT_Init_FreeType'
example1.c:(.text+0x216): undefined reference to `FT_New_Face'
example1.c:(.text+0x236): undefined reference to `FT_Set_Pixel_Sizes'
example1.c:(.text+0x24d): undefined reference to `cos'
example1.c:(.text+0x285): undefined reference to `sin'
example1.c:(.text+0x2bd): undefined reference to `sin'
example1.c:(.text+0x2f5): undefined reference to `cos'
example1.c:(.text+0x360): undefined reference to `FT_Set_Transform'
example1.c:(.text+0x386): undefined reference to `FT_Load_Char'
example1.c:(.text+0x409): undefined reference to `FT_Done_Face'
example1.c:(.text+0x415): undefined reference to `FT_Done_FreeType'
example1.c:(.text+0x24d): undefined reference to `cos'
example1.c:(.text+0x285): undefined reference to `sin'
example1.c:(.text+0x2bd): undefined reference to `sin'
example1.c:(.text+0x2f5): undefined reference to `cos'
指定库编译freetype gcc -o example1 example1.c -I /usr/local/include/freetype2 –lfreetype
缺数学类定义
example1.c:(.text+0x24d): undefined reference to `cos'
example1.c:(.text+0x285): undefined reference to `sin'
example1.c:(.text+0x2bd): undefined reference to `sin'
example1.c:(.text+0x2f5): undefined reference to `cos'
加-lm为加数学类库意思 gcc -o example1 example1.c -I /usr/local/include/freetype2 -lfreetype -lm
执行exampe1 用宋体文件 显示abcfg
./example1 ./simsun.ttc abcfg
陈志朋uicode码为 48 96 D7 5F 67 0B
int chinese_str[] = {0x9648,0x5fd7,0x670b};
for ( n = 0; n < 4; n++ )
{
/* set transformation */
FT_Set_Transform( face, &matrix, &pen );
/* load glyph image into the slot (erase previous one) */
error = FT_Load_Char( face, chinese_str[n], FT_LOAD_RENDER );
if ( error )
continue; /* ignore errors */
/* now, draw to our target surface (convert position) */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
target_height - slot->bitmap_top );
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
./example1 ./simsun.ttc abc
无法直接使用“abc陈志朋a”
使用宽字符
添加头文件include<wchar.h>
#include <wchar.h>
wchar_t * chinese_str = L"陈志朋~陈";
unsigned int *p = (wchar_t *)chinese_str;
int i = 0;
printf("uicode: \n");
for( i = 0; i < wcslen(chinese_str); i++)
{
printf("0x%x " , p[i]);
}
printf("\n");
return 0;
85:27: error: converting to execution character set: Invalid or incomplete multibyte or wide character
代码格式为asii应转化为uicode码
gcc -finput-charset=GBK -fexec-charset=UTF-8 -o example1 example1.c -I /usr/local/include/freetype2 -lfreetype -lm
结果
uicode:
0x9648 0x5fd7 0x670b 0x7e 0x9648
打印出位置大小参数
添加头文件#include FT_GLYPH_H
FT_BBox bbox;
FT_Glyph glyph;
// 将FT_GlyphSlot glyph转化为 FT_Glyph glyph;
error = FT_Get_Glyph( face->glyph, &glyph );
if(error)
{
printf("FT_Get_Glyph error \n");
}
/*从glyph中获取bbox*/
FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox );
//汉字uicode码
printf("uicode: %x\