為了在嵌入式系統實現矢量中文顯示,我先在PC機上實現失量字庫中文顯示,在此基礎上將其移植到嵌入式系統中。該方法是利用VC++開發工具,將freetype庫函數移植到VC環境中進行開發。
在建立的工程中加入*.lib文件,以及頭文件。
#include <stdio.h>
#include <ft2build.h>
//#include FT_FREETYPE_H
#include <freetype\freetype.h>
#include <freetype\ftglyph.h>
簡單地創建一個FT_Library類型的變量,例如library,然后象下面那樣調用函數FT_Init_FreeType:
FT_Library pFTLib = NULL;
// 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 ;
}
FT_Face pFTFace = NULL;
// create font face from font file
error = FT_New_Face(pFTLib, "C:\\WINDOWS\\Fonts\\arialuni.ttf",0,& pFTFace);
當一個新的face對象建立時,所有成員都在初始化階段0設為0。調用FT_Set_Char_Size對這個結構進行賦值。這里有一個例子,它在一個300x300dpi設備上把字符大小設置為16pt。
error = FT_Set_Char_Size( face,
0,
16*64,
300,
300 );
FT_Set_Char_Size(pFTFace, 16 << 6 , 16 << 6 , 300 , 300 );
1、從字符碼檢索字形索引
glyph_index = FT_Get_Char_Index( pFTFace, ucode[n] );
2、從face中裝載字形
error = FT_Load_Glyph( pFTFace, glyph_index, FT_LOAD_DEFAULT );
error = FT_Get_Glyph(pFTFace -> glyph, & glyph);
3、得到字形位圖
FT_Glyph_To_Bitmap( & glyph, ft_render_mode_normal, 0 , 1 );