fontconfig
fontconfig會優先讀 $XDG_CONFIG_HOME/fontconfig/fonts.conf 的配置,因此自定義配置優先級更高。沒有才會讀 /etc/fonts/fonts.conf
之前使用texlive將textlive的字體做為系統字體后,系統的字體顯示就變的混亂了,chrome網頁中同一段文本既有黑體,又有宋體,因此需要重新設置字體配置。
fc-match -a <字體名> 查詢字體名對應的字體文件,會出來一大堆,一般會用第一個。目前猜測是如果第一個中沒有所要字形,就會順序用第二個,依次類推,直到字形被渲染。應該就是網頁中同一段部分字體是楷體,部分是黑體的原因。
一般重點是sans-serif,serif和monospace三類字體,自己寫fonts.conf 把系統中已有字體加到匹配列表最前面。
修改完fonts.conf后,需要運行 fc-cache -fv
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font">
<edit name="embeddedbitmap" mode="assign">
<bool>false</bool>
</edit>
</match>
<match>
<test qual="any" name="family">
<string>serif</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>Source Han Serif SC</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>sans-serif</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>Source Han Sans CN</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>monospace</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>Source Han Mono SC</string>
</edit>
</match>
<match>
<test name="lang" compare="contains">
<string>zh</string>
</test>
<test name="family">
<string>serif</string>
</test>
<edit name="family" mode="prepend">
<string>Source Han Sans CN</string>
</edit>
</match>
<match>
<test name="lang" compare="contains">
<string>zh</string>
</test>
<test name="family">
<string>sans-serif</string>
</test>
<edit name="family" mode="prepend">
<string>Source Han Sans CN</string>
</edit>
</match>
<match>
<test name="lang" compare="contains">
<string>zh</string>
</test>
<test name="family">
<string>monospace</string>
</test>
<edit name="family" mode="prepend">
<string>Source Han Mono SC</string>
</edit>
</match>
<!--WenQuanYi Zen Hei -> WenQuanYi Micro Hei -->
<match target="pattern">
<test qual="any" name="family">
<string>WenQuanYi Zen Hei</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>WenQuanYi Micro Hei</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>WenQuanYi Zen Hei Lite</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>WenQuanYi Micro Hei Lite</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>WenQuanYi Zen Hei Mono</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>WenQuanYi Micro Hei Mono</string>
</edit>
</match>
<!--Microsoft YaHei, SimHei, SimSun -> WenQuanYi Micro Hei -->
<match target="pattern">
<test qual="any" name="family">
<string>Microsoft YaHei</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>WenQuanYi Micro Hei</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>SimHei</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>WenQuanYi Micro Hei</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>SimSun</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>WenQuanYi Micro Hei</string>
</edit>
</match>
<match target="pattern">
<test qual="any" name="family">
<string>SimSun-18030</string>
</test>
<edit name="family" mode="assign" binding="same">
<string>WenQuanYi Micro Hei</string>
</edit>
</match>
</fontconfig>
