fontconfig 区分 sans 和 sans-serif

fontconfig 区分 sans 和 sans-serif

尝试配置 fontconfig 以使字体“Sans”映射到“Times”,将“sans-serif”映射到“Helvetica”,无论我如何尝试,Sans 和 sans-serif 都会映射到同一种字体。配置:

<alias>
  <family>sans-serif</family>
  <prefer>
    <family>Helvetica</family>
  </prefer>
</alias>
<alias>
  <family>sans</family>
  <prefer>
    <family>Times</family>
  </prefer>
</alias>

<match>
  <test name="family">
    <string>sans-serif</string>
  </test>
  <edit binding="strong" name="family" mode="append">
    <string>Helvetica</string>
  </edit>
</match>

<match>
  <test name="family">
    <string>sans</string>
  </test>
  <edit name="family" mode="append">
    <string>Times</string>
  </edit>
</match>

结果:

$ fc-match "sans"
   Times.ttc: "Times" "Regular"`
$ fc-match "sans-serif"
   Times.ttc: "Times" "Regular"   <-- want this to be Helvetica!

有趣的是,任何以“sans-”开头的字符串现在都可以与 Times 匹配:

$ fc-match "sans-ssdsdxcc"
   Times.ttc: "Times" "Regular"

而“sans serif”与其他字体匹配:

$ fc-match "sans serif"
   GoudyBookletter1911.otf: "Goudy Bookletter 1911" "Regular"

相关内容