随笔 - 132  文章 - 51  trackbacks - 0
<2011年7月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(7)

随笔分类

随笔档案

文章分类

文章档案

cocos2d-x

OGRE

OPenGL

搜索

  •  

最新评论

阅读排行榜

评论排行榜

1         引言

为了在嵌入式系统实现矢量中文显示,我先在PC机上实现失量字库中文显示,在此基础上将其移植到嵌入式系统中。该方法是利用VC++开发工具,将freetype库函数移植到VC环境中进行开发。

2         实现步骤

2.1       建立VC动态连接库工程

在建立的工程中加入*.lib文件,以及头文件。

#include <stdio.h>

#include <ft2build.h>

//#include FT_FREETYPE_H

#include <freetype\freetype.h>

#include <freetype\ftglyph.h>

2.2       初始化库

简单地创建一个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 ;

}

2.3       装载一个字体face

        FT_Face        pFTFace         =  NULL;

        //  create font face from font file

       error  =  FT_New_Face(pFTLib, "C:\\WINDOWS\\Fonts\\arialuni.ttf",0,& pFTFace);

2.4       设置当前象素尺寸

当一个新的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 );

2.5       装载一个字形图像

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 );

2.6       输出字形

 

posted on 2011-05-03 14:00 风轻云淡 阅读(2245) 评论(0)  编辑 收藏 引用 所属分类: FreeType

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理