2012-07-13 82 views
5

我有以下问题:iPhone:Fontconfig的错误:无法加载默认的配置文件

我包括fontconfig的libfontconfig.a的静态库到我iPhone项目

的应用正在建设,我可以在设备上运行,但是当我做了调用与以下错误

Fontconfig error: Cannot load default config file

terminate called throwing an exception

需要这个库的一些功能的应用程序崩溃的方法,我读了这当FontConfig找不到通常位于/ etc/fonts中的fonts.conf文件时,通常会发生错误。

但我不能在文件移动到iPhone的这个目录。有没有人有解决方案?将文件复制到应用程序包也无济于事。

我将不胜感激任何帮助。

+0

你是如何能够编译Fontconfig的。你能分享图书馆吗? – 2013-05-24 14:37:48

+0

我没有自己编译它。我把它作为另一个项目。你可以在这个github项目中找到已编译的fontConfig:https://github.com/xil3f/podofo_iOS_sample – 2013-06-11 22:39:11

回答

3

我终于找到了一种方法来解决这个问题。我设置环境变量 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> 

然后它没有崩溃了。

相关问题