当我在 CSS 中指定“Liberation Mono”时,为什么会选择“DejaVu Serif”?

Lon*_*ner 5 css firefox fonts iceweasel

我在带有 XFCE4 桌面的 Debian 系统上使用 Iceweasel 浏览器(Firefox 衍生版本)。

我没有在 ~/.config/fontconfig/fonts.conf 中定义任何自定义字体替换。

这是 fc-match 目前告诉我的。

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

因此,我希望当我有 HTML 时,使用“Liberation Mono”字体应该提供与使用“Courier”相同的结果。但从下面的屏幕截图中可以看出,情况并非如此(JSFiddle: http: //jsfiddle.net/8L3rmyxn/)。

在此输入图像描述

我单击“检查元素”并找到实际使用的字体。

对于CSS中使用“Liberation Mono”的文本,浏览器使用“DejaVu Serif”代替,这与fc-math的输出不一致。

对于 CSS 中使用“Courier”的文本,浏览器使用“Nimbus Mono L”,这与 fc-match 的输出一致。

对于 CSS 中使用“monospace”的文本,浏览器使用“DejaVu Sans Mono”,这再次与 fc-match 的输出一致。

问题

为什么在“Liberation Mono”字体的情况下,浏览器不使用“Nimbus Mono L”而是使用“DejaVu Serif”字体?

已知分辨率

请注意,我知道解决此问题的方法。如果我在 ~/.config/fontconfig/fonts.conf 中明确定义“Liberation Mono”的别名,那么我会得到所需的结果,即“Liberation Mono”字体中的文本和“Courier”字体中的文本看起来相似。

lone@debian:~$ cat ~/.config/fontconfig/fonts.conf 
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <alias>
        <family>Liberation Mono</family>
        <prefer><family>Nimbus Mono L</family></prefer>
    </alias>
</fontconfig>
lone@debian:~$ fc-match "Liberation Mono"
n022003l.pfb: "Nimbus Mono L" "Regular
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

再次提问

但我的问题仍然存在。为什么在 fonts.conf 中没有这个显式别名,当我在 CSS 中指定“Liberation Mono”字体时,浏览器不使用“Nimbus Mono L”而是使用“DejaVu Serif”字体,即使输出fc-match "Liberation Mono"相同不管我是否在 fonts.conf 中定义了别名?

Mil*_*uff 1

默认情况下,Firefox 只允许通过 fontconfig 进行最多 3 次替换。

您可以gfx.font_rendering.fontconfig.max_generic_substitutions在 about:config 中设置来增加此限制。允许的最高值为 127。

  • 根据[此问题](https://bugzilla.mozilla.org/show_bug.cgi?id=1243226),此限制已到位,因为*“包含大量额外字体会减慢字体回退的速度,因此将人为的限制是最好的事情”*。因此,根据系统速度等因素,将此限制设置为 127 *可能*不是最好的主意。 (2认同)