Linux CentOS 7 安装字体库 & 中文字体 & 设置中文

解决的问题?

  • 最近有一个需求是在 Linux 上使用 phantomjs 对指定网页进行截图后,把截图发送到钉钉消息群。但是在过程中遇到了截图无法正确显示中文的问题,查询各种资料都未解决。在快要走火入魔将要放弃的时候,突然背后传来一个声音“看看Linux的中文包装没有”。瞬间感觉世界都出现了一丝阳光,马上在网上搜索了相关资料,觉得可能就是这个问题导致的,立马按照网上的指导一顿操作,what fuck 竟然搞定了!
  • 所以为了记录这次的经历,遂提笔写下本篇文章以作记录,感谢那名点拔我的高人。

葵花宝典

第一式:检查系统是否有字体库

  • 查看字体库列表
fc-list
  • 如果没有安装字体库,使用下面的命令安装字体库
yum -y install fontconfig

第二式:安装中文字体

  • 首先在/usr/shared/fonts 目录下新建一个目录 chinese。
mkdir /usr/shared/fonts/chinese
  • 上传字体文件到 chinese 文件夹中。
<!-- 悄悄的说:这2个文件可以在Windows系统的C:fonts文件夹中找到. -->

simsun.ttc
simsunb.ttf
  • 修改 chinese 目录的权限
chmod -R 755 /usr/share/fonts/chinese
  • 安装 ttmkfdir 来搜索目录中所有的字体信息,并汇总生成 fonts.scale 文件。
yum -y install ttmkfdir

ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
  • 修改字体配置文件,添加 chinese 文件夹的地址
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>

    <!-- 添加chinese文件夹的地址 -->
    <dir>/usr/share/fonts/chinese</dir>

    <dir prefix="xdg">fonts</dir>
    <!-- the following element will be removed in the future -->
    <dir>~/.fonts</dir>

  • 清除字体缓存
fc-cache

OKOK,接下来就是见证奇迹的时刻了。


感谢无名前辈留下的经验

原文地址:https://www.cnblogs.com/jasontang369/p/13904801.html