It has always been a headache for Linux beginners to display and enter Chinese characters correctly on the Linux Desktop. at present, there are many articles in the Chinese language, but most of them only talk about the steps and don't talk about the truth, so that beginners can get confused in the cloud. this article will start with the font principle of X to help you understand the font mechanism of X and learn it in Chinese.
First, we need to understand that X's font engine. X supports Truetype fonts (a scalable font) mainly in four engines: freetype, xtt, xfs, and Xft.
Freetype and xtt are internal modules of X. freetype1 rendering engine is used.
Xfs and xft are external service programs. xfs is a system-level Font Service program. It can also be used as an internal module of X. Like other class libraries, freetype2. Xft is loaded only when it is called. only xft supports antialias.
It is necessary to talk about freetype here. freetype is an open source font rendering engine, not just designed for X. its function is to read Truetype font information, such as the size, resolution, encoding, and so on, and then render it into the desired bitmap data output. freetype's current version is 2.x. the biggest difference from 1.0 is the addition of the anti-aliasing function.
Which one should I use if there are so many engines? As a matter of fact, the best Chinese support is xtt so far. because the effect of Chinese fonts calculated by using the function description method is unsatisfactory when the font is small, many Chinese font companies embed bitmap fonts in Truetype fonts. these bitmap fonts need to be read in special ways, and only xtt can do this in all engines.
The next step is to add the font to X so that xtt can be read correctly.
First, to configure the Linux system file, we need to use the root account to enter, which is equivalent to the administrator in windows.
The configuration file for X is/etc/XF86Config-4 (newer graphics card) or XF86Config (older graphics card). Open it with your favorite text editor, such as kedit or gedit.
After opening the configuration file, we find that the configuration file is divided into multiple sections. The first Section we need to configure is Section "Files". This Section describes the file information to be called by X.
To add a font directory, you just need to insert a line of FontPath "directory name" in it, such:
Section "Files"
# Multiple FontPath entries are allowed (they are concatenated together)
# By default, Mandrake 6.0 and later now use a font server independent
# The X server to render fonts.
FontPath "unix/:-1"
FontPath "/truetype" # insert a font directory
EndSection
Then let X load the xtt font engine:
Locate Section "Module" and modify it as follows:
Section "Module"
# Load "dbe" # Double-Buffering Extension
# Load "v4l" # Video for Linux
Load "extmod"
Load "glx
# Load "type1" # The type1 module renders the type1 font, which is in conflict with xtt and must be shielded.
# Load "freetype" # The freetype module renders Truetype fonts, conflicts with xtt, and must be shielded.
Load "xtt" # Add the xtt module Engine
EndSection
Now, xtt will automatically find the font in/truetype.
Now, copy the font to/truetype. First, create a truetype directory in the root directory
Mkdir/truetype
You can.
To copy data from a windows partition, you must first mount the file to connect the Linux directory to the windows partition. Create a "c" directory under the root directory.
Mkdir/c
Then
Mount/dev/hda1/c
In this way, the drive c under windows is connected to the/c directory under Linux. You can see the file on drive c in/c.
Then, enter the font file directory in/c, which is usually in Fonts under the window. Note that the directory names are case-sensitive in Linux.
Copy the font file to/truetype and press
Cp simsun. ttc/truetype/simsun. ttf
Cp tahoma */truetype/
In this way, we will copy the required font file to truetype.
Next, we need to set the font file. in Linux, the font setting of X is very annoying. Unlike windows, it's just a copy. In the initial stage, we can't help it.
Create a fonts. dir File, As shown below
Simsun. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-c-0-gb2312.1980-0
Ai = 0.3: simsun. ttf-misc-SimSun-medium-I-normal -- 0-0-0-0-c-0-gb2312.1980-0
Ds = y: simsun. ttf-misc-SimSun-bold-r-normal -- 0-0-0-0-c-0-gb2312.1980-0
Ds = y: ai = 0.3: simsun. ttf-misc-SimSun-bold-I-normal -- 0-0-0-0-c-0-gb2312.1980-0
Tahoma. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-p-0-iso8859-1
Ai = 0.3: tahoma. ttf-misc-SimSun-medium-I-normal -- 0-0-0-0-p-0-iso8859-1
Tahomabd. ttf-misc-SimSun-bold-r-normal -- 0-0-0-0-p-0-iso8859-1
Ai = 0.3: tahomabd. ttf-misc-SimSun-bold-I-normal -- 0-0-0-0-p-0-iso8859-1
Simsun. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-p-0-gbk-0
Ai = 0.3: simsun. ttf-misc-SimSun-medium-I-normal -- 0-0-0-0-p-0-gbk-0
Ds = y: simsun. ttf-misc-SimSun-bold-r-normal -- 0-0-0-0-p-0-gbk-0
Ds = y: ai = 0.3: simsun. ttf-misc-SimSun-bold-I-normal -- 0-0-0-0-p-0-gbk-0
Simsun. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-p-0-fcd8859-15
Ai = 0.3: simsun. ttf-misc-SimSun-medium-I-normal -- 0-0-0-0-p-0-fcd8859-15
Ds = y: simsun. ttf-misc-SimSun-bold-r-normal -- 0-0-0-0-p-0-fcd8859-15
Ds = y: ai = 0.3: simsun. ttf-misc-SimSun-bold-I-normal -- 0-0-0-0-p-0-fcd8859-15
Simsun. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-p-0-iso8859-15
Ai = 0.3: simsun. ttf-misc-SimSun-medium-I-normal -- 0-0-0-0-p-0-iso8859-15
Ds = y: simsun. ttf-misc-SimSun-bold-r-normal -- 0-0-0-0-p-0-iso8859-15
Ds = y: ai = 0.3: simsun. ttf-misc-SimSun-bold-I-normal -- 0-0-0-0-p-0-iso8859-15
Simsun. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-c-0-iso10646-1
Ai = 0.3: simsun. ttf-misc-SimSun-medium-I-normal -- 0-0-0-0-c-0-iso10646-1
Ds = y: simsun. ttf-misc-SimSun-bold-r-normal -- 0-0-0-0-c-0-iso10646-1
Ds = y: ai = 0.3: simsun. ttf-misc-SimSun-bold-I-normal -- 0-0-0-0-c-0-iso10646-1
The 24 in the first line indicates that there are a total of 24 rows below (it seems silly), and other formats are similar:
Ds = y: ai = 0.3: simsun. ttf-misc-SimSun-bold-I-normal -- 0-0-0-0-p-0-gbk-0
Note:
Simsun. ttf: font file name
Ds = [yn]: ds is an xtt function. If it is set to "y", it indicates bold and "n" indicates normal.
Ai = Real_number: indicating inclination. If not set, it indicates automatic.
Misc: indicates the font category.
SimSun: indicates the font name.
Bold: bold indicates bold, others such as medium indicates normal,
I: It indicates italic, and r is normal.
P: Variable Length. c is a square and m is a fixed width.
Gbk: font Encoding
We found that we also use tahoma English font, which will be replaced by pp tahoma when the system reads Simsun English font.
Now, save the disk and copy it to fonts. scale.
Cp fonts. dir fonts. scale
Then copy the encoding File encodings. dir to the directory.
Cp/usr/X11R6/lib/X11/fonts/encodings. dir/truetype
Okay. Let's restart. Change all default fonts such as KDE, mozilla, and galeon to simsun. Haha, isn't it much more beautiful than before?
You can back up these configuration files and do not need to set them later.
The following describes the configurations of several other font engines:
Xfs: the configuration file is/etc/X11/fs/config.
Xft: the configuration file is/etc/X11/Xftconfig.
Xft configuration is relatively easy. You only need to copy the font to any directory specified by dir in the configuration file. If you need a small font that does not display AA, you can add it at the end:
Match
Any size> 8
Any size <17
Edit
Antialias = false;
Match
Any pixelsize> 8
Any pixelsize <17
Edit
Antialias = false;
So 8 ~ The font on the 17th will not use the anti-aliasing function.