There are three common GUI programs in Linux configuration files

Source: Internet
Author: User

The Linux configuration file has been developing for a long time. Here I will share my personal understanding. Next I will talk about the Linux configuration file. There are three common Linux GUI programs: GTK1, GTK2, and QT. Programs Based on these three graphics libraries have different requirements for beautification. Common font drawing schemes in XFree86 include xtt, freetype, Fontconfig, and Xft. Next let's take a look at it separately.

1. The GTK1 program does not support Fontconfig. So it is a little troublesome. To get a font, you first need to let X find it, right? This step will be detailed in the Fontpath attribute in the Section "files" Section of/etc/X11/XF86config. Now, X knows where the font is.

The gtk1 program cannot use them directly, because we have not "registered" them yet, so we need to generate two files fonts in the Fontpath set above. dir fonts. the scale files contain the list of all fonts in the Fontpath, which is an "Index ".

With this "Index", the gtk1 program can find the corresponding font. Tools for generating these two files include mkfontdir, mkfontscale, and ttmkfdir. Well, if the above two steps are completed correctly, your gtk1 program can now display Chinese characters normally. Common gtk1 programs include xmms, gimp .....

2. The GTK2 and QT programs can use Fontconfig. Fontconfig is a tool that selects fonts and determines how to display them. Similar to the Fontpath attribute in XF86config and the features of fonts. dir and fonts. scale mentioned above, this is to let the program find these fonts.

Therefore, GTK2 and QT XF86config and fonts. dir are useless. For such programs, the main Linux configuration file is/etc/fonts. conf. There are a lot of advanced features of Fontconfig, detailed instructions can refer to here: http://www.linuxfans.org/nuke/modules.php? Name = Forums & file = viewtopic & t = 48331 there are a lot of programs for GTK2 and QT, KDE, GNOME, Firebird ............

The two paragraphs mentioned above only let the program find the font and are not responsible for the specific display work. They can only ensure that your program can find the font without garbled characters, that is, the so-called "Chinese". What is freetype/Xft or xtt?

I understand that they are responsible for displaying fonts on the screen, which determines the effect of the fonts you see. The famous "firefly beautification package" has done a lot of work to improve the Chinese display effect. That is, the so-called "beautification". At this point, you should have a general concept of "Chinese" and "beautification.

The next step is to implement freetype, fontconfig, and xft in Slackware 9.1. I use Slackware 9.1, but the principle of beautifying other releases is similar. After reading the article and understanding it through practice, we should be able to flexibly apply other releases. The following command starts with #, indicating that the operation is performed as root, and $ indicates that the operation is performed as normal user.

Step1. prepare TrueType fonts, such as simsun. ttf tahoma. ttf verdana. ttf. Then decide which directory you want to put the font in. This directory is whatever you like. I put them in/usr/X11R6/lib/X11/fonts/TTF. For example, if all the ttf fonts you downloaded are under/home/username/myfonts/, perform the following operations # cp/home/username/myfonts /*. ttf/usr/X11R6/lib/X11/fonts/TTF/

Step2. let the GTK1 program find the font you just put in. Have you forgotten the method mentioned above? Let's first modify XF86config # vi/etc/X11/XF86config to find Section "Files, add a Fontpath attribute FontPath "/usr/X11R6/lib/X11/fonts/TTF /"

Of course, if you already have a path in your font, you don't need to add it. If your path is different from mine, write your path, you can also add your own font path at any time.
If you find the line Load "xtt" in XF86config, comment it out.

I don't need xtt. Next, of course, I want to prepare fonts. dir and fonts. scale. The two file generation tools are described above. Slackware comes with mkfontdir and mkfontscale. I personally strongly do not recommend these two tools. The fonts. dir they generate is very uncomfortable, and the gbk encoding cannot be found in simsun. ttf.

You can download a tool named ttmkfdir: ftp: // 216.254.0.38/linux/rawhide/1.0/i386/Fedora/RPMS/ttmkfdir-3.0.9-7.i386.rpm assuming you have installed this tool, do the following: # ttmkfdir/usr/X11R6/lib/X11/fonts/TTF/-o/usr/X11R6/lib/X11/fonts/TTF/fonts. scale Now check this file # vi/usr/X11R6/lib/X11/fonts/TTF/fonts. scale

