Fontconfig 配置
跳转到导航
跳转到搜索
渲染设置
<match target="font">
<edit mode="assign" name="autohint">
<bool>false</bool>
</edit>
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
<edit mode="assign" name="lcdfilter">
<const>lcddefault</const>
</edit>
<edit name="rgba" mode="assign">
<const>rgb</const>
</edit>
</match>
点阵与矢量字体
创建链接 /etc/fonts/conf.d/70-no-bitmaps.conf
到 ../conf.avail/70-no-bitmaps.conf
来禁用点阵字体。[1]
禁用指定矢量字体中内嵌的点阵字体:
<match target="pattern" name="family">
<edit name="embeddedbitmap">
<bool>false</bool>
</edit>
</match>
字体编辑
基础操作
以下设置将使用文泉驿正黑取代小于 12px 的宋体:
<match target="pattern">
<test name="family">
<string>宋体</string>
</test>
<test compare="less_eq" name="pixelsize">
<double>12</double>
</test>
<edit binding="strong" mode="prepend" name="family">
<string>文泉驿正黑</string>
</edit>
</match>
Arch 下设置 monospace 字体:
<match target="pattern">
<test qual="any" name="family">
<string>monospace</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>DejaVu Sans Mono</string>
</edit>
</match>
指定程序名
使用 prgname
属性来指定程序名,如:
<match target="pattern">
<test qual="any" name="family">
<string>monospace</string>
</test>
<test name="prgname" compare="not_eq">
<string>leafpad</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>DejaVu Sans Mono</string>
<string>文泉驿等宽正黑</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>monospace</string>
</test>
<test name="prgname" compare="eq">
<string>leafpad</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>宋体</string>
</edit>
</match>
prgname
的值可以从设置环境变量 FC_DEBUG=1
之后的调试输出中取得。
去除指定范围的字符
<match target="scan">
<test name="family" compare="contains">
<string>DejaVu</string>
</test>
<edit name="charset" mode="assign" binding="same">
<minus>
<name>charset</name>
<charset>
<range>
<int>0x1f600</int>
<int>0x1f640</int>
</range>
</charset>
</minus>
</edit>
</match>
修改后需要运行 sudo fc-cache -rf
来生效。对火狐(93)无效。
使用指定字体来取代斜体的汉字
为了避免影响英文字体,需要 target 到匹配的中文字体上。为了避免倾斜显示,需要在 scan 的时候设置 italic。
<match target="pattern">
<test qual="any" name="family">
<string>文泉驿等宽正黑</string>
</test>
<test name="slant">
<const>Italic</const>
</test>
<edit name="family" binding="same" mode="prepend">
<string>楷体_GB2312</string>
</edit>
</match>
<match target="scan">
<test qual="any" name="family">
<string>楷体_GB2312</string>
</test>
<edit name="slant" binding="same" mode="append">
<const>Italic</const>
</edit>
</match>
需要刷新字体缓存:sudo fc-cache -rf
。
禁用字体
<selectfont>
<rejectfont>
<patelt name="family">
<string>Source Han Sans SC</string>
</patelt>
<patelt name="family">
<string>Source Han Sans HW SC</string>
</patelt>
</rejectfont>
</selectfont>
命令行工具
查询
查询指定字体是否包含指定字符:
fc-list "Symbols Nerd Font":charset=0x45
环境变量
FONTCONFIG_FILE
- 指向主配置文件(默认为
/etc/fonts/fonts.conf
) FONTCONFIG_PATH
- 主配置目录
FC_DEBUG
- 输出多种调试信息
LC_CTYPE
- locale 会影响 fontconfig 对字体的选择(即使设置了别名,没有声明支持该语种的字体也可能被排除)
配置文件
用户配置文件位于 ~/.config/fontconfig/fonts.conf
。以前位于 ~/.fonts.conf
。在 Arch Linux 上这个由 /etc/fonts/conf.d/50-user.conf
决定。
archlinuxcn/fontconfig-ubuntu-zh-cn
包含有来自 Ubuntu 的 CJK 配置,其中含有对 Windows 常见字体名的到 Arphic 和文泉驿字体等的别名配置。[3]
参见
外部链接
- fonts.conf 中文手册 [金步国]
- Linux 字体配置要略(2012-02-15 更新) - Ubuntu中文论坛
- Linux fontconfig 的字体匹配机制 - 双猫CC
- 用 fontconfig 治理 Linux 中的字体 - 双猫CC