一,fc-list所屬的rpm包
[root@blog ~]$ whereis fc-list fc-list: /usr/bin/fc-list /usr/share/man/man1/fc-list.1.gz [root@blog ~]$ rpm -qf /usr/bin/fc-list fontconfig-2.13.1-3.el8.x86_64
如果提示找不到fc-list命令,
可以用dnf來安裝:
[root@blog ~]# dnf install fontconfig
說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest
對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/
說明:作者:劉宏締 郵箱: 371125307@qq.com
二,fontconfig包命令使用舉例:
1,列出字體列表
[root@blog ~]$ fc-list
在centos8上,字體文件主要包含在兩個目錄下:
/usr/share/fonts
/usr/share/X11/fonts
2,列出所有中文字體
#:lang 指定語言
[root@blog ~]$ fc-list :lang=zh /usr/share/fonts/simhei/simhei.ttf: SimHei,黑體:style=Regular /usr/share/fonts/simsun/simsun.ttc: NSimSun,新宋體:style=Regular /usr/share/fonts/google-droid/DroidSansFallback.ttf: Droid Sans:style=Regular /usr/share/fonts/simsun/simsun.ttc: SimSun,宋體:style=Regular
列出所有英文字體:
[root@blog im4]# fc-list :lang=en
3,查看一個字體的詳情
#-v: 指定要查看詳情的字體名
[root@blog ~]$ fc-match -v "SimHei"
4,建立字體緩存信息
參數:包含字體文件的目錄,
fc-cache會掃描目錄,創建字體文件的緩存信息
[root@blog ~]# fc-cache /usr/share/fonts/simhei/
經過掃描后,新添加到目錄下的字體文件會出現在 fc-list的列表中
5,如何增加一個字體目錄?
新建目錄,把字體文件復制進去,
然后把目錄添加到字體的配置文件中
編輯字體配置文件:
[root@blog ~]# vi /etc/fonts/fonts.conf
內容
<!-- Font directory list --> <dir>/usr/share/fonts</dir> <dir>/usr/share/X11/fonts/Type1</dir> <dir>/usr/share/X11/fonts/TTF</dir> <dir>/usr/local/share/fonts</dir> <dir prefix="xdg">fonts</dir> <!-- the following element will be removed in the future --> <dir>~/.fonts</dir>
添加到這一段中即可:
例如:
<dir>/usr/local/fonts/simhei</dir>
添加完成后,執行fc-cache,
把字體添加到fc-list列表中,使系統可以使用
[root@blog ~]# fc-cache
這樣不需要重啟系統
三,例子:在centos8上新安裝一種字體
我們把一個windows中的字體文件安裝到centos8上
1,在windows機器上找到字體文件FZLTHK.TTF,上傳到centos8
2,創建目錄,復制字體文件到目錄下
[root@blog ~]# mkdir /usr/share/fzfonts [root@blog ~]# cd /usr/share/fzfonts/ [root@blog fzfonts]# cp /data/dev/think_file/html/im4/FZLTHK.TTF ./
3,編輯字體配置文件
[root@blog fzfonts]# cd /etc/fonts/ [root@blog fonts]# vi fonts.conf
增加一行
<dir>/usr/share/fzfonts</dir>
4,建立緩存信息
[root@blog fonts]# fc-cache /usr/share/fzfonts/
5,用fc-list檢查字體是否可用
[root@blog fonts]# fc-list :lang=zh /usr/share/fonts/simhei/simhei.ttf: SimHei,黑體:style=Regular /usr/share/fonts/simsun/simsun.ttc: NSimSun,新宋體:style=Regular /usr/share/fzfonts/FZLTHK.TTF: FZLanTingHei\-R\-GBK,方正蘭亭黑_GBK:style=Regular /usr/share/fonts/simsun/simsun.ttc: SimSun,宋體:style=Regular
也可用fc-match查看詳情:
[root@blog fonts]# fc-match -v "FZLanTingHei\-R\-GBK"
6,檢查imagemagick是否可以使用此字體?
[root@blog fonts]# convert -list font | grep FZ
可以使用
四,查看centos的版本
[root@blog ~]# cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)