If there are rows starting with: 1: simsun. ttfxxxxxxxxxxxxxxxxxx and like this, delete them. freetype does not need this, and may cause some problems. Pay special attention to the generation of simsun. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-c-0-gb2312.1980-0 simsun. ttf-misc-SimSun-medium-r-normal -- 0-0-0-0-c-0-gbk-0, because encoding is very important, mkfontdir generates fonts. dir probably does not have the encoding of-gbk-0.

This will also cause some problems. So after I use ttmkfdir to ensure that no error occurs, # cp/usr/X11R6/lib/X11/fonts/TTF/fonts. scale/usr/X11R6/lib/X11/fonts/TTF/fonts. dir files are actually the same.) You can use fonts for the gtk1 program, but you must specify the fonts you want to use in the gtk1 program. There is a global Linux configuration file/etc/gtk/gtkrc. zh_CN for the fonts used by the gtk1 program.
Paste my Linux configuration file

# This file defines the fontsets for Chinese language (zh) using
# The simplified chinese standard GuoBiao as in mainland China (CN)
#
#1999, Pablo Saratxaga
#

Style "gtk-default-zh-cn "{
Fontset = "-*-bitstream vera sans-medium-r-normal-*-120-*-p-*-microsoft-cp1252 ,\
-*-Simsun-medium-r-normal-*-12-*-gbk-0"
}
Class "GtkWidget" style "gtk-default-zh-cn"


This file tells the program that bitstream vera sans fonts are preferred for English fonts. Because bitstream vera sans does not have Chinese fonts, The simsun fonts behind them are used. At this point, the gtk1 program has been completed in Chinese. Now you can run an xmms command on startx. What is the interface? If the xmms list shows Chinese characters, you can search for other articles. It is also easy to add a few tips and instructions:

1.-*-bitstream vera sans-medium-r-normal-*-120-*-p-*-isn't the font Representation Method complex like microsoft-cp1252? There is a tip to help you select the font you want,/usr/X11R6/bin/There is a program xfontsel, run it. You can figure it out by yourself. Here you can see that the ttf font that the gtk1 program can find is read from the fonts. dir file you just generated. You can also get the correct expression format of the font you need.

2. Slackware 9.1 has a series of excellent ttf fonts such as bitstream vera sans. By default, all Veraxx. TTF fonts are in the/usr/X11R6/lib/X11/fonts/ttf/directory. However, the fonts. dir in that directory does not list them. If you have already done this by following my methods, ttmkfdir has included them in the previous step. If you are operating on another directory, use ttmkfdir in/usr/X11R6/lib/X11/fonts/TTF. The method is the same as the previous one.

3. fonts generated by ttmkfdir. dir and fonts. scale may have some extra code, such as the lines that end with ascii-0 and adobe standard-0, which causes some problems for me, if you think there is something wrong, delete all such rows first.

Step 3. Complete the gtk2 and QT programs. Fontconfig-based font-based programs are easy to configure. fontconfig also provides some more advanced features. Similar to gtk1, let these programs find these fonts. As mentioned earlier, the Fontpath and fonts. dir files in XF86config are no longer necessary. The core Linux configuration file of fontconfig is/etc/fonts. conf. Start to open this file with vi.

/Usr/X11R6/lib/X11/fonts
~ /. Fonts
/Usr/share/fonts

This section tells fontconfig to find fonts in these directories, including their subdirectories. Isn't it easier than Fontpath and fonts. dir? All you need to do is add the path where you put the font. The path I just put myself in is already included. So you don't need to modify it.

Run # fc-cache to update the font information. Now, the gtk2 and qt programs can use the font you added. Is it too easy? The modification to fonts. conf takes effect immediately. Unlike the gtk1 program, you have to run the gtkrc program again, modify XF86config, or even restart X.

Similar to the gtk1 program, the gtk2 and qt programs both have a global font configuration. The global Linux configuration file for the gtk2 program is/etc/gtk-2.0/gtkrc also paste my content

