The problem

When DevTools was used to debug chromium in headless mode in the VIRTUAL machine, it was found that all the debugging Windows displayed were □□□ (except For English characters). After checking, it was found that the CentOS in the VIRTUAL machine only has English fonts, but does not contain Chinese fonts. To display Chinese characters, we need to install Chinese fonts by ourselves.

Font library related commands

  • If the /usr/shared directory does not have a fonts and fontconfig directory, you need to install the font library first by typing the command:
yum -y install fontconfig
Copy the code
  • After the installation is complete, you can view the installed fonts by entering the following command:
fc-list
Copy the code
  • You can also view the installed Chinese fonts by running the following command:
fc-list :lang=zh
Copy the code

Installing Chinese fonts

In CentOS, the font library is stored in /usr/shared/fonts directory, so we need to find the Chinese font file in Windows and copy it to this directory. Font files for Windows are in the C:\Windows\Fonts directory. So, the installation steps are:

  • To create a new Chinese font folder in CentOS, run the following command:
mkdir -p /usr/share/fonts/chinese
Copy the code
  • If the directory permission is insufficient, run the following command to change the directory permission:
chmod -R 755 /usr/share/fonts/chinese
Copy the code
  • Copy the Chinese Fonts in C:\Windows\Fonts — such as msyh. TTC, simhei. TTF, simsun.ttc — to the directory /usr/share/fonts/ Chinese created in CentOS.

PS: If you open the font folder in WIndows, it is not the file named msyh. TTC, but the Chinese font name, you can copy the font to the desktop, the desktop will show the real file name, and then upload it to CentOS from the desktop.

  • To install the font indexing directive, type:
yum install mkfontscale
Copy the code
  • Go to /usr/share/fonts/ Chinese, generate font index, type command:
cd  /usr/share/fonts/chinese
mkfontscale
Copy the code
  • Finally, run the fc-list :lang=zh command described above to check whether the fonts are installed successfully. After the installation is successful, you can see:
[root@localhost chinese]# fc-list :lang=zh /usr/share/fonts/chinese/msyh.ttc: Microsoft YaHei:style=Normal /usr/share/fonts/chinese/simsun.ttc: Song typeface, SimSun: style = routine, Regular/usr/share/fonts/Chinese/msyh TTC: Microsoft YaHei UI:style=Normal /usr/share/fonts/chinese/simsun.ttc: New song typeface, NSimSun: style = routine, Regular/usr/share/fonts/Chinese/simhei. The vera.ttf: simhei: style = NormalCopy the code