When we use the Linux system, we often find that Chinese fonts are missing, resulting in failure to generate and display Chinese normally, and garbled characters. The following will briefly introduce how to install and extend new Chinese fonts to solve the above problems. The specific steps are as follows:
1. Download the Chinese character library
Download by searching online, or by copying the Chinese font library in the windows directory (C:\Windows\Fonts), such as Song type: simsun.ttf, Microsoft Yahei: msyh.ttf and msyhbd.ttf
2. Query the installed fonts of the Linux system
[root@updev1 ~]# fc-list
AR PL UMing TW:style=Light
AR PL UMing HK:style=Light
AR PL UMing CN:style=Light
AR PL UKai TW MBE:style=Book
AR PL UKai CN:style=Book
AR PL UKai HK:style=Book
AR PL UKai TW:style=Book
WenQuanYi Zen Hei, WenQuanYi Zheng Hei, WenQuanYi Zheng Hei: style=Regular
WenQuanYi Zen Hei Mono, WenQuanYi equal width and black, WenQuanYi equal width and black: style=Regular
AR PL UMing TW MBE:style=Light
WenQuanYi Zen Hei Sharp, Wenquanyi dot matrix is black, Wenquanyi dot matrix is black: style=Regular
Note: The query result through the command does not have the required Chinese font (Song style)
3. Create a font library directory and copy the corresponding font library files to this directory
[root@updev1 ~]# cd /usr/share/fonts
[root@updev1 fonts]# mkdir chinese
Copy the simsun.ttf file to this directory
Fourth, generate font index information
[root@updev1 fonts]# cd chinese
[root@updev1 chinese]# mkfontscale
[root@updev1 chinese]# mkfontdir
[root@updev1 chinese]# ll
total 10264
-rw-r--r-- 1 root root 189 Sep 6 17:46 fonts.dir
-rw-r--r-- 1 root root 189 Sep 6 17:46 fonts.scale
-rw-r--r-- 1 root root 10499104 Sep 6 17:46 simsun.ttf
Note: Generate corresponding fonts.scale and fonts.dir files
5. Check whether the installation has been successful
[root@updev1 chinese]# fc-list :lang=zh
AR PL UMing TW:style=Light
AR PL UMing HK:style=Light
AR PL UMing CN:style=Light
SimSun, Times New Roman: style=Regular
AR PL UKai TW MBE:style=Book
AR PL UKai CN:style=Book
AR PL UKai HK:style=Book
AR PL UKai TW:style=Book
WenQuanYi Zen Hei, WenQuanYi Zheng Hei, WenQuanYi Zheng Hei: style=Regular
WenQuanYi Zen Hei Mono, WenQuanYi equal width and black, WenQuanYi equal width and black: style=Regular
AR PL UMing TW MBE:style=Light
WenQuanYi Zen Hei Sharp, Wenquanyi dot matrix is black, Wenquanyi dot matrix is black: style=Regular
Note: The result list is visible (red font), and the Song Dynasty font library has been installed successfully