[Freetype]MinGW编译 FreeType2.7 以及 示例代码

C/C++第三方开源库的介绍和相关讨论
回复
头像
C艹艹
崭露头角
崭露头角
帖子: 26
注册时间: 2016年09月23日 11:32
联系:

[Freetype]MinGW编译 FreeType2.7 以及 示例代码

帖子 C艹艹 »

需要提前配置好的环境:
MinGW: http://nuwen.net/mingw.html
MSYS2.0: https://sourceforge.net/projects/msys2/
Cmake 备用

FreeType 下载地址:
https://www.freetype.org/download.html
http://download.savannah.gnu.org/releases/freetype/
预编译的版本,但是版本只到 2.3:
https://sourceforge.net/projects/gnuwin ... pe/2.3.5-1

以下引用内容转自 http://general.blog.51cto.com/927298/662736/
以 freetype-2.4.0.tar.gz 为例,下载后解压,例如目录是 D:\freetype-2.4.0

从系统菜单打开找到 MinGW-w64 Win32 Shell (#1)终端并打开,进入目录:
cd 'D\freetype-2.4.0'

打开 msys shell 或者 cygwin, 执行:
$ ./configure
$ make

错误提示:

代码: 全选

Fatal error: can't create D:/freetype-2.4.0/objs/.libs/ftsystem.o: No such file or directory
make: *** [D:/freetype-2.4.0/builds/freetype.mk:198: D:/freetype-2.4.0/objs/ftsystem.lo] Error 1
原因是freetype-2.4.6/objs/下没有.libs文件夹,执行 mkdir ./objs/.libs
重新make, OK.
命令顺序参考:
$ cd 'D:\freetype-2.4.0'
$ ./configure
$ mkdir ./objs/.libs
$ make
好了,以上是对于2.4的版本,而 freetype 2.7,已经包含 CMake 配置文件,需要先单独建立一个目录,然后Cmake
mkdir build cd build cmake -G "MinGW Makefiles" .. make
生成 libfreetype.a 位于 build 目录下。

如果要生成动态库(DLL)请使用:
cmake -DBUILD_SHARED_LIBS=ON -G "MinGW Makefiles" ..

编译好的2.7库文件( .a .dll 32位 以及 64位 )
FT27_LIBRARY.7z
(1.52 MiB) 已下载 141 次
示例代码的编译和运行请看 二楼
上次由 C艹艹 在 2016年12月08日 21:40,总共编辑 8 次。
头像
C艹艹
崭露头角
崭露头角
帖子: 26
注册时间: 2016年09月23日 11:32
联系:

编译、运行 FreeType 示例程序 example1.c

帖子 C艹艹 »

III. Examples

makefile
MAIN=example1
CC=gcc
INCDIR= -ID:/freetype-2.4.0/include
LIBDIR= -LD:/freetype-2.4.0/objs/.libs
LIBS= -lfreetype

$MAIN:
${CC} -o ${MAIN} $(MAIN).c ${INCDIR} ${LIBDIR} ${LIBS}
  1. 执行 make (可以在MSYS终端,也可以在cmd),编译生成 example1.exe文件
  2. 将 D:\freetype-2.4.0\objs\.libs 目录下的 libfreetype-6.dll 复制到当前运行目录,
  3. 将需要使用的字体文件放置到当前目录,例如 Arial.ttf(或者指定绝对路径:C:/windows/fonts/arial.ttf)
  4. 调用方法,示例: example1 ./arial.ttf Text
附件
example1.c
(3.58 KiB) 已下载 143 次
头像
C艹艹
崭露头角
崭露头角
帖子: 26
注册时间: 2016年09月23日 11:32
联系:

MinGW编译 FreeType2.7

帖子 C艹艹 »

发现不需要 MSYS 或者 cygwin 也可以,
Cmake + MinGW,打开Cmd进入对应解压目录,
mkdir build cd build cmake -G "MinGW Makefiles" .. make
生成库文件 libfreetype.a 位于 build 目录下
头像
C艹艹
崭露头角
崭露头角
帖子: 26
注册时间: 2016年09月23日 11:32
联系:

编译 ft2demos

帖子 C艹艹 »

补充,编译 ft2demos-2.7.tar.gz

首先将编译过的 freetype-2.7 整个目录放在相同的解压目录下,重命名为 freetype2

和前面编译 freetype-2.7 静态库的过程类似,但是需要 mingw 或者 cygwin

在 MINGW64 Shell 执行 make

第一个错误
ld.exe: cannot open output file D:/Lib/ft2demos-2.7/bin/.libs/ftbench.exe: No such file or directory
mkdir ./bin/.libs
make

第二个错误
D:/Lib/ft2demos-2.7/src/ttdebug.c:34:21: fatal error: termios.h: No such file or directory #include <termios.h>
这个貌似是 unix 系统下的,暂时没找到解决方法。

bin 目录下生成三个工具:
ftbench.exe - 貌似是测试 freetype 运行效率,调用方式: ftbench.exe [参数] 字体完整路径

ftdump.exe - 导出数据和信息,示例:ftdump.exe [参数] 字体完整路径
-V 参数导出 Unicode/索引值 映射表

ftlint.exe - a simple font tester. This program tries to load all the glyphs of a given font.

这三个程序在调用的时候需要带后缀,否则提示错误。

粗略试了一下,ffdump.exe 好像可以导出字符的原始数据,
D:\Lib\ft2demos-2.7\bin>ftdump.exe -p c:/windows/fonts/consola.ttf |grep -A 5 "
97 "
glyf program 97 (0061)
0061:0000 b1_17_1b b8_01_9f b7_2b_19_2b_19_09_15_1c_25 b8
0061:0010 _01_a4 40_17_09_2c_18_df_1a_1a_01_15_df_13_41_20
0061:0020 _e0_0e_42_28_e0_04_44_1c_e0_01_43 00 3f ed 3f ed
0061:0030 3f ed 3f ed 12 39 2f ed 01 10 d6 e1 d4 c4 12 39
0061:0040 39 2f 2f f1 c5 31 30
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 0 访客