厚积薄发,滴水穿石

搬家到主站了:http://www.cnblogs.com/cokecoffe/
随笔 - 45, 文章 - 8, 评论 - 12, 引用 - 0
数据加载中……

FreeType的使用

在嵌入式环境中显示字体,如果采用点阵的方式,要先取得汉字的点阵表示形式,然后根据点阵中每一位是否为1来决定是否对屏幕上相应的像素赋值;如果采用矢量字体的话,例如使用freetype库来显示TrueType类型的字体时,其大致的过程如下:
1.初始化库
1 FT_Library library;
2 FT_Face face;
3
 FT_Error error = FT_Init_FreeType( &library ); 

2. 加载相应的字体文件
error = FT_New_Face( library, "/usr/share/fonts/truetype/arial.ttf"0&face );

3. 设置字体的大小  
1 error = FT_Set_Char_Size(face, /* handle to face object */  
2   0/* char_width in 1/64th of points */
3   16*64/* char_height in 1/64th of points */
4   300/* horizontal device resolution */
5   300 ); /* vertical device resolution */
6 
7   error = FT_Set_Pixel_Sizes(face, /* handle to face object */
8   0/* pixel_width */
9   16 ); /* pixel_height */

4. 加载字符的glyph
1 glyph_index = FT_Get_Char_Index( face, charcode );
2 
3 error = FT_Load_Glyph(face, /* handle to face object */
4   glyph_index, /* glyph index */
5   load_flags ); /* load flags, see below */
6 
7 error = FT_Render_Glyph( face->glyph, /* glyph slot */
8   render_mode ); /* render mode */

5. 字体变换(旋转和缩放)
1 error = FT_Set_Transform( face, /* target face object */
2   &matrix, /* pointer to 2x2 matrix */
3   &delta ); /* pointer to 2d vector */

6. 把字符显示出来
1 draw_bitmap( &slot->bitmap, pen_x + slot->bitmap_left, pen_y - slot->bitmap_top );

posted on 2011-09-07 10:47 Wangkeke 阅读(3495) 评论(0)  编辑 收藏 引用 所属分类: Tools


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