在Centos7.X上安装中文字体及相关配置

在Centos7.X上安装中文字体及相关配置

前言

Linux字体文件放在/usr/share/font/,只要将字体文件拷贝到这里就可以了。
这里示例安装Windows的所有字体。
1,新建路径存放字体库:/usr/share/fonts/
2,进入Windows下> 的字体库目录c:\windows\Fonts。复制字体库到创建好的字体库目录/usr/share/fonts/。
3,进入字体库目录,刷新系统即刻生效,输入命令:mkfontscale ; mkfontdir ; fc-cache。

一、查看系统字体

在开始安装之前,我们先查看系统中已经安装的字体。
要查看系统中已经安装的字体,我们可以使用fc-list命令进行查看。如果系统中没有该命令的话,我们需要先安装相关的软件包。
查看系统类型:cat /etc/issue
在centos上,使用如下命令进行安装:
yum install -y fontconfig mkfontscale
在ubuntu上,使用如下命令进行安装:
sudo apt-get -y install fontconfig xfonts-utils
查看系统默认字体:fc-list
如果要查看系统中已经安装的中文字体,我们可以使用如下命令:fc-list :lang=zh
根据提示安装相关的依赖包

yum install -y libX11 libXext libXrender libjpeg xorg-x11-fonts-75dpi xorg-x11-fonts-Type1

二、安装字体

上传字体文件到/usr/share/fonts/chinese
然后执行字体缓存更新
在这里插入图片描述

[root@shigj fonts]# cd /usr/share/fonts/chinese
[root@shigj fonts]# mkfontscale
[root@shigj fonts]# mkfontdir
[root@shigj fonts]# fc-cache -fv 
/usr/share/fonts: caching, new cache contents: 2 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/var/cache/fontconfig: cleaning cache directory
/root/.fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded
fc-cache -fv

三、检测linux上安装的中文字体

[root@webadmin01 chinese]# fc-list :lang=zh-cn
/usr/share/fonts/chinese/youyuan.TTF: YouYuan:style=Regular
/usr/share/fonts/chinese/Songti.ttc: STSong:style=Regular,Normaali
/usr/share/fonts/chinese/Songti.ttc: Songti TC,宋体\-,宋體\-繁:style=Regular,常规体,標準體
/usr/share/fonts/chinese/Songti.ttc: Songti SC,宋体\-,宋體\-簡:style=Regular,常规体,標準體
/usr/share/fonts/chinese/MSYH.TTC: Microsoft YaHei:style=Normal
/usr/share/fonts/chinese/SIMSUN.TTC: SimSun,宋体:style=Regular,常规
/usr/share/fonts/chinese/Songti.ttc: Songti SC,宋体\-,宋體\-簡:style=Light,细体,細體
/usr/share/fonts/chinese/MSYHBD.TTC: Microsoft YaHei:style=Έντονα
/usr/share/fonts/chinese/STKAITI.TTF: STKaiti:style=Regular
/usr/share/fonts/chinese/Songti.ttc: Songti TC,宋体\-,宋體\-繁:style=Light,细体,細體
/usr/share/fonts/chinese/MSYH.TTC: Microsoft YaHei UI:style=Normal
/usr/share/fonts/chinese/隶书.ttf: LiSu:style=Regular
/usr/share/fonts/chinese/MSYHBD.TTC: Microsoft YaHei UI:style=Έντονα
/usr/share/fonts/chinese/STFANGSO.TTF: STFangsong:style=Regular
/usr/share/fonts/chinese/SIMSUN.TTC: NSimSun,新宋体:style=Regular,常规
/usr/share/fonts/chinese/MSYHL.TTC: Microsoft YaHei UI,Microsoft YaHei UI Light:style=Light,Regular
/usr/share/fonts/chinese/Songti.ttc: Songti SC:style=Black
/usr/share/fonts/chinese/SIMKAI.TTF: KaiTi:style=Regular,Normaali
/usr/share/fonts/chinese/Songti.ttc: Songti SC,宋体\-,宋體\-簡:style=Bold,粗体,粗體
/usr/share/fonts/chinese/Songti.ttc: Songti TC,宋体\-,宋體\-繁:style=Bold,粗体,粗體
/usr/share/fonts/chinese/STSONG.TTF: STSong:style=Regular
/usr/share/fonts/chinese/仿宋_GB2312.ttf: FangSong_GB2312:style=Regular
/usr/share/fonts/chinese/SIMHEI.TTF: SimHei:style=Normal
/usr/share/fonts/chinese/楷体_GB2312.ttf: KaiTi_GB2312:style=Regular
/usr/share/fonts/chinese/SIMFANG.TTF: FangSong:style=Regular,Normaali
/usr/share/fonts/chinese/MSYHL.TTC: Microsoft YaHei,Microsoft YaHei Light:style=Light,Regular

