数码相册——FreeType介绍
- 硬件平台:韦东山嵌入式Linxu开发板(S3C2440.v3)
- 软件平台:运行于VMware Workstation 12 Player下UbuntuLTS16.04_x64 系统
- 参考资料:《嵌入式Linux应用开发手册》、《嵌入式Linux应用开发手册第2版》、【FreeType教程】、【FreeType2使用总结】
- 开发环境:Linux 3.4.2内核、arm-linux-gcc 4.3.2工具链
- 源码仓库:https://gitee.com/d_1254436976/Embedded-Linux-Phase-3
一、FreeType简要介绍
FreeType是一个软件字体引擎,被设计成小、高效、可定制和可移植,同时能够产生高质量的输出(字形图像)。它可以用于图形库、显示服务器、字体转换工具、文本图像生成工具以及许多其他产品。
支持单色位图、反走样位图的渲染。FreeType库是高度模块化的程序库,虽然它是使用ANSI C开发,但是采用面向对象的思想,因此,FreeType的用户可以灵活地对它进行裁剪。
在嵌入式环境中,可以只编译那些你的嵌入式工程或环境需要的模块,从而有效的减小FreeType 2 的代码大小。
废话少说,下面结合FreeType的官方教程来进行代码介绍与编程步骤总结。
二、简单的字形装载过程的描述
1.头文件

- 在使用时候,需要包含下列头文件:
在FreeType中有许多头文件的宏定义,需要添加ft2build.h文件才可以使用这些宏定义。
#include <ft2build.h>
#include FT_FREETYPE_H
2.库初始化
这调用的函数为FT_Init_FreeType()
- 原型
FT_Init_FreeType( FT_Library *alibrary );
- 参数解析
·FT_Library * alibrary:A handle to a new library object.(一个新库对象的句柄) - 返回值
成功执行:0,错误执行:FreeType error code(错误码) - 调用案例
FT_Library library;
...
error = FT_Init_FreeType( &library );
if ( error )
{
... an error occurred during library initialization ...
}
3.加载字体
- 函数原型
FT_New_Face( FT_Library library,
const char* filepathname,
FT_Long face_index,
FT_Face *aface );
- 参数
- FT_Library library — A handle to the library resource(库资源的句柄).
- const char * filepathname — A path to the font file(字体文件的路径).
- FT_Long face_index — The index of the face within the font. The first face has index 0(字体中face的索引。第一个face的索引为0).
- FT_Face * aface — A handle to a new face object. If ‘face_index’ is greater than or equal to zero, it must be non-NULL. See FT_Open_Face for more details(一个新face对象的句柄。如果FACE_INDEX大于或等于零,则必须为非NULL).
- 返回值
成功执行:0,错误执行:FreeType error code(错误码) - 调用案例
FT_Library library; /* handle to library */
FT_Face face; /* handle to face object */
error = FT_Init_FreeType( &library );
if ( error ) {
... }
error = FT_New_Face( library,
"/usr/share/fonts/truetype/arial.ttf",
0,
&face );
if ( error == FT_Err_Unknown_File_Format )
{
... the font file could be opened and read, but it appears
... that its font format is unsupported
}
else if ( error )
{
... another error code means that the font file could not
... be opened or read, or that it is broken...
}
4.访问face数据
可以通过face句柄进行访问
- 原型
typedef struct FT_FaceRec_

本文介绍了FreeType字体引擎的基本概念,包括其特点、模块化设计以及如何在嵌入式Linux环境下进行字形装载和渲染。文章详细解释了FreeType的库初始化、字体加载、设置字体大小、字形图像加载及文本渲染等步骤。
最低0.47元/天 解锁文章
3134

被折叠的 条评论
为什么被折叠?



