I. Introduction
When I took a screenshot using selenium in Linux recently, I found that the text had changed into boxes:
Although it does not affect the use of selenium, it does affect debugging and is not good-looking. Later I found out that it was because Linux lacks Chinese fonts, and it can be solved by installing Chinese fonts.
2. Install Chinese fonts (take centos as an example)
1) Pre-inspection
First check /usr/share
whether there is a directory in the directory fonts
. fontconfig
If not, you need to execute the following command to install it:
yum -y install fontconfig
After the installation is complete, you can use fc-list
the command to check the fonts installed on the system:
Here we can directly use fc-list :lang=zh
the command to check whether the Chinese fonts are installed.
2) Download the Songti font
There are many on the Internet, just search for the Song Dynasty font and you will be able to find them. If you really can’t find the card at the end of the article, please contact me and I will send it to you (links are easy to be blocked).
3) Install fonts
Directory to enter first /usr/share/fonts
:
cd /usr/share/fonts
Then /usr/shared/fonts
create a new Chinese font folder in and enter the command:
mkdir chinese
Then transfer the downloaded fonts chinese
to the directory.
Execute the command again to install the font index command:
yum install mkfontscale
Then enter the chinese directory and execute the command to generate the font index:
cd chinese
mkfontscale
fc-list :lang=zh
Finally , you can see the installed Chinese fonts through the command:
At this time, if we take a screenshot, it will display normally, and the box fonts will no longer appear.