Linux CentOS 7 Install Font Library & Chinese Fonts

foreword

In the report, it is found that there are Chinese garbled characters and Chinese fonts are not neat (overlapping). The first consideration is whether the operating system has Chinese fonts. In CentOS 7, it is found that the input command to view the font list indicates that the command is invalid: 
write picture description here 
As can be seen from the above figure, not only There is no Chinese font, not even a font library, so let's record how to install the font library and Chinese fonts in Linux CentOS 7.

Install the font library

In CentOS 4.x, fontconfig is used to install the font library, so enter the following command:

yum -y install fontconfig
  • 1

When you see the prompt message in the figure below, it means that the installation has been successful: 
write picture description here

At this time, you can see the fonts and fontconfig directories in the /usr/shared directory (which were not there before): 
write picture description here

Next, we can add Chinese fonts to our font library.

Add Chinese font

In CentOS, the font library is stored in the fonts directory shown in the figure above, so the first thing we need to do is to find the Chinese font file and put it in this directory, and the Chinese font file can be found in our windows system. , open the Windows/Fonts directory under the c drive: 
write picture description here

As shown in the figure above, we only need to copy the fonts we need and upload them to the linux server. Here I choose Song and Hei (these two fonts are used in the report). You can see that there are two suffixes named ttf and ttc files: write picture description here 
Before that, we need to create a new directory. First, create a new directory Chinese in the /usr/shared/fonts directory: 
write picture description here

Then upload the above two fonts to the /usr/shared/fonts/chinese directory: 
write picture description here

Then you need to modify the permissions of the Chinese directory:

chmod -R 755 /usr/share/fonts/chinese
  • 1

Next, you need to install ttmkfdir to search for all font information in the directory, and generate a fonts.scale file. Enter the command:

yum -y install ttmkfdir
  • 1

When you see the prompt message in the figure below, it means that the installation has been successful: 
write picture description here

Then execute the ttmkfdir command:

ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
  • 1

The last step is to modify the font configuration file, first open the configuration file through the editor:

vi /etc/fonts/fonts.conf
  • 1

You can see a Font list, that is, the font list. Here we need to add the Chinese font location we added: 
write picture description here 
then enter: wq to save and exit, and finally don't forget to refresh the font cache in the memory, so that you don't need to reboot to restart:

fc-cache
  • 1

In this way, all the steps are completed, and finally look at the font list through fc-list again: 
write picture description here

It can be seen that the Chinese fonts have been successfully installed, and the installation process is all over. If you check the report again, you can find that the Chinese style and content can be displayed normally.

Summarize

Briefly record the problem of installing font libraries and Chinese fonts in CentOS 7, I hope it will help students who encounter the same problem, The End.

Original: https://blog.csdn.net/wlwlwlwl015/article/details/51482065

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324849203&siteId=291194637