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 xlsfonts 命令參數詳解:列出 X Server 可用字體

編輯:關於 Linux

xlsfonts 是 X Window 系統工具,用於列出 X Server 當前可用的字體名稱及屬性。雖然現代桌面環境多使用 Fontconfig/Freetype 管理字體,但 xlsfonts 在排查 X 字體問題、配置舊版 X 應用、編寫 X 资源文件時仍有價值。本文完整解析所有參數與實用示例。

xlsfonts 輸出示例

命令語法

xlsfonts [-1Clmou] [-display host:display] [-fn pattern] [-ll] [-lll] [-n columns] [-w width]

參數詳細說明

參數長選項功能描述
-1單列模式輸出,每行一個字體名稱,便於腳本處理
-C多列模式輸出(默認),自動適配終端寬度
-display host:display指定目標 X Server(如 :0、192.168.1.100:1),默認 $DISPLAY
-fn pattern模式匹配過濾字體(支援 * ? 通配符),如 -fn '*helvetica*'
-l顯示字體屬性:Foundry、Family、Weight、Slant、Setwidth、AddStyle、PixelSize、PointSize、Resolution、Spacing、AverageWidth、Charset、Encoding
-ll顯示更詳細屬性(含 FontAscent、FontDescent、MaxBounds 等)
-lll顯示最完整屬性(含每個字符的度量信息),輸出極大
-m配合 -l 顯示字體像素大小範圍
-n columns指定多列模式下的列數
-o以 OpenFont 格式輸出(XLFD 名稱)
-u不排序,按 X Server 返回順序輸出
-w width指定每列最大字符寬度

實用示例

1. 列出所有字體(單列,便於 grep)

xlsfonts -1 | head -20
# -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1
# -misc-fixed-bold-r-normal--13-120-75-75-c-70-iso8859-1
# ...

2. 搜索包含特定關鍵字的字體

# 查找所有 DejaVu 字體
xlsfonts -fn '*dejavu*' -1

# 查找所有等寬字體
xlsfonts -fn '*mono*' -1
xlsfonts -fn '*fixed*' -1

3. 查看字體詳細屬性(排查渲染問題)

xlsfonts -fn '-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1' -l
# 輸出:
# -misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1
#   FOUNDRY: misc
#   FAMILY_NAME: fixed
#   WEIGHT_NAME: medium
#   SLANT: r
#   SETWIDTH_NAME: normal
#   ADD_STYLE_NAME: ""
#   PIXEL_SIZE: 13
#   POINT_SIZE: 120
#   RESOLUTION_X: 75
#   RESOLUTION_Y: 75
#   SPACING: c
#   AVERAGE_WIDTH: 70
#   CHARSET_REGISTRY: iso8859
#   CHARSET_ENCODING: 1

4. 指定遠程 X Server 列出字體

xlsfonts -display 192.168.1.50:0 -1 | wc -l

XLFD 字體命名規範解析

標準 XLFD 格式(14 個字段,用 - 分隔):

-Foundry-Family-Weight-Slant-Setwidth-AddStyle-PixelSize-PointSize-ResX-ResY-Spacing-AvgWidth-CharsetRegistry-CharsetEncoding
字段含義常見值
Foundry字體廠商misc, adobe, b&h, cronyx
Family字體家族fixed, helvetica, times, courier, dejavu
Weight粗細medium, bold, light
Slant傾斜r (roman), i (italic), o (oblique)
Setwidth字寬normal, condensed, extended
AddStyle附加風格通常為空
PixelSize像素高度12, 13, 14...
PointSize點大小 (1/72 inch)120 = 12pt
ResX/ResY水平/垂直分辨率75, 100
Spacing間距類型p (比例), m (等寬), c (字符單元)
AvgWidth平均寬度 (1/10 像素)80 = 8.0 像素
CharsetRegistry/Encoding字符集註冊/編碼iso8859-1, iso10646-1 (Unicode)

現代替代方案:Fontconfig 工具鏈

現代 Linux 桌面(GNOME、KDE、Xfce)使用 Fontconfig 管理字體,推薦工具:

命令用途
fc-list列出所有 Fontconfig 可見字體(含 TTF/OTF/Type1),支援 :family=DejaVu 過濾
fc-match查找匹配模式的最佳字體(如 fc-match 'sans:bold')
fc-query查詢字體文件詳細屬性
fc-cache -fv重建字體緩存(安裝新字體後必跑)

常見問題

現象原因解決
xlsfonts: command not found未安裝 xorg-x11-apps / x11-appsyum install xorg-x11-apps / apt install x11-apps
列出字體為空X Server 未運行、$DISPLAY 未設置、字體路徑未配置啟動 X、export DISPLAY=:0、檢查 /etc/X11/fontpath.d/
舊版 X 應用找不到字體應用使用 XLFD 直接請求,Fontconfig 未暴露xset +fp /usr/share/fonts/... 添加字體路徑,xset fp rehash

掌握 xlsfonts 能幫助理解 X 字體機制,排查經典 X 應用字體缺失問題;日常桌面開發請優先使用 Fontconfig 工具鏈。

Copyright © Windows教程網 All Rights Reserved