<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar/8638045102788407707?origin\x3dhttp://micro1o.blogspot.com', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

(转贴)ubuntu 8.10字体配置大略

Ironflower
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://ironflower.blogbus.com/logs/31662528.html


我写这篇东西源自长久以来按图索骥的配置字体,昨天登录时试着把locale改成中文,结果字体变成了最难看的那种。非常不爽,只好开始用font关键字来找配置。运气好,发现所有的字体配置信息都在手册FONTS-CONF(5)里。

在线版本在http://fontconfig.org/fontconfig-user.html,从风格来看fontconfig应该是freedesktp的一部分。本地的手册:

$ man fonts-config

手册是这么说的:

--------------------------------------

/etc/fonts/fonts.conf
/etc/fonts/fonts.dtd
/etc/fonts/conf.d
~/.fonts.conf


Fontconfig是一个设计用来提供系统范围内的字体设置,定制和应用程序访问的库。

它包含两个基本部分:
1、配置模块:从XML文件生成内部格式的配置
2、匹配模块:接受字体模式并返回最接近的字体

----------------------------------------

我是懒人加上手册太长,知道这两点后所以决定猜测具体的配置过程。

/etc/fonts/fonts.conf是字体配置的总入口,如里面注释所说,没有特别原因不改为妙。来看看内容。

<dir>/usr/share/fonts</dir>
<dir>~/.fonts</dir>


这里很显然,是我们字体存放目录,而且会递归的扫描子目录。我们自己的可以放在~/.fonts里 ;-P

<cachedir>/var/cache/fontconfig</cachedir>


放缓存的目录。。。恩,什么的缓存呢?目录名为fontconfig,应该是这些XML配置文件的缓存吧,而且既然手册里说把XML转化为内部的配置,缓存文件应该用的就是内部格式。注意到/var/cache/fontconfig里的文件数目正好和/etc/fonts/conf.d里的文件数目相等,恩,猜测更有信心了:)

d@onepiece:~$ ls .fontconfig/
cabbd14511b9e8a55e92af97fb3a0461-x86.cache-2
d@onepiece:~$ ls /var/cache/fontconfig/cabbd14511b9e8a55e92af97fb3a0461-x86.cache-2


上面的说明了用户级别的配置缓存放在~/.fontconfig里,而系统级别的在这些系统字体配置文件被改动后,自动生成放在/var/cache /fontconfig中。如果在字体设置的界面中改变了什么东西的话,放在~/.fontconfig里。diff上面两个文件,完全相同。

不过此缓存和另一个命令:fc-cache -s -v(刷新字体缓存)做的事情不一样,见fc-cache手册。

<!--
  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>


这段有注释,说是把已被废弃使用的mono(字体别名)用monospace代替,恩,为了怕万一某些程序还是编码了老的别名进去,做个防护处理,把有可能的老别名统一替换为新别名。这是个很有代表性的匹配。

<!--
  Load local system customization file
-->
        <include ignore_missing="yes">conf.d</include>


这个对我们很重要,需要定制的内容都放在这个目录下。

<!--
  Rescan configuration every 30 seconds when FcFontSetList is called
 -->
                <rescan>
                        <int>30</int>
                </rescan>


每隔30自动刷新一遍,也就是说改动了某个配置文件会最多30秒后自动生效(我的conf.avail目录里有个多余的文件,把它删了,过了会儿屏幕闪了下,恩,说明重读配置了;-)

我们看那个/etc/fonts/conf.d目录,这个目录里都是指向/etc/fonts/conf.avail里文件的符号链接。这样可以灵活的决定包括哪个,排除哪儿,只要新建或者删除链接就行了。

读README总是个好习惯,告诉我们这是按照字母顺序一个个包括进去的,后包括的应该会覆盖前面的配置-至少对匹配来说,把一个匹配的模式想成一个哈希表的键?这点其实对实际配置意义不大。

 Files begining with:   Contain:
 
 00 through 09          Font directories
 10 through 19          system rendering defaults (AA, etc)
 20 through 29          font rendering options
 30 through 39          family substitution
 40 through 49          generic identification, map family->generic
 50 through 59          alternate config file loading
 60 through 69          generic aliases, map generic->family
 70 through 79          select font (adjust which fonts are available)
 80 through 89          match target="scan" (modify scanned patterns)
 90 through 99          font synthesis


我们挑典型来看。

00-09:定义字体目录的,在我的8.10系统上没有,前面都定义完了

10-19:系统渲染的默认配置

有五个文件:

10-antialias.conf
10-hinting.conf
10-hinting-medium.conf
10-no-sub-pixel.conf
11-lcd-filter-lcddefault.conf

这基本对应菜单的System->Preferences->Appearance-> "Fonts" 的"Rendering"配置,不过改动界面里的,我们改动了自己家目录里的缓存,而不是这些系统文件。这些文件的内容也很容易理解。

20-29:字体渲染选项,随便看一个:20-unhint-small-vera.conf

其实里面的注释很清楚,不过还是具体看配置是咋样的。。

        <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>


用<test>来匹配了两个属性,都符合的话就把hinting关闭。。。

看来20-29是对特定字体的渲染设置的定制。要是有哪个字体不想使用默认的渲染设置(10-19里设置的),就在这里定制下。

30-39:字体家族替换

        <alias>
                <family>SimSun</family>
                <family>NSimSun</family>
                <family>SimSun-18030</family>
                <family>NSimSun-18030</family>
                <family>AR MingtiM GB</family>
                <accept><family>AR PL UMing CN</family></accept>
                <accept><family>AR PL ShanHeiSun Uni</family></accept>
        </alias>


上面的的片段里1。prefer,2。accept,3。default都行,这样如果match了Simsun别名,那么就会1放在match的别名里,2放在match的别名后,default放在最后。

40-49:字体的映射,好像44-wqy-zenhei.conf 放错了地方,这个应该放在20-29里。典型的是49-sansserif.conf。

        <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>


50-59:装载别的配置文件,在网上指南里常看到的language-selector.conf, ~/.fonts.conf,local.conf等。

60-69:别名,定义所有的别名。

70-79:调整哪些字体可以被用

80-89:这个需要了解<match target="scan">的用处,回头看。

90-99:字体综合,针对字体的配置,改动特定字体的配置。

----------------------------------------

话说回来,要改成用黑体,不管是STHeiti,或者WenQuanYi Zen Hei,只要改动69-language-selector-zh-cn.conf。把STHeiti/WenQuanYi Zen Hei如法炮制的放在AR PL UMing CN的前面。

对单纯的配置来说,这大概就行了。

标签: ,

You can leave your response or bookmark this post to del.icio.us by using the links below.
Comment | Bookmark | Go to end