【问题标题】:iPhone: Fontconfig error: Cannot load default config fileiPhone:Fontconfig 错误:无法加载默认配置文件
【发布时间】:2012-07-20 00:13:20
【问题描述】:

我有以下问题:

我将 FontConfig libfontconfig.a 的静态库包含到我的 iPhone 项目中。

应用程序正在构建,我可以在设备上运行它,但是当我调用需要此库的某些功能的方法时,应用程序崩溃并出现以下错误

Fontconfig 错误:无法加载默认配置文件

终止调用抛出异常

我了解到,当 FontConfig 找不到通常位于 /etc/fonts 中的 fonts.conf 文件时,通常会发生此错误。

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

我将不胜感激。

【问题讨论】:

  • 你是如何编译fontConfig的。你能分享图书馆吗?
  • 不是我自己编译的。我把它从另一个项目中拿出来。你可以在这个github项目中找到编译好的fontConfig:github.com/xil3f/podofo_iOS_sample

标签: iphone ios xcode static-libraries fontconfig


【解决方案1】:

我终于找到了解决这个问题的方法。我设置了一个环境变量 FONTCONFIG_FILE 和FONTCONFIG_PATH,它们定义了fonts.conf 文件的位置以及/etc/fonts 之前的路径。所以我可以将fonts目录添加到项目中并定义路径@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/fonts 和缓存目录到 FC/cache 并在两个部分调整了 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>

然后它不再崩溃了。

【讨论】:

    猜你喜欢
    • 2019-10-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-27
    相关资源
    最近更新 更多