Firefox 在 Linux 下頻繁出現中文亂碼,核心原因是字體回退機制將無中文字符的西文字體優先匹配給 sans-serif/serif 等通用族系。本文提供從瀏覽器設定到系統字體配置的分級修復方案。
about:preferences → 語言與外觀 → 字體與顏色 → 進階問題核心在 /etc/fonts/conf.d/49-sansserif.conf,此檔案定義 sans-serif/serif/monospace 的字體回退順序,預設綁定西文字體導致中文缺字時落回錯誤字形。
sudo mv /etc/fonts/conf.d/49-sansserif.conf /etc/fonts/conf.d/49-sansserif.conf.bak
sudo cp /etc/fonts/conf.d/49-sansserif.conf /etc/fonts/conf.d/49-sansserif.conf.bak
sudo vim /etc/fonts/conf.d/49-sansserif.conf
修改內容,將中文字體置於優先位置:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="pattern">
<test qual="all" name="family" compare="not_eq">
<string>sans-serif</string>
</test>
<test qual="all" name="family" compare="not_eq">
<string>serif</string>
</test>
<test qual="all" name="family" compare="not_eq">
<string>monospace</string>
</test>
<edit name="family" mode="append_last">
<string>Noto Sans CJK TC</string> <!-- 替換為你系統安裝的中文字體 -->
</edit>
</match>
</fontconfig>
# 重建字體快取
fc-cache -fv
# 重啟 Firefox (或重啟 X Session)
sans-serif/serif/monospace 是虛擬字體族系,不對應實體字體檔/etc/fonts/conf.d/ 下配置檔(按檔名排序優先級)將實體字體綁定到虛擬族系font-family: sans-serif 時,首選西文字體 → 無中文字符 → 回退機制失效或落回錯誤字形 → 亂碼49- 前綴優先級低於 48- 等系統基礎配置,修改後需 fc-cache 重建快取fc-list :lang=zh~/.config/fontconfig/fonts.conf (優先級更高,不需 root)
終極建議:若無法解決,考慮使用對中文支援更好的國產瀏覽器或 Chromium 內核瀏覽器(內建更完善的字體回退)。