freetype显示矢量字体 -- 在PC上测试初步使用
解压freetype-2.4.10.tar.bz2,
重命名为freetype-2.4.10_pc放入01th_pc目录下。
进入目录配置:./configure
编译:make
安装:sudo make install
编译应用程序:example.c
gcc -o example1 example1.c -I /usr/local/include/freetype2 -lfreetype -lm
gcc编译参数设置 -I +头文件目录 库文件 使用数学函数
找一个字体文件:
simsun.ttc字体文件放入01th_pc目录下。
运行:
./example1 ./simsun.ttc zhu
太大了,看不到结果。
修改以下显示的宽度和高度:
#define WIDTH 80
#define HEIGHT 80
/* start at (0,40) relative to the upper left corner */
pen.x = 0 * 64;
pen.y = ( target_height - 40 ) * 64;
编译应用程序:example.c
运行:
./example1 ./simsun.ttc zhu
出结果了:
+*
***
+**
**
**
** ++* ++*
******** **++***+ *** ***
*++ +**+ ***+++** +** +**
* ***+ **+ +** ** **
+**+ ** +** ** **
*** ** ** ** **
+**+ ** ** ** **
+*** ** ** ** **
+**+ * ** ** **+ +**
+*** +* ** ** **+ +**+
+**+ ++** +**+ +**+ ***+++***
********+ **** **** +****+*++
显示“朱滔zhu”
修改example1.c在002th_chinese目录下,执行结果
++
+ **+ ++ ++
+**+ ** **+ ++****+
+**+ ** +**+ ++++******+++ +*
+*+ ** +++ +*+ ++++++ ++ ***
**++++**+++++***+ +*++++ ++ **+ +**
+*+++++**+++++++++ +++*+ +*+ +*+ **
+*+ ** +*+ ++ +*+ ** +*+ **
++ ** +*+ *+ +*+ ++ *+ **
++ ** ++ **++* + ++ ++ + ******** **++***+
++++++++++**++++++***+ +*+++ ++++**+++++*+ *++ +**+ ***+++**
+++++++++****+++++++++ + *+ ****+++++++**+ * ***+ **+ +**
****++ +* ** *+ +**+ ** +**
+****+*+ ++ ** *+ *** ** **
+**+** +*+ +*+ ** ++ *+ +**+ ** **
+**+ ** +**+ +++** **+***++*++*+ +*** ** **
+**+ ** +**+ ++*** ** ++ *+ +**+ * ** **
+**+ ** +**++ +*+ ** *+ +*** +* ** **
+**+ ** +****+ +*+ ** *+ +**+ ++** +**+ +**+
+*+ ** ++*++ +*+ ** *+ ********+ **** ****
+++ ** + +*+ **+++++++++*+
+ ** +*+ ** *+
++ ++ ++
宽字符显示:
gcc -finput-charset=GBK -fexec-charset=UTF-8 -o example1 example1.c -I /usr/local/include/freetype2 -lfreetype -lm
运行结果:
++
+ **+ ++ ++
+**+ ** **+ ++****+
+**+ ** +**+ ++++******+++ +*
+*+ ** +++ +*+ ++++++ ++ ***
**++++**+++++***+ +*++++ ++ **+ +**
+*+++++**+++++++++ +++*+ +*+ +*+ **
+*+ ** +*+ ++ +*+ ** +*+ **
++ ** +*+ *+ +*+ ++ *+ ** ++* +
++ ** ++ **++* + ++ ++ + ******** **++***+ *** *
++++++++++**++++++***+ +*+++ ++++**+++++*+ *++ +**+ ***+++** +** +
+++++++++****+++++++++ + *+ ****+++++++**+ * ***+ **+ +** **
****++ +* ** *+ +**+ ** +** **
+****+*+ ++ ** *+ *** ** ** **
+**+** +*+ +*+ ** ++ *+ +**+ ** ** **
+**+ ** +**+ +++** **+***++*++*+ +*** ** ** **
+**+ ** +**+ ++*** ** ++ *+ +**+ * ** ** **+ +
+**+ ** +**++ +*+ ** *+ +*** +* ** ** **+ +
+**+ ** +****+ +*+ ** *+ +**+ ++** +**+ +**+ ***+++
+*+ ** ++*++ +*+ ** *+ ********+ **** **** +****+
+++ ** + +*+ **+++++++++*+
+ ** +*+ ** *+
++ ++ ++
添加打印信息,分析结果:
printf("Unicode2: 0x%x\n",chinese_str[n]);
printf("origin.x/64 = %d,origin.y/64 = %d\n",pen.x/64,pen.y/64);
printf("xMin = %d,xMax = %d,yMin = %d,yMax = %d\n",bbox.xMin,bbox.xMax,bbox.yMin,bbox.yMax);
printf("slot->advance.x/64 = %d,slot->advance.y/64 = %d\n",slot->advance.x/64,slot->advance.y/64);
Unicode:
0x6731 0x6ed4 0x7a 0x68 0x75
Unicode2: 0x6731 朱
origin.x/64 = 0,origin.y/64 = 40
xMin = 1,xMax = 23,yMin = 37,yMax = 60
slot->advance.x/64 = 24,slot->advance.y/64 = 0
Unicode2: 0x6ed4 滔
origin.x/64 = 24,origin.y/64 = 40
xMin = 25,xMax = 47,yMin = 37,yMax = 59
slot->advance.x/64 = 24,slot->advance.y/64 = 0
Unicode2: 0x7a z
origin.x/64 = 48,origin.y/64 = 40
xMin = 50,xMax = 59,yMin = 40,yMax = 51
slot->advance.x/64 = 12,slot->advance.y/64 = 0
Unicode2: 0x68 h
origin.x/64 = 60,origin.y/64 = 40
xMin = 61,xMax = 71,yMin = 40,yMax = 57
slot->advance.x/64 = 12,slot->advance.y/64 = 0
Unicode2: 0x75 u
origin.x/64 = 72,origin.y/64 = 40
xMin = 73,xMax = 83,yMin = 40,yMax = 52
slot->advance.x/64 = 12,slot->advance.y/64 = 0