为什么 fc-match 不尊重我对 Courier 的匹配和编辑规则,而对 Consolas 却如此?

Lon*_*ner 3 linux fonts debian xfce

我正在使用带有 XFCE 的 Debian。

默认行为:无匹配项或别名

首先,让我展示当 ~/.config/fontconfig/fonts.conf 没有匹配或别名标签时我的系统的默认行为。

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
</fontconfig>
Run Code Online (Sandbox Code Playgroud)

在这种情况下, fc-match 为 Courier 和 Consolas 输出以下内容。

lone@debian:~$ fc-match Courier
n022003l.pfb: "Nimbus Mono L" "Regular"
lone@debian:~$ fc-match Consolas
DejaVuSans.ttf: "DejaVu Sans" "Book"
Run Code Online (Sandbox Code Playgroud)

自定义行为:定义匹配时

现在我在 ~/.config/fontconfig/fonts.conf 中有以下内容。

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <!-- Courier => DejaVu Sans Mono -->
    <match>
        <test name="family"><string>Courier</string></test>
        <edit name="family"><string>Deja Vu Sans Mono</string></edit>
    </match>

    <!-- Consolas => DejaVu Sans Mono -->
    <match>
        <test name="family"><string>Consolas</string></test>
        <edit name="family"><string>Deja Vu Sans Mono</string></edit>
    </match>
</fontconfig>
Run Code Online (Sandbox Code Playgroud)

在这种情况下, fc-match 输出以下内容。

lone@debian:~$ fc-match Courier
n022003l.pfb: "Nimbus Mono L" "Regular"
lone@debian:~$ fc-match Consolas
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"
Run Code Online (Sandbox Code Playgroud)

在这里我们看到系统尊重了我对 Consolas 的替换规则,但它没有尊重我对 Courier 的替换规则。为什么输出fc-match Courier仍然是“Nimbus Mono L”而不是“DejaVu Sans Mono”?

小智 5

我知道这个问题可能已经过时了,但是我在自己搜索解决方案时遇到了它,该解决方案用 Liberation Sans 覆盖系统替换 Arial,我在新的 Kubuntu Xenial 16.04 桌面上不喜欢它。

如果您想要为您的用户覆盖 fontconfig 的默认替换,也许您有兴趣阅读我在 Askubuntu 上的帖子:https ://askubuntu.com/a/793363/306420

简短的摘要

在现代系统上, fontconfig 从~/.config/fontconfig/fonts.conf或 (更好地用于分离目的)拉取用户配置~/.config/fontconfig/conf.d

就我而言,我希望 Firefox 使用 Noto Sans 使用 CSS 字体系列来渲染文本,以更喜欢 Arial。Fontconfig 默认配置为使用 Liberation Sans 作为 Arial ( /etc/fonts/conf.avail/30-metric-aliases.conf) 的度量插入,起初似乎无法在不更改 fontconfig 的主要配置文件的情况下覆盖。

经过长时间的搜索、反复试验,解决方案非常简单:在提到的用户目录中时会尊重覆盖,并根据 fontconfig 的期望在表单中命名[0-9][0-9]*.conf(请参阅/etc/fonts/conf.avail/50-user.conf/etc /fonts/conf.d/README)。

我覆盖 Arial 的工作配置:

~/.config/fontconfig/conf.d/00-arial-noto.conf

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <!-- Map Arial to Noto Sans instead of Liberation Sans
       (overrides /etc/fonts/conf.d/30-metric-aliases.conf) -->
  <alias binding="same">
    <family>Arial</family>
    <accept>
      <family>Noto Sans</family>
    </accept>
  </alias>
</fontconfig>
Run Code Online (Sandbox Code Playgroud)

fc-match Arial作为您的用户在控制台上检查,它应该输出“Noto Sans”(或任何您的新配置)而无需额外的努力。

在花了半天的时间弄清楚所有这些之后,包括阅读有关 fontconfig 领域勇敢战斗的冒险故事,我希望这对其他人有所帮助。