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

FreeBSD 系統安裝字型完整指南:Type1、TrueType 與文泉驛中文字型

編輯:關於 Linux

FreeBSD 基礎系統不預設包含大量字型,若需在 X11 環境(GNOME、KDE、Xfce 等)正常顯示中文、特殊符號或滿足圖形應用(GIMP、LibreOffice、瀏覽器)需求,需手動安裝並設定字型路徑。本文詳細說明 Type1(URW)、TrueType(微軟雅黑、宋體等)與開源中文字型(文泉驛)的安裝與設定流程。

前置需求

  • 已安裝 X11 伺服器(xorg 套件)
  • Ports 集合更新至最新(portsnap fetch update)
  • 具備 root 權限

方法一:安裝 URW Type1 標準字型集(Helvetica、Times、Courier 替代)

URW Fonts 提供高品質 PostScript Type1 字型,為 Ghostscript、TeX、印刷排版常用基礎字型。

1. 從 Ports 安裝

cd /usr/ports/x11-fonts/urwfonts
make install clean

2. 設定 X 伺服器字型路徑

編輯 /etc/X11/xorg.conf,於 Section "Files" 內新增:

FontPath "/usr/local/lib/X11/fonts/URW/"

3. 當前 Session 即時生效(無需重啟 X)

xset fp+ /usr/local/lib/X11/fonts/URW
xset fp rehash

注意: 需在 X 終端機(如 xterm、Konsole)執行,SSH 非 X 轉發環境無效。

方法二:安裝 TrueType 字型(微軟雅黑、宋體、自定義 .ttf/.ttc)

Xorg 內建 FreeType 模組支援 TrueType/OpenType 字型。

1. 載入 freetype 模組

編輯 /etc/X11/xorg.conf,於 Section "Module" 確認有:

Load "freetype"

2. 建立字型目錄並複製字型檔

mkdir -p /usr/local/lib/X11/fonts/TrueType
# 將 .ttf/.ttc 檔案複製至此
# 注意:僅支援 Unix/Windows 格式,Macintosh 格式需轉換

3. 產生 fonts.dir 索引檔

pkg install ttmkfdir  # 安裝工具
cd /usr/local/lib/X11/fonts/TrueType
ttmkfdir -o fonts.dir

4. 註冊字型路徑

編輯 /etc/X11/xorg.conf Section "Files" 新增:

FontPath "/usr/local/lib/X11/fonts/TrueType"

即時生效:

xset fp+ /usr/local/lib/X11/fonts/TrueType
xset fp rehash

5. 驗證字型可用

fc-list | grep -i "microsoft\|yahei\|sim"
# 或
xlsfonts | grep -i true

方法三:安裝文泉驛開源中文字型(推薦中文環境)

文泉驛(WenQuanYi)提供微米黑、正黑、點陣宋體等高品質開源中文字型,授權寬鬆(GPL+字型例外條款)。

1. 從 Ports 安裝

cd /usr/ports/x11-fonts/wqy
make install clean
# 約 15 分鐘編譯完成

2. 設定 X 開機自動載入

編輯 /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

3. 更新字型快取並驗證

fc-cache -fv
fc-list :lang=zh | head -20

現代字型管理:Fontconfig(推薦替代方案)

現代 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),一次設定、全平台生效。

Copyright © Windows教程網 All Rights Reserved