我终于找到了一种方法来解决这个问题。我设置环境变量 FONTCONFIG_FILE和FONTCONFIG_PATH定义fonts.conf文件的位置,那是以前的/ etc /字体的路径。所以我可以将字体目录添加到项目中并定义路径@runtime。
环境变量在你的代码中设置调用需要的fontconfig的功能的方法之前。我在AppDelegate中开始我的应用程序后设置它。
这里是我添加的代码:
//Get the directory of your Application
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
//Create a String with the location of your fonts.conf file
NSString *fontconfigFile= [bundlePath stringByAppendingString:
[NSString stringWithFormat:@"/fonts/fonts.conf"]];
//Create a String with the path of the FontConfig configuration path
NSString *fontconfigPath= [bundlePath stringByAppendingString:
[NSString stringWithFormat:@"/fonts"]];
//Set the Environment Variables
setenv("FONTCONFIG_FILE", [fontconfigFile UTF8String], 0);
setenv("FONTCONFIG_PATH", [fontconfigPath UTF8String], 0);
第二步我只好再修改我的fonts.conf文件。我加入了字体目录FC /字体和缓存目录FC /缓存我的项目和调整了两个部分的fonts.conf文件。
我改变第一部分:
<!-- Font directory list -->
<dir>/usr/share/fonts</dir>
<dir>/usr/X11R6/lib/X11/fonts</dir>
<dir>~/.fonts</dir>
到:
<!-- Font directory list -->
<dir>FC/fonts</dir>
和第二部分:
<!-- Font cache directory list -->
<cachedir>/opt/local/fc1407cd/var/cache/fontconfig</cachedir>
<cachedir>~/.fontconfig</cachedir>
到:
<!-- Font cache directory list -->
<cachedir>FC/cache</cachedir>
然后它没有崩溃了。
你是如何能够编译Fontconfig的。你能分享图书馆吗? – 2013-05-24 14:37:48
我没有自己编译它。我把它作为另一个项目。你可以在这个github项目中找到已编译的fontConfig:https://github.com/xil3f/podofo_iOS_sample – 2013-06-11 22:39:11