為了在嵌入式系統(tǒng)實(shí)現(xiàn)矢量中文顯示,我先在PC機(jī)上實(shí)現(xiàn)失量字庫(kù)中文顯示,在此基礎(chǔ)上將其移植到嵌入式系統(tǒng)中。該方法是利用VC++開發(fā)工具,將freetype庫(kù)函數(shù)移植到VC環(huán)境中進(jìn)行開發(fā)。
2.1 建立VC動(dòng)態(tài)連接庫(kù)工程
在建立的工程中加入*.lib文件,以及頭文件。
#include <stdio.h>
#include <ft2build.h>
//#include FT_FREETYPE_H
#include <freetype\freetype.h>
#include <freetype\ftglyph.h>
簡(jiǎn)單地創(chuàng)建一個(gè)FT_Library類型的變量,例如library,然后象下面那樣調(diào)用函數(shù)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);
當(dāng)一個(gè)新的face對(duì)象建立時(shí),所有成員都在初始化階段0設(shè)為0。調(diào)用FT_Set_Char_Size對(duì)這個(gè)結(jié)構(gòu)進(jìn)行賦值。這里有一個(gè)例子,它在一個(gè)300x300dpi設(shè)備上把字符大小設(shè)置為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 );