Style "user-font "{
Font_name = "Bitstream Vera Sans 9 "}
Class "*" style "user-font"

Is to tell the program to use Bitstream Vera Sans, the font size is 9 qt program default font configuration $/usr/lib/qt-3.2.1/bin/qtconfig out a graphical interface, you can easily select the font you want.

Tips and notes:

1. The xfontsel mentioned above can help you check the available fonts of gtk1. What fonts does fontconfig find? There is also a program called fc-list, which is run under/usr/X11R6/bin/by default, and a list is displayed. The font name is the font that can be used. For example, the font name of the gtk2Linux configuration file is in.

2./etc/fonts. conf has many powerful functions, which are actually complicated. For detailed settings, refer to the article connection at the beginning of this article.

3. You should find out. For example, when you select a font in the kde control center, you can select Tahoma and Vera sans for all fonts. What I wrote in gtkrc is also an English font, in this way, the English font looks very pp, and how does the Chinese font decide? Why can I still display the English font while the Chinese font is normal? This is the credit of fontconfig. There are two sections in my fonts. config:

Bitstream Vera Sans
Tahoma
Verdana
Arial
Helvetica
Nimbus Sans L
Luxi Sans
Kochi Gothic
Ar pl KaitiM GB
Ar pl KaitiM Big5
Baekmuk Dotum
SimSun
Sans-serif

And

Sans-serif
Bitstream Vera Sans
Tahoma
Verdana
Arial
Helvetica
Nimbus Sans L
Luxi Sans
Kochi Gothic
Ar pl KaitiM GB
Ar pl KaitiM Big5
Baekmuk Dotum
SimSun

This section tells the program to display the sans-serif font, first use the front font in the list, here is Bitstream Vera Sans, if the font cannot display the expected characters, search for them below. For Chinese characters, find the last SimSun (Sun. If you want to use other default Chinese characters, you can stack the Chinese fonts you need on SimSun. The font you want is preferred.

Until now, the Chinese language has actually ended. If you think the effect is good, stop it. If you think it is still not perfect, for example, the Chinese details are not very good, you can turn to firefly's beautification package to install these packages. I will briefly introduce the features of these packages. The fontconfig-2.2.1-i486-1.Firefly.tgz will replace your current/etc/fonts. conf with some firefly modified attributes.

Freetype-2.1.5-i486-1.Firefly.tgz xft-2.1.2-i486-1.Firefly.tgz these two are the core part of the font drawing, installed they can make the Chinese display more perfect, the specific principle I don't understand, hehe, did not work to study.

Xfree86-4.3.0-i486-5.Firefly.tgz can also improve the font display effect, I do not install it here, the taskbar and the title bar of the Chinese bold display does not come out. If your network is not good, this package is big too. You can leave it alone.

Qt-3.2.1-i486-1.Firefly.tgz this package does not matter, it is quite big. I think there is no more valuable feature than displaying a Chinese font name (SimSun shows "") when selecting a font for your qt program.


The above steps have been completed. If nothing happens, the English letters displayed by your gtk2 and qt programs are both bold and bold. If you think this is good, that's it. If you are the same as me, you may find it ugly to be dirty. You can add such a paragraph to your/etc/fonts/fons. conf file.

Medium
Medium
Spacing
Proportional
Demibold
Bold
16
8
F

In this way, Tahoma, Verdana, and other major ttf fonts in Windowz are no different from those in Windows. However, Bitstream Vera Sans seems to be a little "little meat", but the overall effect is good, please choose to use. To add one point, for the GTK2 program, there is generally no need to change/etc/fonts. conf such as English with Tahoma, Chinese with SimSun can be directly in/etc/gtk-2.0/gtkrc change

Style "default"
{
Font_name = "Tahoma, SimSun 9"
}
Widget_class "*" style "default"

  1. Manage Linux configuration files in Perl
  2. Understand Linux configuration files
  3. Linux software development and installation of Grub, installation from hard disk iso
  4. Linux gcc compiles and writes a small program to verify its correctness.
  5. Linux Startup Service provides advanced power management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.