Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 中文字體安裝全攻略:從停用 xfs 到字體路徑配置與驗證

編輯:Linux 教學

核心衝突:xfs 字體服務會自動覆蓋手動配置

Linux 圖形系統透過 XFS (X Font Server) 管理字體,**會自動更新 fonts.dir 覆蓋手工修改**。安裝中文字體前,**必須先停用 xfs 服務**。

步驟一:停用 xfs 服務


# 圖形介面
setup → 服務 → 取消 xfs 隨系統啟動

# 或命令行 (Systemd 系統)
systemctl disable xfs
systemctl stop xfs

# SysVinit 系統
chkconfig xfs off
service xfs stop

步驟二:部署字體檔案並生成索引

  1. 推薦字體:**SimSun (宋體) `simsun.ttf`**,公認中文顯示效果最佳
  2. 複製至字體目錄:cp simsun.ttf /usr/share/fonts/default/TrueType/
  3. 進入目錄生成索引:cd /usr/share/fonts/default/TrueType; ttmkfdir > fonts.dir
  4. 編輯 fonts.dir,在 simsun.ttf -misc-SimSun-medium-r-normal--0-0-0-0-p-0-ascii-0 後追加兩行編碼映射:
    
    simsun.ttf -misc-SimSun-medium-r-normal--0-0-0-0-p-0-gb2312.1980-0
    simsun.ttf -misc-SimSun-medium-r-normal--0-0-0-0-p-0-gbk-0
    
  5. 修正首行字體計數數字 (原數字 +2)
  6. 複製索引:cp fonts.dir fonts.scale

步驟三:配置 X 伺服器字體路徑與模組

編輯 /etc/X11/XF86Config-4 (或 xorg.conf):


Section "Files"
    # FontPath "unix/:7100"   # 註解掉 xfs 網路字體路徑
    FontPath "/usr/X11R6/lib/X11/fonts/misc:unscaled"
    FontPath "/usr/X11R6/lib/X11/fonts/75dpi:unscaled"
    FontPath "/usr/X11R6/lib/X11/fonts/misc"
    FontPath "/usr/X11R6/lib/X11/fonts/Type1"
    FontPath "/usr/X11R6/lib/X11/fonts/Speedo"
    FontPath "/usr/X11R6/lib/X11/fonts/75dpi"
    FontPath "/usr/share/fonts/default/TrueType"  # 新增 TrueType 字體路徑
EndSection

Section "Module"
    ...
    Load "xtt"      # 載入 TrueType 字體模組 (FreeType)
    ...
EndSection

步驟四:重啟驗證

  1. 重啟 X 伺服器 (或重啟系統)
  2. 進入桌面控制中心 → 字體設定 → 選擇 SimSun
  3. 打開終端/編輯器測試中文顯示

現代系統補充 (Fontconfig 時代)

現代發行版 (Fedora 20+、Ubuntu 14.04+、CentOS 7+) 採用 **Fontconfig** 取代 XFS:


# 1. 複製字體至系統/用戶目錄
cp simsun.ttf /usr/share/fonts/          # 系統級 (需 root)
# 或
mkdir -p ~/.local/share/fonts
cp simsun.ttf ~/.local/share/fonts/      # 用戶級

# 2. 重建快取
fc-cache -fv

# 3. 驗證
fc-list :lang=zh | grep -i simsun
fc-match sans:lang=zh

Fontconfig 自動掃描目錄、解析 TTF/OTF、按語言匹配,**無需手動編輯 fonts.dir、無需停用服務、無需改 X 配置**,極大簡化流程。

常見問題排查

  • 字體不顯示:確認 fc-list 可見、fc-cache 無錯誤、重啟應用程式
  • 字體模糊:調整 /etc/fonts/conf.d/10-antialias.conf、10-hinting.conf
  • 缺字:補裝 wqy-zenhei、noto-fonts-cjk 等開源完整字體
Copyright © Windows教程網 All Rights Reserved