一、在PC上的安装与使用
1) 开发环境
系统版本: ubuntu14.04
freetype版本: freetype-2.4.10
gcc版本: gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
2) 步骤
1. 解压缩 tar xjf freetype-2.4.10.tar.bz2
2. 配置 ./configure
3. 编译安装 make install
注意: 安装完后会将freetype的头文件安装到/usr/local/include/freetype2目录下,库文件安装到
/usr/local/lib目录下
4. 测试用例
编译测试文件example.c gcc example.c -o example -I /usr/local/include/freetype2 -lfreetype -lm
/* example1.c */
/* */
/* This small program shows how to print a rotated string with the */
/* FreeType 2 library. */#include <stdio.h>
#include <string.h>
#include <math.h>#include <ft2build.h>
#include FT_FREETYPE_H#define WIDTH 80
#define HEIGHT 80/* origin is the upper left corner */
unsigned char image[HEIGHT][WIDTH];/* Replace this function with something useful. */void
draw_bitmap( FT_Bitmap* bitmap,FT_Int x,FT_Int y)
{FT_Int i, j, p, q;FT_Int x_max = x + bitmap->width;FT_Int y_max = y + bitmap->rows;for ( i = x, p = 0; i < x_max; i++, p++ ){for ( j = y, q = 0; j < y_max; j++, q++ ){if ( i < 0 || j < 0 ||i >= WIDTH || j >= HEIGHT )continue;image[j][i] |= bitmap->buffer[q * bitmap->width + p];}}
}void
show_image( void )
{int i, j;for ( i = 0; i < HEIGHT; i++ ){for ( j = 0; j < WIDTH; j++ )putchar( image[i][j] == 0 ? ' ': image[i][j] < 128 ? '+': '*' );putchar( '\n' );}
}int
main( int argc,char** argv )
{FT_Library library;FT_Face face;FT_GlyphSlot slot;FT_Matrix matrix; /* transformation matrix */FT_Vector pen; /* untransformed origin */FT_Error error;char* filename;char* text;double angle;int target_height;int n, num_chars;if ( argc != 3 ){fprintf ( stderr, "usage: %s font sample-text\n", argv[0] );exit( 1 );}filename = argv[1]; /* first argument */text = argv[2]; /* second argument */num_chars = strlen( text );angle = ( 0.0 / 360 ) * 3.14159 * 2; /* use 25 degrees */target_height = HEIGHT;error = FT_Init_FreeType( &library ); /* initialize library *//* error handling omitted */error = FT_New_Face( library, argv[1], 0, &face ); /* create face object *//* error handling omitted */#if 0/* use 50pt at 100dpi */error = FT_Set_Char_Size( face, 50 * 64, 0,100, 0 ); /* set character size *//* pixels = 50 /72 * 100 = 69 */
#elseFT_Set_Pixel_Sizes(face, 24, 0);
#endif/* error handling omitted */slot = face->glyph;/* set up matrix */matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );/* the pen position in 26.6 cartesian space coordinates; *//* start at (0,40) relative to the upper left corner */pen.x = 0 * 64;pen.y = ( target_height - 40 ) * 64;for ( n = 0; n < num_chars; n++ ){/* set transformation */FT_Set_Transform( face, &matrix, &pen );/* load glyph image into the slot (erase previous one) */error = FT_Load_Char( face, text[n], FT_LOAD_RENDER );if ( error )continue; /* ignore errors *//* now, draw to our target surface (convert position) */draw_bitmap( &slot->bitmap,slot->bitmap_left,target_height - slot->bitmap_top );/* increment pen position */pen.x += slot->advance.x;pen.y += slot->advance.y;}show_image();FT_Done_Face ( face );FT_Done_FreeType( library );return 0;
}/* EOF */
运行测试程序 ./example ./simsun.ttc fbg (预先将simsun.ttc字体文件拷贝到当前目录)结果如下:
二、在s3c2440上的安装与使用
1) 开发环境
内核版本: linux-2.6.22
freetype版本: freetype-2.4.10
gcc版本: gcc-3.4.5
2) 步骤
1. 解压缩 tar xjf freetype-2.4.10.tar.bz2
2. 配置 ./configure --host=arm-linux --prefix=自定义安装目录
3. 编译安装 make install
注意: 安装完后会将freetype的头文件和库文件安装到自定义安装目录下
4. 测试用例
为了避免编译时指定各个参数现在将生成的头文件和库文件拷贝到交叉工具链中,首先进入头文件所在目录并执行命令
cp * /opt/cross-tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include -rf
mv freetype2/freetype/ .
然后进入库文件所在目录并执行如下命令
cp * /opt/cross-tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib -rf -d
同时将动态库拷贝到文件系统中
cp *so* /nfs/sysfs/fs_s3c2440/lib -d
编译测试文件example.c arm-linux-gcc example.c -o example -lfreetype -lm