查看系统字体安装位置

fc-cache -v

这会列出所有被查找的字体文件夹,输出类似:

/usr/share/fonts: skipping, existing cache is valid: 0 fonts, 6 dirs
/usr/share/fonts/X11: skipping, existing cache is valid: 0 fonts, 4 dirs
/usr/share/fonts/X11/Type1: skipping, existing cache is valid: 8 fonts, 0 dirs
/usr/share/fonts/X11/encodings: skipping, existing cache is valid: 0 fonts, 1 dirs
…………
/usr/share/fonts/type1: skipping, existing cache is valid: 0 fonts, 1 dirs
/usr/share/fonts/type1/urw-base35: skipping, existing cache is valid: 35 fonts, 0 dirs
/usr/local/share/fonts: skipping, existing cache is valid: 0 fonts, 0 dirs
/home/jetson/.local/share/fonts: skipping, no such directory
/home/jetson/.fonts: skipping, no such directory
/usr/share/fonts/X11: skipping, looped directory detected
/usr/share/fonts/cMap: skipping, looped directory detected
/usr/share/fonts/cmap: skipping, looped directory detected
/usr/share/fonts/opentype: skipping, looped directory detected
…………
/usr/share/fonts/truetype/ubuntu: skipping, looped directory detected
/usr/share/fonts/type1/urw-base35: skipping, looped directory detected
/usr/share/fonts/X11/encodings/large: skipping, looped directory detected
/var/cache/fontconfig: not cleaning unwritable cache directory
/home/jetson/.cache/fontconfig: cleaning cache directory
/home/jetson/.fontconfig: not cleaning non-existent cache directory

安装字体

如果你想要将字体安装给当前用户,就将字体放到~/.fonts目录下(或其中的子文件夹),若要安装到系统供所有用户使用,可以放到/usr/share/fonts下(或其中的子文件夹),例如:

mkdir ~/.fonts      # 默认情况下没有此文件夹,需要创建
cp *.ttf ~/.fonts/  # 将当前文件夹内所有ttf文件复制到字体目录

之后再刷新字体缓存:

fc-cache -v -f | grep "/.fonts"  # 这里加grep是为了筛选不必要的信息,只看刚刚添加字体的文件夹的信息

安装正确的话,输出如下:

jetson@ubuntu:~/iTrashGUI/assets/fonts$ fc-cache -v -f | grep "/.fonts"
/home/jetson/.fonts: caching, new cache contents: 25 fonts, 0 dirs

使用以下命令可以检查特定字体是否正确安装:

fc-list | grep "字体名称"