fontconfig 源码分析

手头项目遇到个ass库,在这个库的中用到了fontconfig库,由于字符编码问题,导致找不到字体文件,所以不得不修改下fontconfig库,看了看源码,头大眼皮沉。。。写个记录屡屡思路

首先libass调用fontconfig库集成了几个函数

fontconfig_init();初始化fontfontconfg库

fontconfig_select();选择一个字体,输入族名编码等参数,返回一个可用的字体的字体文件路径。

fontconfig_done();销毁库对象

fontconfig_update();更新kudu库对象

libass库的rander.c文件中的调用顺序是init - select - update -select -update -……done;

并且定义了一个FCInstance的结构体作为上下文,其中有个FcConfig*的指针存放fontconfig库返回的上下文,FcConfig结构体内存放了一系列的set结构,其中包括config配置文件的路径,字体文件夹的路径,具体字体文件的路径,字体替换的patterns等信息。fontconfig的运行主要依靠该结构体。

首先是初始化

调用 FcConfigCreate();

函数返回一个FcConfig结构体指针,并对结构体内各个set结构初始化,置零。

调用FcConfigParseAndLoad();

参数为FcConfig结构体指针 和 字体配置文件的路径,最后是是否覆盖。

说道这里就得说下字体配置文件一般命名为fonts.conf ,该文件可以根据自己需求编辑,也可以直接找一个套用(文档后会附一份我常用的字体配置文件)。所谓fonts.con文件其实就是一个xml,格式如下

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/fonts.conf file to configure system font access -->
<fontconfig>

<!--
    DO NOT EDIT THIS FILE.
    IT WILL BE REPLACED WHEN FONTCONFIG IS UPDATED.
    LOCAL CHANGES BELONG IN 'local.conf'.

    The intent of this standard configuration file is to be adequate for
    most environments.  If you have a reasonably normal environment and
    have found problems with this configuration, they are probably
    things that others will also want fixed.  Please submit any
    problems to the fontconfig bugzilla system located at fontconfig.org

    Note that the normal 'make install' procedure for fontconfig is to
    replace any existing fonts.conf file with the new version.  Place
    any local customizations in local.conf which this file references.

    Keith Packard
-->

<!-- Font directory list -->

<!--
  Uncomment this directory if we need libass and fontconfig to access all system fonts.
  The drawback is the long initial indexing time by fontconfig, and mkv files usually
  include their fonts.
  <dir>WINDOWSFONTDIR</dir>
-->
    <dir>c:/windows/fonts</dir>
  <dir>media/Fonts</dir>       <!-- used by an installed XBMC -->
  <dir>../../media/Fonts</dir> <!-- used when running in Visual Studio -->
    <dir>~/.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值