(2024.6.30)
系統字體保存路徑在/usr/share/fonts下,如果此目錄下缺少字體,則使用其他可視化api(如Python的pygame庫)的默認配置時可能會出現亂碼問題。
往Ubuntu中添加字體的方法
方法一:手動添加字體文件
- 下載字體文件:從互聯網下載你需要的字體文件(例如,.ttf 或 .otf 文件)。
- 復制字體文件到 /usr/local/share/fonts:將下載的字體文件復制到 /usr/local/share/fonts 目錄。
sudo cp /path/to/downloaded/font.ttf /usr/local/share/fonts/
- 更新字體緩存:添加字體后,運行 fc-cache 命令來更新字體緩存。
sudo fc-cache -fv
方法二:通過系統包管理器安裝字體
Ubuntu 提供了多種字體包,可以通過 apt 包管理器安裝。以下是一些常見的字體包:
- 安裝 Microsoft 字體:
sudo apt update
sudo apt install ttf-mscorefonts-installer
- 安裝 Google 字體:
sudo apt update
sudo apt install fonts-noto
- 安裝其他常用字體:
sudo apt update
sudo apt install fonts-dejavu
sudo apt install fonts-liberation
sudo apt install fonts-ubuntu
安裝這些字體包后,系統會自動將字體文件添加到合適的目錄(通常是 /usr/share/fonts 或 /usr/local/share/fonts),并更新字體緩存。
方法三:使用 fontconfig 來查找現有系統字體
即使 /usr/local/share/fonts 目錄中沒有字體文件,系統其他位置仍然可能有字體文件。你可以使用 fontconfig 來查找這些字體。
fc-list
此命令會列出系統中所有可用的字體及其路徑。你可以使用 grep 來查找特定的字體。例如:
fc-list | grep -i "arial"