F
edora Core 1 桌面美化心得
最近查阅了一些以前的成果,下手把自己的FC1美化了一下,有些心得,特别拿来和大家交流一下。和多都是个人的想法,必定少不了一些错误,请大家指教。
参考文章:
1. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=73159
2. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=30742
3. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=81056
4. http://linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=47899
5. http://linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=20603
6. http://fractal.csie.org/~eric/fontconfig
7. http://www.linuxfans.org/nuke/modules.php?name=News&file=article&sid=1184&mode=thread&order=0&thold=0
8. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=5137&highlight=fonts.dir
刚刚开始美化的时候总是会遇见这么一大堆的咚咚,如xft、xtt、fontconfig、freetype、type1等.这些东西对newbie来说确实搞得人非常迷惑,我现在来谈谈我对他们的理解。这要首先说说X的两种字体系统,一种是核心X11字体系统,另一种xft字体系统,xft相对核心字体有很多好处,大家可以查阅参考文章。但是现在的应用程序中,有的使用的是核心字体系统,有的使用xft字体系统。相信随着时间的推移核心字体系统将被 xft字体系统取代。
应用程序中,KDE和GTK2基本上都是使用的xft字体系统,而X程序(直接由X的API写的)和GTK1程序很多都是基于核心字体系统的。
xft自己没有配置机制,配置它我们就得依靠fontconfig了,其中它的配置文件为/etc/fonts/fonts.conf,这是一个基于xml的文档,在我们以后的美化工作中它将非常重要。这里还要提到一个XF86config文件,他是X的配置文件。
xtt freetype type1都是用来优化字体如何来被显示的,如做一些光栅处理、反锯齿、字体渲染等工作。其实对于不同类型的字体选一种就可以啦。
现在,我们来开始进行美化工作吧。我们首先需要以下字体文件:mingliu.ttc simsun.ttc tahoma.ttf tahomabd.ttf times.ttf timesbd.ttf timesi.ttf timesbi.ttf verdana.ttf verdanab.ttf verdanai.ttf verdanabz.ttf (大家应该都知道怎么找到这些吧)
将以上这些字体放入下这两个目录中:/usr/X11R6/lib/X11/fonts/TTF
/usr/share/fonts/zh_CN/TrueType
以上两个目录应该是选一个就可以的,但是我是两个里面都放入了字体文件,呵呵。
然后我们可以安装firefly的美化包,里面修改了一些fontconfig的内容使得汉字效果更好。
http://firefly.idv.tw/setfont-xft/Fedora/Core_1/RPMS/
下面我们在来为X核心字体系统来添加这些字体,使得使用X核心字体的程序能够使用他们。为此我们将为以上两个目录重新生成fonts.dir和fonts.scale两个文件,请先对他们进行备份。X核心字体系统就是依靠这些文件来知道能够使用什么字体的。
[root@localhost root]# ttmkfdir -d /usr/X11R6/lib/X11/fonts/TTF -o /usr/X11R6/lib/X11/fonts/TTF/fonts.scale
[root@localhost root]# cp fonts.scale fonts.dir
[root@localhost root]# ttmkfdir -d /usr/share/fonts/zh_CN/TrueType -o /usr/share/fonts/zh_CN/TrueType/fonts.scale
[root@localhost root]# cp fonts.scale fonts.dir
然后我们修改/etc/X11/XF86config这个文件,让X知道到哪里去找字体文件
[root@localhost root]# vi /etc/X11/XF86config
修改如下:
Section "Files"
# RgbPath is the location of the RGB database. Note, this is the name of the
# file minus the extension (like ".txt" or ".db"). There is normally
# no need to change the default.
# Multiple FontPath entries are allowed (they are concatenated together)
# By default, Red Hat 6.0 and later now use a font server independent of
# the X server to render fonts.
RgbPath "/usr/X11R6/lib/X11/rgb"
FontPath "/usr/share/fonts/zh_CN/TrueType" #加入
FontPath "/usr/X11R6/lib/X11/fonts/TTF" #加入
FontPath "unix/:7100"
EndSection
现在我们已经为X核心字体系统添加了我们需要的字体啦,但是为了让一些GTK1的程序能够使用他门,我们还需要对GTK1的配置文件进行修改。
GTK1的配置文件为/etc/gtk/gtkrc.zh_CN ,我是修改为如下这个样子:
# $(gtkconfigdir)/gtkrc.zh_CN
#
# This file defines the fontsets for Chinese language (zh) using
# the simplified chinese standard GuoBiao as in mainland China (CN)
#
# 1999, Pablo Saratxaga <pablo@mandrakesoft.com>
#
style "gtk-default-zh-cn" {
fontset = "-microsoft-verdana-medium-r-normal-*-12-*-*-*-p-*-microsoft-cp1252,/
-misc-simsun-medium-r-normal-*-12-*-*-*-*-*-gb2312.1980-0"
}
class "GtkWidget" style "gtk-default-zh-cn"
这是为了告诉对于GTK1的程序,优先使用verdana字体,遇到无法显示的,如汉字,就用simsun字体(就是宋体)。
重启X:Ctrl+Alt+BackSpace
接着我们要做的是为xft字体系统来添加我们需要的字体。与核心系统不同,我们不需要那些令人讨厌的fonts.scale和fonts.dir 文件啦,所有的系统字体配置都交给了fontconfig来完成。fontconfig在下一次寻找时就能发现这些字体,并重建自己的字体列表。如果想在命令行上激活这个行为(比如想全面升级全系统的Fontconfig信息),可以使用`fc-cache'命令。
[root@localhost root]# fc-cache -v
然后要做的就是修改fonts.conf文件啦,我修改后的fonts.conf如下:(修改的地方我都做了注释)
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/fonts.conf file to configure system font access -->
<fontconfig>
<!--
DO NOT EDIT THIS FILE.
IT WILL BE REPLACED WHEN FONTCONFIG IS UPDATED.
LOCAL CHANGES BELONG IN 'local.conf'.
The intent of this standard configuration file is to be adequate for
most environments. If you have a reasonably normal environment and
have found problems with this configuration, they are probably
things that others will also want fixed. Please submit any
problems to the fontconfig bugzilla system located at fontconfig.org
Note that the normal 'make install' procedure for fontconfig is to
replace any existing fonts.conf file with the new version. Place
any local customizations in local.conf which this file references.
Keith Packard
-->
<dir>/usr/X11R6/lib/X11/fonts</dir>
<dir>/usr/share/fonts</dir>
<dir>~/.fonts</dir>
<!--
Accept deprecated 'mono' alias, replacing it with 'monospace'
-->
<match target="pattern">
<test qual="any" name="family">
<string>mono</string>
</test>
<edit name="family" mode="assign">
<string>monospace</string>
</edit>
</match>
<!--
Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
-->
<match target="pattern">
<test qual="any" name="family">
<string>sans serif</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<!--
Accept deprecated 'sans' alias, replacing it with 'sans-serif'
-->
<match target="pattern">
<test qual="any" name="family">
<string>sans</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<!--
Mark common families with their generics so we'll get
something reasonable
-->
<!--
Serif faces
-->
<alias>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Serif</family>
<family>Times</family>
<family>Times New Roman</family>
<family>Nimbus Roman No9 L</family>
<family>Luxi Serif</family>
<family>Kochi Mincho</family>
<family>AR PL SungtiL GB</family>
<family>AR PL Mingti2L Big5</family>
<family>Baekmuk Batang</family>
<default><family>serif</family></default>
</alias>
<!--
Sans-serif faces
-->
<alias>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Sans</family>
<family>Helvetica</family>
<family>Arial</family>
<family>Verdana</family>
<family>Nimbus Sans L</family>
<family>Luxi Sans</family>
<family>Kochi Gothic</family>
<family>AR PL KaitiM GB</family>
<family>AR PL KaitiM Big5</family>
<family>Baekmuk Dotum</family>
<default><family>sans-serif</family></default>
</alias>
<!--
Monospace faces
-->
<alias>
<family>Bitstream Vera Sans Mono</family>
<family>NSimSun</family> <!--加入-->
<family>Tahoma</family> <!--加入-->
<family>Courier</family>
<family>Courier New</family>
<family>Andale Mono</family>
<family>Luxi Mono</family>
<family>Nimbus Mono L</family>
<default><family>monospace</family></default>
</alias>
<!--
If the font still has no generic name, add sans-serif
-->
<match target="pattern">
<test qual="all" name="family" compare="not_eq">
<string>sans-serif</string>
</test>
<test qual="all" name="family" compare="not_eq">
<string>serif</string>
</test>
<test qual="all" name="family" compare="not_eq">
<string>monospace</string>
</test>
<edit name="family" mode="append_last">
<string>sans-serif</string>
</edit>
</match>
<!--
The Bitstream Vera fonts have GASP entries suggesting that hinting be
disabled below 8 ppem, but FreeType ignores those, preferring to use
the data found in the instructed hints. The initial Vera release
didn't include the right instructions in the 'prep' table. Fix this
by disabling hinting manually at smaller sizes (< 8ppem)
-->
<match target="font">
<test name="family">
<string>Bitstream Vera Sans</string>
</test>
<test name="pixelsize" compare="less">
<double>7.5</double>
</test>
<edit name="hinting">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test name="family">
<string>Bitstream Vera Serif</string>
</test>
<test name="pixelsize" compare="less">
<double>7.5</double>
</test>
<edit name="hinting">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test name="family">
<string>Bitstream Vera Sans Mono</string>
</test>
<test name="pixelsize" compare="less">
<double>7.5</double>
</test>
<edit name="hinting">
<bool>false</bool>
</edit>
</match>
<!--
Load per-user customization file
-->
<include ignore_missing="yes">~/.fonts.conf</include>
<!--
Load local system customization file
-->
<include ignore_missing="yes">local.conf</include>
<!--
Alias well known font names to available TrueType fonts
-->
<alias>
<family>Times</family>
<accept><family>Times New Roman</family></accept>
</alias>
<alias>
<family>Helvetica</family>
<accept><family>Verdana</family></accept>
</alias>
<alias>
<family>Arial</family>
<accept><family>Verdana</family></accept>
</alias>
<alias>
<family>Courier</family>
<accept><family>Courier New</family></accept>
</alias>
<!--
Check user preference to avoid bitmap fonts and replace
bitmap face names with equivalent scalable fonts
-->
<match target="pattern">
<test name="prefer_outline">
<bool>true</bool>
</test>
<test name="family">
<string>Helvetica</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>Arial</string>
</edit>
</match>
<match target="pattern">
<test name="prefer_outline">
<bool>true</bool>
</test>
<test name="family">
<string>Times</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>Times New Roman</string>
</edit>
</match>
<!--
Provide required aliases for standard names
-->
<alias>
<family>serif</family>
<prefer>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Serif</family>
<family>Times New Roman</family>
<family>Nimbus Roman No9 L</family>
<family>Luxi Serif</family>
<family>Times</family>
<family>Kochi Mincho</family>
<family>AR PL SungtiL GB</family>
<family>AR PL Mingti2L Big5</family>
<family>Baekmuk Batang</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Sans</family>
<family>Verdana</family>
<family>Nimbus Sans L</family>
<family>Luxi Sans</family>
<family>Arial</family>
<family>Helvetica</family>
<family>Kochi Gothic</family>
<family>AR PL KaitiM GB</family>
<family>AR PL KaitiM Big5</family>
<family>Baekmuk Dotum</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>NSimSun</family> <!--加入-->
<family>Tahoma</family> <!--加入-->
<family>Andale Mono</family>
<family>Courier New</family>
<family>Luxi Mono</family>
<family>Nimbus Mono L</family>
<family>Kochi Gothic</family>
<family>AR PL KaitiM GB</family>
<family>Baekmuk Dotum</family>
</prefer>
</alias>
<!--
Artificial oblique for fonts without an italic or oblique version
-->
<match target="font">
<!-- check to see if the font is roman -->
<test name="slant">
<const>roman</const>
</test>
<!-- check to see if the pattern requested non-roman -->
<test target="pattern" name="slant" compare="not_eq">
<const>roman</const>
</test>
<!-- multiply the matrix to slant the font -->
<edit name="matrix" mode="assign">
<times>
<name>matrix</name>
<matrix><double>1</double><double>0.2</double>
<double>0</double><double>1</double>
</matrix>
</times>
</edit>
<!-- pretend the font is oblique now -->
<edit name="slant" mode="assign">
<const>oblique</const>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
Artificial bold for fonts without a bold version.
-->
<match target="font">
<!-- check to see if the pattern requested > "medium" -->
<test target="pattern" name="weight" compare="more">
<const>medium</const>
</test>
<!-- pretend the font is bold now -->
<edit name="weight" mode="assign">
<const>bold</const>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
Disable "Global Advance" for all mono spacing fonts.
-->
<match target="font">
<test name="spacing" compare="eq">
<const>mono</const>
</test>
<edit name="globaladvance" mode="assign">
<bool>false</bool>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
Enable "hinting & autohint" for all fonts.
-->
<match target="font">
<edit name="hinting" mode="assign">
<bool>true</bool>
</edit>
<edit name="autohint" mode="assign">
<bool>true</bool>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
If you don't want to use emdebedbitmap first.
you can set this "embed" with false.
<match target="font">
<edit name="embed" mode="assign">
<bool>false</bool>
</edit>
</match>
-->
<config>
<!--
These are the default Unicode chars that are expected to be blank
in fonts. All other blank chars are assumed to be broken and
won't appear in the resulting charsets
-->
<blank>
<int>0x0020</int> <!-- SPACE -->
<int>0x00a0</int> <!-- NO-BREAK SPACE -->
<int>0x00ad</int> <!-- SOFT HYPHEN -->
<int>0x115f</int> <!-- HANGUL CHOSEONG FILLER -->
<int>0x1160</int> <!-- HANGUL JUNGSEONG FILLER -->
<int>0x1680</int> <!-- OGHAM SPACE MARK -->
<int>0x2000</int> <!-- EN QUAD -->
<int>0x2001</int> <!-- EM QUAD -->
<int>0x2002</int> <!-- EN SPACE -->
<int>0x2003</int> <!-- EM SPACE -->
<int>0x2004</int> <!-- THREE-PER-EM SPACE -->
<int>0x2005</int> <!-- FOUR-PER-EM SPACE -->
<int>0x2006</int> <!-- SIX-PER-EM SPACE -->
<int>0x2007</int> <!-- FIGURE SPACE -->
<int>0x2008</int> <!-- PUNCTUATION SPACE -->
<int>0x2009</int> <!-- THIN SPACE -->
<int>0x200a</int> <!-- HAIR SPACE -->
<int>0x200b</int> <!-- ZERO WIDTH SPACE -->
<int>0x200c</int> <!-- ZERO WIDTH NON-JOINER -->
<int>0x200d</int> <!-- ZERO WIDTH JOINER -->
<int>0x200e</int> <!-- LEFT-TO-RIGHT MARK -->
<int>0x200f</int> <!-- RIGHT-TO-LEFT MARK -->
<int>0x2028</int> <!-- LINE SEPARATOR -->
<int>0x2029</int> <!-- PARAGRAPH SEPARATOR -->
<int>0x202a</int> <!-- LEFT-TO-RIGHT EMBEDDING -->
<int>0x202b</int> <!-- RIGHT-TO-LEFT EMBEDDING -->
<int>0x202c</int> <!-- POP DIRECTIONAL FORMATTING -->
<int>0x202d</int> <!-- LEFT-TO-RIGHT OVERRIDE -->
<int>0x202e</int> <!-- RIGHT-TO-LEFT OVERRIDE -->
<int>0x202f</int> <!-- NARROW NO-BREAK SPACE -->
<int>0x205f</int> <!-- MEDIUM MATHEMATICAL SPACE -->
<int>0x2060</int> <!-- WORD JOINER -->
<int>0x2061</int> <!-- FUNCTION APPLICATION -->
<int>0x2062</int> <!-- INVISIBLE TIMES -->
<int>0x2063</int> <!-- INVISIBLE SEPARATOR -->
<int>0x206A</int> <!-- INHIBIT SYMMETRIC SWAPPING -->
<int>0x206B</int> <!-- ACTIVATE SYMMETRIC SWAPPING -->
<int>0x206C</int> <!-- INHIBIT ARABIC FORM SHAPING -->
<int>0x206D</int> <!-- ACTIVATE ARABIC FORM SHAPING -->
<int>0x206E</int> <!-- NATIONAL DIGIT SHAPES -->
<int>0x206F</int> <!-- NOMINAL DIGIT SHAPES -->
<int>0x3000</int> <!-- IDEOGRAPHIC SPACE -->
<int>0x3164</int> <!-- HANGUL FILLER -->
<int>0xfeff</int> <!-- ZERO WIDTH NO-BREAK SPACE -->
<int>0xffa0</int> <!-- HALFWIDTH HANGUL FILLER -->
<int>0xfff9</int> <!-- INTERLINEAR ANNOTATION ANCHOR -->
<int>0xfffa</int> <!-- INTERLINEAR ANNOTATION SEPARATOR -->
<int>0xfffb</int> <!-- INTERLINEAR ANNOTATION TERMINATOR -->
</blank>
<!--
Rescan configuration every 30 seconds when FcFontSetList is called
-->
<rescan>
<int>30</int>
</rescan>
<!--
Add by Firefly (firefly@firefly.idv.tw)
Output non English/Latin family name.
-->
<other_family>
<bool>true</bool>
</other_family>
</config>
</fontconfig>
对于fonts.conf文件我想做如说明,其中<alias></alias>这对标签是为一族字体定义一个相同的别名,这样我们在应用程序中选择字体的时候就可以选择这个别名,这样做一个很大的好处就是当一族字体其中的一种字体不存在或者无法工作(如无法显示汉字)时可以用其它字体来代替它。显然,这个fonts.conf文件定义了3个族的字体,他们分别是:serif sans-serif monospace ,这三个族字体可以发现在应用程序的字体选择中都有,选择了他们其实就是选择了这一族字体,并且通过fontconfig来起作用。再来看看我所修改的地方,由于默认的字体要不不能显示中文,要不就是很不好看,所以我们要加入比较好的字体,比如Tahoma和SimSun,其中前者用来显示英文,后者用来显示中文。特别注意的是,我们加入这两个字体的<family></family>标签的时候,都是把Tahoma和 SimSun放在该族字体的最前面,并把Tahoma放在SimSun的前面,这样做就是告诉fontconf要优先使用Tahoma来进行显示,当遇到 Tahoma无法显示时(如中文)就要用SimSun来显示,两者的顺序切不能颠倒。有些朋友美化后报告说程序中英文字体间隔过大,其原因之一就是可能因为颠倒了两者,把汉字字体放到了前面,那么系统优先使用这些字体,由于大多数汉字字体每个字都是等宽的,就会造成英文字体间隔过大。其它内容可以参考上面的参考文章。
我们又要回到/etc/X11/XF86config文件做点修改:(把Section "Module"部分修改为下面这个样子)
Section "Module"
Load "dbe"
Load "extmod"
Load "fbdevhw"
Load "glx"
Load "record"
Load "xtt"
# Load "freetype"
Load "type1"
# Load "dri"
EndSection
即我使用的xtt来进行字体效果渲染,大家也可以使用freetype,但是不推荐同时使用两者。我在美化过程中发现如果使用freetype的话,一些X程序的英文字体会间隔过大,这是freetype的问题,解决办法应该是修改freetype源码中的某些预定义常量然后重新编译。
同样,对于GTK2的程序也有对应的资源配置文件/etc/gtk-2.0/gtkrc,大家可以加入以下一段:
style "user-font"
{
font_name="Tahoma 9"
}
class "*" style "user-font"
然后执行下面的命令
[root@localhost root]# cp /usr/lib/libXft.so* /usr/X11R6/lib
KDE程序可以通过以下命令来配置
[root@localhost root]# qtconfig
重启X,应该可以看到美化生效了吧。
我使用的是gnome桌面(为什么?$@#%@#^^&**),所以进入后可以如下设置字体:(大家可以按照自己的喜好试试)
(见贴图)
关xmms的汉字显示问题,我在这里重复提一下,前面也有很多解决方法。在首选项的字体中如下填入
播放清单
-adobe-helvetica-medium-r-*-*-12-*,-misc-simsun-medium-r-normal-*-12-*-*-*-c-*-gb2312.1980-0
主窗口
-adobe-helvetica-medium-r-*-*-12-*,-misc-simsun-medium-r-normal-*-12-*-*-*-c-*-gb2312.1980-0
即要xmms优先用helvetica显示英文,用simsun显示中文,大家也可以换自己喜欢的。
还有一个有用的工具xfontsel,相信对大家一定有用,运行一下就知道是什么啦。
我的美化也有不足之处,也请大家提出一些建议,在mozilla中,粗体和斜体都可以被正常显示,而且个人感觉效果不错,但是在 OpenOffice中,除了少数英文字体能够被显示粗体和斜体外,其它字体(包括汉字)都无法显示粗体和斜体,我也正在研究中,不知道大家有什么好的解决方法没。
总结:学习linux的过程中就是要多动手,多实验,多请教,在挫折中不断前进。(不要扔鸡蛋,有禽流感噢。^_^)
有任何问题大家可以和我联系(li_zy@eyou.com),本文基本上都是前人的成果,所以我没有CopyRight,呵呵
感谢 linuxsir.org linuxfans.org bbs.edu.cn bbs.whnet.edu.cn
最近查阅了一些以前的成果,下手把自己的FC1美化了一下,有些心得,特别拿来和大家交流一下。和多都是个人的想法,必定少不了一些错误,请大家指教。
参考文章:
1. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=73159
2. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=30742
3. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=81056
4. http://linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=47899
5. http://linuxfans.org/nuke/modules.php?name=Forums&file=viewtopic&t=20603
6. http://fractal.csie.org/~eric/fontconfig
7. http://www.linuxfans.org/nuke/modules.php?name=News&file=article&sid=1184&mode=thread&order=0&thold=0
8. http://www.linuxsir.com/bbs/showthread.php?s=&threadid=5137&highlight=fonts.dir
刚刚开始美化的时候总是会遇见这么一大堆的咚咚,如xft、xtt、fontconfig、freetype、type1等.这些东西对newbie来说确实搞得人非常迷惑,我现在来谈谈我对他们的理解。这要首先说说X的两种字体系统,一种是核心X11字体系统,另一种xft字体系统,xft相对核心字体有很多好处,大家可以查阅参考文章。但是现在的应用程序中,有的使用的是核心字体系统,有的使用xft字体系统。相信随着时间的推移核心字体系统将被 xft字体系统取代。
应用程序中,KDE和GTK2基本上都是使用的xft字体系统,而X程序(直接由X的API写的)和GTK1程序很多都是基于核心字体系统的。
xft自己没有配置机制,配置它我们就得依靠fontconfig了,其中它的配置文件为/etc/fonts/fonts.conf,这是一个基于xml的文档,在我们以后的美化工作中它将非常重要。这里还要提到一个XF86config文件,他是X的配置文件。
xtt freetype type1都是用来优化字体如何来被显示的,如做一些光栅处理、反锯齿、字体渲染等工作。其实对于不同类型的字体选一种就可以啦。
现在,我们来开始进行美化工作吧。我们首先需要以下字体文件:mingliu.ttc simsun.ttc tahoma.ttf tahomabd.ttf times.ttf timesbd.ttf timesi.ttf timesbi.ttf verdana.ttf verdanab.ttf verdanai.ttf verdanabz.ttf (大家应该都知道怎么找到这些吧)
将以上这些字体放入下这两个目录中:/usr/X11R6/lib/X11/fonts/TTF
/usr/share/fonts/zh_CN/TrueType
以上两个目录应该是选一个就可以的,但是我是两个里面都放入了字体文件,呵呵。
然后我们可以安装firefly的美化包,里面修改了一些fontconfig的内容使得汉字效果更好。
http://firefly.idv.tw/setfont-xft/Fedora/Core_1/RPMS/
下面我们在来为X核心字体系统来添加这些字体,使得使用X核心字体的程序能够使用他们。为此我们将为以上两个目录重新生成fonts.dir和fonts.scale两个文件,请先对他们进行备份。X核心字体系统就是依靠这些文件来知道能够使用什么字体的。
[root@localhost root]# ttmkfdir -d /usr/X11R6/lib/X11/fonts/TTF -o /usr/X11R6/lib/X11/fonts/TTF/fonts.scale
[root@localhost root]# cp fonts.scale fonts.dir
[root@localhost root]# ttmkfdir -d /usr/share/fonts/zh_CN/TrueType -o /usr/share/fonts/zh_CN/TrueType/fonts.scale
[root@localhost root]# cp fonts.scale fonts.dir
然后我们修改/etc/X11/XF86config这个文件,让X知道到哪里去找字体文件
[root@localhost root]# vi /etc/X11/XF86config
修改如下:
Section "Files"
# RgbPath is the location of the RGB database. Note, this is the name of the
# file minus the extension (like ".txt" or ".db"). There is normally
# no need to change the default.
# Multiple FontPath entries are allowed (they are concatenated together)
# By default, Red Hat 6.0 and later now use a font server independent of
# the X server to render fonts.
RgbPath "/usr/X11R6/lib/X11/rgb"
FontPath "/usr/share/fonts/zh_CN/TrueType" #加入
FontPath "/usr/X11R6/lib/X11/fonts/TTF" #加入
FontPath "unix/:7100"
EndSection
现在我们已经为X核心字体系统添加了我们需要的字体啦,但是为了让一些GTK1的程序能够使用他门,我们还需要对GTK1的配置文件进行修改。
GTK1的配置文件为/etc/gtk/gtkrc.zh_CN ,我是修改为如下这个样子:
# $(gtkconfigdir)/gtkrc.zh_CN
#
# This file defines the fontsets for Chinese language (zh) using
# the simplified chinese standard GuoBiao as in mainland China (CN)
#
# 1999, Pablo Saratxaga <pablo@mandrakesoft.com>
#
style "gtk-default-zh-cn" {
fontset = "-microsoft-verdana-medium-r-normal-*-12-*-*-*-p-*-microsoft-cp1252,/
-misc-simsun-medium-r-normal-*-12-*-*-*-*-*-gb2312.1980-0"
}
class "GtkWidget" style "gtk-default-zh-cn"
这是为了告诉对于GTK1的程序,优先使用verdana字体,遇到无法显示的,如汉字,就用simsun字体(就是宋体)。
重启X:Ctrl+Alt+BackSpace
接着我们要做的是为xft字体系统来添加我们需要的字体。与核心系统不同,我们不需要那些令人讨厌的fonts.scale和fonts.dir 文件啦,所有的系统字体配置都交给了fontconfig来完成。fontconfig在下一次寻找时就能发现这些字体,并重建自己的字体列表。如果想在命令行上激活这个行为(比如想全面升级全系统的Fontconfig信息),可以使用`fc-cache'命令。
[root@localhost root]# fc-cache -v
然后要做的就是修改fonts.conf文件啦,我修改后的fonts.conf如下:(修改的地方我都做了注释)
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/fonts.conf file to configure system font access -->
<fontconfig>
<!--
DO NOT EDIT THIS FILE.
IT WILL BE REPLACED WHEN FONTCONFIG IS UPDATED.
LOCAL CHANGES BELONG IN 'local.conf'.
The intent of this standard configuration file is to be adequate for
most environments. If you have a reasonably normal environment and
have found problems with this configuration, they are probably
things that others will also want fixed. Please submit any
problems to the fontconfig bugzilla system located at fontconfig.org
Note that the normal 'make install' procedure for fontconfig is to
replace any existing fonts.conf file with the new version. Place
any local customizations in local.conf which this file references.
Keith Packard
-->
<dir>/usr/X11R6/lib/X11/fonts</dir>
<dir>/usr/share/fonts</dir>
<dir>~/.fonts</dir>
<!--
Accept deprecated 'mono' alias, replacing it with 'monospace'
-->
<match target="pattern">
<test qual="any" name="family">
<string>mono</string>
</test>
<edit name="family" mode="assign">
<string>monospace</string>
</edit>
</match>
<!--
Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
-->
<match target="pattern">
<test qual="any" name="family">
<string>sans serif</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<!--
Accept deprecated 'sans' alias, replacing it with 'sans-serif'
-->
<match target="pattern">
<test qual="any" name="family">
<string>sans</string>
</test>
<edit name="family" mode="assign">
<string>sans-serif</string>
</edit>
</match>
<!--
Mark common families with their generics so we'll get
something reasonable
-->
<!--
Serif faces
-->
<alias>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Serif</family>
<family>Times</family>
<family>Times New Roman</family>
<family>Nimbus Roman No9 L</family>
<family>Luxi Serif</family>
<family>Kochi Mincho</family>
<family>AR PL SungtiL GB</family>
<family>AR PL Mingti2L Big5</family>
<family>Baekmuk Batang</family>
<default><family>serif</family></default>
</alias>
<!--
Sans-serif faces
-->
<alias>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Sans</family>
<family>Helvetica</family>
<family>Arial</family>
<family>Verdana</family>
<family>Nimbus Sans L</family>
<family>Luxi Sans</family>
<family>Kochi Gothic</family>
<family>AR PL KaitiM GB</family>
<family>AR PL KaitiM Big5</family>
<family>Baekmuk Dotum</family>
<default><family>sans-serif</family></default>
</alias>
<!--
Monospace faces
-->
<alias>
<family>Bitstream Vera Sans Mono</family>
<family>NSimSun</family> <!--加入-->
<family>Tahoma</family> <!--加入-->
<family>Courier</family>
<family>Courier New</family>
<family>Andale Mono</family>
<family>Luxi Mono</family>
<family>Nimbus Mono L</family>
<default><family>monospace</family></default>
</alias>
<!--
If the font still has no generic name, add sans-serif
-->
<match target="pattern">
<test qual="all" name="family" compare="not_eq">
<string>sans-serif</string>
</test>
<test qual="all" name="family" compare="not_eq">
<string>serif</string>
</test>
<test qual="all" name="family" compare="not_eq">
<string>monospace</string>
</test>
<edit name="family" mode="append_last">
<string>sans-serif</string>
</edit>
</match>
<!--
The Bitstream Vera fonts have GASP entries suggesting that hinting be
disabled below 8 ppem, but FreeType ignores those, preferring to use
the data found in the instructed hints. The initial Vera release
didn't include the right instructions in the 'prep' table. Fix this
by disabling hinting manually at smaller sizes (< 8ppem)
-->
<match target="font">
<test name="family">
<string>Bitstream Vera Sans</string>
</test>
<test name="pixelsize" compare="less">
<double>7.5</double>
</test>
<edit name="hinting">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test name="family">
<string>Bitstream Vera Serif</string>
</test>
<test name="pixelsize" compare="less">
<double>7.5</double>
</test>
<edit name="hinting">
<bool>false</bool>
</edit>
</match>
<match target="font">
<test name="family">
<string>Bitstream Vera Sans Mono</string>
</test>
<test name="pixelsize" compare="less">
<double>7.5</double>
</test>
<edit name="hinting">
<bool>false</bool>
</edit>
</match>
<!--
Load per-user customization file
-->
<include ignore_missing="yes">~/.fonts.conf</include>
<!--
Load local system customization file
-->
<include ignore_missing="yes">local.conf</include>
<!--
Alias well known font names to available TrueType fonts
-->
<alias>
<family>Times</family>
<accept><family>Times New Roman</family></accept>
</alias>
<alias>
<family>Helvetica</family>
<accept><family>Verdana</family></accept>
</alias>
<alias>
<family>Arial</family>
<accept><family>Verdana</family></accept>
</alias>
<alias>
<family>Courier</family>
<accept><family>Courier New</family></accept>
</alias>
<!--
Check user preference to avoid bitmap fonts and replace
bitmap face names with equivalent scalable fonts
-->
<match target="pattern">
<test name="prefer_outline">
<bool>true</bool>
</test>
<test name="family">
<string>Helvetica</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>Arial</string>
</edit>
</match>
<match target="pattern">
<test name="prefer_outline">
<bool>true</bool>
</test>
<test name="family">
<string>Times</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>Times New Roman</string>
</edit>
</match>
<!--
Provide required aliases for standard names
-->
<alias>
<family>serif</family>
<prefer>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Serif</family>
<family>Times New Roman</family>
<family>Nimbus Roman No9 L</family>
<family>Luxi Serif</family>
<family>Times</family>
<family>Kochi Mincho</family>
<family>AR PL SungtiL GB</family>
<family>AR PL Mingti2L Big5</family>
<family>Baekmuk Batang</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Tahoma</family> <!--加入-->
<family>SimSun</family> <!--加入-->
<family>Bitstream Vera Sans</family>
<family>Verdana</family>
<family>Nimbus Sans L</family>
<family>Luxi Sans</family>
<family>Arial</family>
<family>Helvetica</family>
<family>Kochi Gothic</family>
<family>AR PL KaitiM GB</family>
<family>AR PL KaitiM Big5</family>
<family>Baekmuk Dotum</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>NSimSun</family> <!--加入-->
<family>Tahoma</family> <!--加入-->
<family>Andale Mono</family>
<family>Courier New</family>
<family>Luxi Mono</family>
<family>Nimbus Mono L</family>
<family>Kochi Gothic</family>
<family>AR PL KaitiM GB</family>
<family>Baekmuk Dotum</family>
</prefer>
</alias>
<!--
Artificial oblique for fonts without an italic or oblique version
-->
<match target="font">
<!-- check to see if the font is roman -->
<test name="slant">
<const>roman</const>
</test>
<!-- check to see if the pattern requested non-roman -->
<test target="pattern" name="slant" compare="not_eq">
<const>roman</const>
</test>
<!-- multiply the matrix to slant the font -->
<edit name="matrix" mode="assign">
<times>
<name>matrix</name>
<matrix><double>1</double><double>0.2</double>
<double>0</double><double>1</double>
</matrix>
</times>
</edit>
<!-- pretend the font is oblique now -->
<edit name="slant" mode="assign">
<const>oblique</const>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
Artificial bold for fonts without a bold version.
-->
<match target="font">
<!-- check to see if the pattern requested > "medium" -->
<test target="pattern" name="weight" compare="more">
<const>medium</const>
</test>
<!-- pretend the font is bold now -->
<edit name="weight" mode="assign">
<const>bold</const>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
Disable "Global Advance" for all mono spacing fonts.
-->
<match target="font">
<test name="spacing" compare="eq">
<const>mono</const>
</test>
<edit name="globaladvance" mode="assign">
<bool>false</bool>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
Enable "hinting & autohint" for all fonts.
-->
<match target="font">
<edit name="hinting" mode="assign">
<bool>true</bool>
</edit>
<edit name="autohint" mode="assign">
<bool>true</bool>
</edit>
</match>
<!--
Add by firefly@firefly.idv.tw
If you don't want to use emdebedbitmap first.
you can set this "embed" with false.
<match target="font">
<edit name="embed" mode="assign">
<bool>false</bool>
</edit>
</match>
-->
<config>
<!--
These are the default Unicode chars that are expected to be blank
in fonts. All other blank chars are assumed to be broken and
won't appear in the resulting charsets
-->
<blank>
<int>0x0020</int> <!-- SPACE -->
<int>0x00a0</int> <!-- NO-BREAK SPACE -->
<int>0x00ad</int> <!-- SOFT HYPHEN -->
<int>0x115f</int> <!-- HANGUL CHOSEONG FILLER -->
<int>0x1160</int> <!-- HANGUL JUNGSEONG FILLER -->
<int>0x1680</int> <!-- OGHAM SPACE MARK -->
<int>0x2000</int> <!-- EN QUAD -->
<int>0x2001</int> <!-- EM QUAD -->
<int>0x2002</int> <!-- EN SPACE -->
<int>0x2003</int> <!-- EM SPACE -->
<int>0x2004</int> <!-- THREE-PER-EM SPACE -->
<int>0x2005</int> <!-- FOUR-PER-EM SPACE -->
<int>0x2006</int> <!-- SIX-PER-EM SPACE -->
<int>0x2007</int> <!-- FIGURE SPACE -->
<int>0x2008</int> <!-- PUNCTUATION SPACE -->
<int>0x2009</int> <!-- THIN SPACE -->
<int>0x200a</int> <!-- HAIR SPACE -->
<int>0x200b</int> <!-- ZERO WIDTH SPACE -->
<int>0x200c</int> <!-- ZERO WIDTH NON-JOINER -->
<int>0x200d</int> <!-- ZERO WIDTH JOINER -->
<int>0x200e</int> <!-- LEFT-TO-RIGHT MARK -->
<int>0x200f</int> <!-- RIGHT-TO-LEFT MARK -->
<int>0x2028</int> <!-- LINE SEPARATOR -->
<int>0x2029</int> <!-- PARAGRAPH SEPARATOR -->
<int>0x202a</int> <!-- LEFT-TO-RIGHT EMBEDDING -->
<int>0x202b</int> <!-- RIGHT-TO-LEFT EMBEDDING -->
<int>0x202c</int> <!-- POP DIRECTIONAL FORMATTING -->
<int>0x202d</int> <!-- LEFT-TO-RIGHT OVERRIDE -->
<int>0x202e</int> <!-- RIGHT-TO-LEFT OVERRIDE -->
<int>0x202f</int> <!-- NARROW NO-BREAK SPACE -->
<int>0x205f</int> <!-- MEDIUM MATHEMATICAL SPACE -->
<int>0x2060</int> <!-- WORD JOINER -->
<int>0x2061</int> <!-- FUNCTION APPLICATION -->
<int>0x2062</int> <!-- INVISIBLE TIMES -->
<int>0x2063</int> <!-- INVISIBLE SEPARATOR -->
<int>0x206A</int> <!-- INHIBIT SYMMETRIC SWAPPING -->
<int>0x206B</int> <!-- ACTIVATE SYMMETRIC SWAPPING -->
<int>0x206C</int> <!-- INHIBIT ARABIC FORM SHAPING -->
<int>0x206D</int> <!-- ACTIVATE ARABIC FORM SHAPING -->
<int>0x206E</int> <!-- NATIONAL DIGIT SHAPES -->
<int>0x206F</int> <!-- NOMINAL DIGIT SHAPES -->
<int>0x3000</int> <!-- IDEOGRAPHIC SPACE -->
<int>0x3164</int> <!-- HANGUL FILLER -->
<int>0xfeff</int> <!-- ZERO WIDTH NO-BREAK SPACE -->
<int>0xffa0</int> <!-- HALFWIDTH HANGUL FILLER -->
<int>0xfff9</int> <!-- INTERLINEAR ANNOTATION ANCHOR -->
<int>0xfffa</int> <!-- INTERLINEAR ANNOTATION SEPARATOR -->
<int>0xfffb</int> <!-- INTERLINEAR ANNOTATION TERMINATOR -->
</blank>
<!--
Rescan configuration every 30 seconds when FcFontSetList is called
-->
<rescan>
<int>30</int>
</rescan>
<!--
Add by Firefly (firefly@firefly.idv.tw)
Output non English/Latin family name.
-->
<other_family>
<bool>true</bool>
</other_family>
</config>
</fontconfig>
对于fonts.conf文件我想做如说明,其中<alias></alias>这对标签是为一族字体定义一个相同的别名,这样我们在应用程序中选择字体的时候就可以选择这个别名,这样做一个很大的好处就是当一族字体其中的一种字体不存在或者无法工作(如无法显示汉字)时可以用其它字体来代替它。显然,这个fonts.conf文件定义了3个族的字体,他们分别是:serif sans-serif monospace ,这三个族字体可以发现在应用程序的字体选择中都有,选择了他们其实就是选择了这一族字体,并且通过fontconfig来起作用。再来看看我所修改的地方,由于默认的字体要不不能显示中文,要不就是很不好看,所以我们要加入比较好的字体,比如Tahoma和SimSun,其中前者用来显示英文,后者用来显示中文。特别注意的是,我们加入这两个字体的<family></family>标签的时候,都是把Tahoma和 SimSun放在该族字体的最前面,并把Tahoma放在SimSun的前面,这样做就是告诉fontconf要优先使用Tahoma来进行显示,当遇到 Tahoma无法显示时(如中文)就要用SimSun来显示,两者的顺序切不能颠倒。有些朋友美化后报告说程序中英文字体间隔过大,其原因之一就是可能因为颠倒了两者,把汉字字体放到了前面,那么系统优先使用这些字体,由于大多数汉字字体每个字都是等宽的,就会造成英文字体间隔过大。其它内容可以参考上面的参考文章。
我们又要回到/etc/X11/XF86config文件做点修改:(把Section "Module"部分修改为下面这个样子)
Section "Module"
Load "dbe"
Load "extmod"
Load "fbdevhw"
Load "glx"
Load "record"
Load "xtt"
# Load "freetype"
Load "type1"
# Load "dri"
EndSection
即我使用的xtt来进行字体效果渲染,大家也可以使用freetype,但是不推荐同时使用两者。我在美化过程中发现如果使用freetype的话,一些X程序的英文字体会间隔过大,这是freetype的问题,解决办法应该是修改freetype源码中的某些预定义常量然后重新编译。
同样,对于GTK2的程序也有对应的资源配置文件/etc/gtk-2.0/gtkrc,大家可以加入以下一段:
style "user-font"
{
font_name="Tahoma 9"
}
class "*" style "user-font"
然后执行下面的命令
[root@localhost root]# cp /usr/lib/libXft.so* /usr/X11R6/lib
KDE程序可以通过以下命令来配置
[root@localhost root]# qtconfig
重启X,应该可以看到美化生效了吧。
我使用的是gnome桌面(为什么?$@#%@#^^&**),所以进入后可以如下设置字体:(大家可以按照自己的喜好试试)
(见贴图)
关xmms的汉字显示问题,我在这里重复提一下,前面也有很多解决方法。在首选项的字体中如下填入
播放清单
-adobe-helvetica-medium-r-*-*-12-*,-misc-simsun-medium-r-normal-*-12-*-*-*-c-*-gb2312.1980-0
主窗口
-adobe-helvetica-medium-r-*-*-12-*,-misc-simsun-medium-r-normal-*-12-*-*-*-c-*-gb2312.1980-0
即要xmms优先用helvetica显示英文,用simsun显示中文,大家也可以换自己喜欢的。
还有一个有用的工具xfontsel,相信对大家一定有用,运行一下就知道是什么啦。
我的美化也有不足之处,也请大家提出一些建议,在mozilla中,粗体和斜体都可以被正常显示,而且个人感觉效果不错,但是在 OpenOffice中,除了少数英文字体能够被显示粗体和斜体外,其它字体(包括汉字)都无法显示粗体和斜体,我也正在研究中,不知道大家有什么好的解决方法没。
总结:学习linux的过程中就是要多动手,多实验,多请教,在挫折中不断前进。(不要扔鸡蛋,有禽流感噢。^_^)
有任何问题大家可以和我联系(li_zy@eyou.com),本文基本上都是前人的成果,所以我没有CopyRight,呵呵
感谢 linuxsir.org linuxfans.org bbs.edu.cn bbs.whnet.edu.cn