检查能否解析中文字体名

for family in 微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆; do   echo -n "$family: ";   fc-match "$family"; done

发现不能正常解析

[root@webadmin01 chinese]# for family in 微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆; do   echo -n "$family: ";   fc-match "$family"; done
微软雅黑: DejaVuSans.ttf: "DejaVu Sans" "Book"
宋体: SIMSUN.TTC: "SimSun" "Regular"
黑体: DejaVuSans.ttf: "DejaVu Sans" "Book"
仿宋: DejaVuSans.ttf: "DejaVu Sans" "Book"
仿宋_GB2312: DejaVuSans.ttf: "DejaVu Sans" "Book"
楷体: DejaVuSans.ttf: "DejaVu Sans" "Book"
楷体_GB2312: DejaVuSans.ttf: "DejaVu Sans" "Book"
隶书: DejaVuSans.ttf: "DejaVu Sans" "Book"
幼圆: DejaVuSans.ttf: "DejaVu Sans" "Book"

四、配置别名

vim /etc/fonts/fonts.conf
在配置节之间增加以下match标签,增加中文字体解析规则。

  <!-- 为微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆;配置别名 -->
  <match>
    <test name="family"><string>微软雅黑</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>Microsoft YaHei</string>
    </edit>
  </match>
  <match>
    <test name="family"><string>宋体</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>SimSun</string>
    </edit>
  </match>
  <match>
    <test name="family"><string>黑体</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>SimHei</string>
    </edit>
  </match>
  <match>
    <test name="family"><string>仿宋</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>FangSong</string>
    </edit>
  </match>
   <match>
    <test name="family"><string>仿宋_GB2312</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>FangSong_GB2312</string>
    </edit>
  </match>
   <match>
    <test name="family"><string>楷体</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>KaiTi</string>
    </edit>
  </match>
  <match>
    <test name="family"><string>楷体_GB2312</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>KaiTi_GB2312</string>
    </edit>
  </match>
  <match>
    <test name="family"><string>隶书</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>LiSu</string>
    </edit>
  </match>
  <match>
    <test name="family"><string>幼圆</string></test>
    <edit name="family" mode="assign" binding="strong">
      <string>YouYuan</string>
    </edit>
  </match>

配置后,再次检查解析情况

[root@webadmin01 chinese]# for family in 微软雅黑 宋体 黑体 仿宋 仿宋_GB2312 楷体 楷体_GB2312 隶书 幼圆; do   echo -n "$family: ";   fc-match "$family"; done
微软雅黑: MSYH.TTC: "Microsoft YaHei" "Normal"
宋体: SIMSUN.TTC: "SimSun" "Regular"
黑体: SIMHEI.TTF: "SimHei" "Normal"
仿宋: SIMFANG.TTF: "FangSong" "Regular"
仿宋_GB2312: 仿宋_GB2312.ttf: "FangSong_GB2312" "Regular"
楷体: SIMKAI.TTF: "KaiTi" "Regular"
楷体_GB2312: 楷体_GB2312.ttf: "KaiTi_GB2312" "Regular"
隶书: 隶书.ttf: "LiSu" "Regular"
幼圆: youyuan.TTF: "YouYuan" "Regular"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值