CentOS 安装中文字体

Siona

CentOS 安装中文字体

参考文章:aspose 部署到 Linux 中文乱码open in new window

1. 操作系统已有字体列表

# 查看字体列表
fc-list

# 查看中文字体列表
fc-list :lang=zh

2. 安装字体库

fc-list 命令不存在,则安装字体库

# 安装字体库
# 在 CentOS 4.x 开始用 fontconfig 来安装字体库
yum -y install fontconfig

这时在 /usr/share 目录就可以看到 fonts 和 fontconfig 目录了(之前是没有的): 安装字体库后 /usr/share 目录结构.png

3. 在字体库中添加中文字体

要点:

1、CentOS 在字体文件夹 /usr/share/fonts/ 下创建 chinese 文件夹,并修改权限 755

2、将本地的中文字体 scp 到 CentOS 的 /usr/share/fonts/chinese 文件夹下

3、配置字体文件夹到安装程序中

(1)可以直接使用 Windows 电脑的字体 Windows 电脑 Fonts 字体(86个).png

由于作者本人使用的是 Mac 电脑,起初试图使用 Mac 中的字体上传到 Linux,但是发现新的问题:Linux 预览 PDF 不乱码了,但是字体与 Mac 电脑上的效果并不完全一致。 最终,还是从 Windows 电脑上拷贝了字体。以下附上 fonts.zip 下载链接。

Windows 电脑 Fonts 字体(86个).zipopen in new window

注意:可以选择指定的字体,也可以直接将整个 Fonts 文件夹中字体直接上传。

(2)在 /usr/shared/fonts 目录下新建一个目录 chinese,并赋予权限

# 创建 chinese 目录
mkdir -p /usr/share/fonts/chinese

# 赋权 755
chmod -R 755 /usr/share/fonts/chinese

4. 安装字体索引指令

【4、5 两步骤可能有其他方法?后期参考该文章进行修改:Linux安装中文字体(已验证)open in new window

安装 ttmkfdir 来搜索目录中所有的字体信息,并汇总生成 fonts.scale 文件

# 安装 ttmkfdir
yum -y install ttmkfdir

# 执行 ttmkfdir
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir

5. 修改字体配置文件

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>
        # ------ 将创建的 chinese 目录加入到字体配置文件中 ------ #
        <dir>/usr/share/fonts/chinese</dir>
        # -------------------------------------------------- # 
        <!-- the following element will be removed in the future -->
        <dir>~/.fonts</dir>

ESC
:wq

6. 刷新字体缓存

刷新内存中的字体缓存【不用 reboot 重启】

fc-cache

7. 检验是否成功

# 查看字体列表
fc-list

# 查看中文字体列表
fc-list :lang=zh
安装完成后,中文字体列表.png
安装完成后,中文字体列表.png
Last Updated 3/25/2024, 3:44:55 PM