Centos7安装字体全过程:
1、查看字体库[root@nb003 softs]# fc-list -bash: fc-list: command not found2、安装字体库
上述 fc-list 发现没有安装字体库,故安装。
yum -y install fontconfig
[root@nb003 softs]# yum -y install fontconfig Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 kubernetes | 1.4 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/3): epel/x86_64/updateinfo | 1.1 MB 00:00:00 (2/3): epel/x86_64/primary_db | 7.0 MB 00:00:00 (3/3): updates/7/x86_64/primary_db | 14 MB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package fontconfig.x86_64 0:2.13.0-4.3.el7 will be installed --> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.0-4.3.el7.x86_64 --> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.0-4.3.el7.x86_64 --> Running transaction check ---> Package dejavu-sans-fonts.noarch 0:2.33-6.el7 will be installed --> Processing Dependency: dejavu-fonts-common = 2.33-6.el7 for package: dejavu-sans-fonts-2.33-6.el7.noarch ---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed --> Running transaction check ---> Package dejavu-fonts-common.noarch 0:2.33-6.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================================================================================================================= Installing: fontconfig x86_64 2.13.0-4.3.el7 base 254 k Installing for dependencies: dejavu-fonts-common noarch 2.33-6.el7 base 64 k dejavu-sans-fonts noarch 2.33-6.el7 base 1.4 M fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k Transaction Summary ======================================================================================================================================================================================================================================================================= Install 1 Package (+3 Dependent packages) Total download size: 1.7 M Installed size: 5.9 M Downloading packages: (1/4): dejavu-fonts-common-2.33-6.el7.noarch.rpm | 64 kB 00:00:00 (2/4): fontconfig-2.13.0-4.3.el7.x86_64.rpm | 254 kB 00:00:00 (3/4): fontpackages-filesystem-1.44-8.el7.noarch.rpm | 9.9 kB 00:00:00 (4/4): dejavu-sans-fonts-2.33-6.el7.noarch.rpm | 1.4 MB 00:00:00 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 6.9 MB/s | 1.7 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : fontpackages-filesystem-1.44-8.el7.noarch 1/4 Installing : dejavu-fonts-common-2.33-6.el7.noarch 2/4 Installing : dejavu-sans-fonts-2.33-6.el7.noarch 3/4 Installing : fontconfig-2.13.0-4.3.el7.x86_64 4/4 Verifying : fontpackages-filesystem-1.44-8.el7.noarch 1/4 Verifying : dejavu-fonts-common-2.33-6.el7.noarch 2/4 Verifying : fontconfig-2.13.0-4.3.el7.x86_64 3/4 Verifying : dejavu-sans-fonts-2.33-6.el7.noarch 4/4 Installed: fontconfig.x86_64 0:2.13.0-4.3.el7 Dependency Installed: dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 Complete!
安装后,在/usr/share目录可以查看到fonts 和 fontconfig目录
将中文字体,如msyhbd.ttc msyhl.ttc msyh.ttc simsun.ttc STSONG.TTF等(有些字体不是免费的哈,仅个人研究可以使用)
在/usr/share/fonts目录新建chinese目录,将上述中文字体上传到/usr/share/fonts/chinese目录下:
[root@nb003 share]# cd /usr/share/fonts/ [root@nb003 fonts]# ls dejavu [root@nb003 fonts]# mkdir chinese [root@nb003 fonts]# ls chinese dejavu [root@nb003 fonts]# cd chinese/ [root@nb003 chinese]# ls msyhbd.ttc msyhl.ttc msyh.ttc simsun.ttc STSONG.TTF
给chinese目录加 755 权限
[root@nb003 chinese]# chmod -R 755 /usr/share/fonts/chinese4、安装ttmkfdir
ttmkfdir是用来搜索目录中所有的字体信息,并汇总生成fonts.scale文件的
[root@nb003 chinese]# yum -y install ttmkfdir Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package ttmkfdir.x86_64 0:3.0.9-42.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================================================================================================================================= Installing: ttmkfdir x86_64 3.0.9-42.el7 base 48 k Transaction Summary ======================================================================================================================================================================================================================================================================= Install 1 Package Total download size: 48 k Installed size: 103 k Downloading packages: ttmkfdir-3.0.9-42.el7.x86_64.rpm | 48 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : ttmkfdir-3.0.9-42.el7.x86_64 1/1 Verifying : ttmkfdir-3.0.9-42.el7.x86_64 1/1 Installed: ttmkfdir.x86_64 0:3.0.9-42.el7 Complete!
安装ttmkfdir后,执行如下ttmkfdir命令:
[root@nb003 chinese]# ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
修改字体配置文件:
[root@nb003 chinese]# vim /etc/fonts/fonts.conf
将我们的字体目录/usr/share/fonts/chinese加入到/etc/fonts/fonts.conf配置文件中,如下:
fc-cache
[root@nb003 chinese]# fc-cache Fontconfig warning: "/etc/fonts/fonts.conf", line 27: unknown element "div" Fontconfig error: "/etc/fonts/fonts.conf", line 27: mismatched tag Fontconfig error: Cannot load config file from /etc/fonts/fonts.conf Fontconfig warning: noelements found. Check configuration. Fontconfig warning: adding /usr/lib/fontconfig/cache Fontconfig warning: addingfontconfig
最后,再次查看字体库:
[root@nb003 chinese]# fc-list Fontconfig warning: "/etc/fonts/fonts.conf", line 27: unknown element "div" Fontconfig error: "/etc/fonts/fonts.conf", line 27: mismatched tag Fontconfig error: Cannot load config file from /etc/fonts/fonts.conf Fontconfig warning: noENDelements found. Check configuration. Fontconfig warning: adding /usr/lib/fontconfig/cache Fontconfig warning: addingfontconfig /usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique /usr/share/fonts/chinese/msyh.ttc: Microsoft YaHei:style=Normal /usr/share/fonts/dejavu/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold /usr/share/fonts/chinese/simsun.ttc: SimSun,宋体:style=Regular,常规 /usr/share/fonts/chinese/msyhbd.ttc: Microsoft YaHei:style=Έντονα /usr/share/fonts/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book /usr/share/fonts/chinese/msyh.ttc: Microsoft YaHei UI:style=Normal /usr/share/fonts/chinese/msyhbd.ttc: Microsoft YaHei UI:style=Έντονα /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/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold /usr/share/fonts/chinese/STSONG.TTF: STSong:style=Regular /usr/share/fonts/dejavu/DejaVuSansCondensed.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book /usr/share/fonts/dejavu/DejaVuSans-ExtraLight.ttf: DejaVu Sans,DejaVu Sans Light:style=ExtraLight /usr/share/fonts/dejavu/DejaVuSansCondensed-BoldOblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique /usr/share/fonts/dejavu/DejaVuSans-Oblique.ttf: DejaVu Sans:style=Oblique /usr/share/fonts/dejavu/DejaVuSans-BoldOblique.ttf: DejaVu Sans:style=Bold Oblique /usr/share/fonts/chinese/msyhl.ttc: Microsoft YaHei,Microsoft YaHei Light:style=Light,Regular



