FreeBSD 基礎系統不預設包含大量字型,若需在 X11 環境(GNOME、KDE、Xfce 等)正常顯示中文、特殊符號或滿足圖形應用(GIMP、LibreOffice、瀏覽器)需求,需手動安裝並設定字型路徑。本文詳細說明 Type1(URW)、TrueType(微軟雅黑、宋體等)與開源中文字型(文泉驛)的安裝與設定流程。
xorg 套件)portsnap fetch update)URW Fonts 提供高品質 PostScript Type1 字型,為 Ghostscript、TeX、印刷排版常用基礎字型。
cd /usr/ports/x11-fonts/urwfonts
make install clean
編輯 /etc/X11/xorg.conf,於 Section "Files" 內新增:
FontPath "/usr/local/lib/X11/fonts/URW/"
xset fp+ /usr/local/lib/X11/fonts/URW
xset fp rehash
注意: 需在 X 終端機(如 xterm、Konsole)執行,SSH 非 X 轉發環境無效。
Xorg 內建 FreeType 模組支援 TrueType/OpenType 字型。
編輯 /etc/X11/xorg.conf,於 Section "Module" 確認有:
Load "freetype"
mkdir -p /usr/local/lib/X11/fonts/TrueType
# 將 .ttf/.ttc 檔案複製至此
# 注意:僅支援 Unix/Windows 格式,Macintosh 格式需轉換
pkg install ttmkfdir # 安裝工具
cd /usr/local/lib/X11/fonts/TrueType
ttmkfdir -o fonts.dir
編輯 /etc/X11/xorg.conf Section "Files" 新增:
FontPath "/usr/local/lib/X11/fonts/TrueType"
即時生效:
xset fp+ /usr/local/lib/X11/fonts/TrueType
xset fp rehash
fc-list | grep -i "microsoft\|yahei\|sim"
# 或
xlsfonts | grep -i true
文泉驛(WenQuanYi)提供微米黑、正黑、點陣宋體等高品質開源中文字型,授權寬鬆(GPL+字型例外條款)。
cd /usr/ports/x11-fonts/wqy
make install clean
# 約 15 分鐘編譯完成
編輯 /etc/X11/xorg.conf,於 Section "Files" 新增:
FontPath "/usr/local/lib/X11/fonts/wqy"
完整 Section "Files" 範例:
Section "Files"
ModulePath "/usr/local/lib/xorg/modules"
FontPath "/usr/local/lib/X11/fonts/misc/"
FontPath "/usr/local/lib/X11/fonts/TTF/"
FontPath "/usr/local/lib/X11/fonts/OTF/"
FontPath "/usr/local/lib/X11/fonts/Type1/"
FontPath "/usr/local/lib/X11/fonts/100dpi/"
FontPath "/usr/local/lib/X11/fonts/75dpi/"
FontPath "/usr/local/lib/X11/fonts/wqy"
EndSection
fc-cache -fv
fc-list :lang=zh | head -20
現代 X11 應用(GTK3/Qt5 以降)主要透過 Fontconfig 而非 X 核心字型路徑尋找字型。建議採用下列方式:
# 系統層級安裝
mkdir -p /usr/local/share/fonts/truetype
cp *.ttf /usr/local/share/fonts/truetype/
fc-cache -fv /usr/local/share/fonts/truetype
# 使用者層級安裝
mkdir -p ~/.local/share/fonts
cp *.ttf ~/.local/share/fonts/
fc-cache -fv ~/.local/share/fonts
此法無需修改 xorg.conf,相容 Wayland、Flatpak、Snap 等新架構。
| 現象 | 原因與解決 |
|---|---|
| 中文顯示方框/亂碼 | 缺少中文字型,安裝 wqy 或 Noto Sans CJK |
| xset fp+ 報 "BadFont" | 路徑錯誤或 fonts.dir 缺失,重跑 ttmkfdir |
| GIMP/Inkscape 找不到新字型 | 重啟應用程式,或執行 fc-cache -fv |
| Ports 編譯失敗 | 更新 ports tree,檢查 /usr/ports/UPDATING |
FreeBSD 字型安裝核心步驟:安裝字型檔 → 產生索引 → 註冊路徑 → 更新快取。傳統 X 核心字型路徑(xorg.conf + xset)適用於舊版應用;現代環境建議直接使用 Fontconfig(/usr/local/share/fonts 或 ~/.local/share/fonts + fc-cache),一次設定、全平台生效。