X的字体配置和美化
- See the Xorg Font Documentation for full details.
- See the FreeType2 Project Page for details on the freetype X.org Module.
- See Optimal Use of Fonts on Linux for more information about fonts in Linux.
xorg.conf模块
- freetype - 为True Type (ttf, ttc), Type1 (pfa, pfb), CID (cid), CFF, Open Type, 点阵bitmap (bdf, pcf, snf), Windows (fnt), PFR, 和 Type42 字体提供支持
- type1 - 为Type1 (pfa, pfb) 和CID (cid) 字体提供支持
- speedo - 支持Bitstream Speedo (spd) 字体
- xtt - 为True Type (ttf, ttc) 字体提供支持 (conflicts with freetype)
- bitmap - 提供bitmap (bdf, pcf, snf) 的支持
如你所看到的,freetype提供了所有的支持.补充说明一点,xtt(或许应该是xft,这里依据原文)于freetype有冲突.
X.org字体路径和/etc/fonts/配置目录
xorg.conf字体路径
xorg.conf里面的字体路径是给非xft字体用的. 为大多数字体在这里指定路径是值得的. 那些不支持xft的程序会寻找X的字体路径.我个人来说,我在这里填写最少的字体路径-仅仅为了xterm和那一类程序使用.
/etc/fonts/配置目录
/etc/fonts下的配置文件 (fonts.conf and local.conf)是用来配置字体的(Xft fonts). fonts.conf 不应该被更改, 如果要更改应该改local.conf(系统全局) 或者 ~/.fonts.conf (用户自定义). 在/etc/fonts/conf.d目录下的文件都是以一个数字开头,还有.conf结尾的一个软链接.
在fonts.conf列出的目录会为字体配置而被fc-cache扫描 (/usr/share/fonts 和 ~/.fonts). 所有的字体都应该放在这些文件夹内. 如果安装一个新字体,运行fc-cache -fv会让改变生效.
添加新字体
当新字体被添加后,它们不过是系统里面的一些文件. 必须使用一些工具来告诉系统新字体已经被安装了.
/usr/bin/fc-cache
这样将会更新系统字体缓存, 当然是假设新字体能够被配置文件找到 (看上一节关于/etc/fonts部分)
/usr/bin/mkfontscale
/usr/bin/mkfontdir
ln -s /usr/X11R6/lib/X11/fonts/encodings/encodings.dir encodings.dir
这几个工具需要在含有新字体的目录内运行. mkfontscale创建一个fonts.scale文件, mkfontdir 则创建一个fonts.dir文件. 这两个文件被X服务所使用, 也仅仅需要当字体通过X.org的字体路径使用的时候运行.而encodings的软链接允许X服务使用这些新字体(支持相关编码情况下).所有这些完成后, 你会发现这个字体目录下有3个新文件 : fonts.scale, fonts.dir, and encodings.dir.
fc-list和xlsfont工具
这两个工具将在命令行下用不同方式列出所有可用字体. fc-list将列出所有配置过的字体,而xlsfont则会列出所有的X字体. 如果同时使用grep效果会非常好,例如: "xlsfonts || grep -i bitstream" 可以看到所有可用的bitstream字体.
一些字体的下载
- Arkpandora TrueType fonts - Replacements for Arial and Times New Roman.
- PPants Angular Font Collection-Small collection of Angular-styled fonts with a general width of six pixels.
- Profont-Programming font.
Goodies
LCD的ClearType补丁
http://bbs.archlinux.org/viewtopic.php?id=33955
我的字体像屎一样难看.我都配置好了,但是好像是我缺少好看字体.
建议你从pacman安装如下包来解决:
pacman -S ttf-ms-fonts ttf-cheapskate artwiz-fonts
另外一个方法是删除75/100dpi包然后安装Bitstream Vera.后者提供漂亮的等宽终端字体,也能是浏览网页字体更好看(至少是firefox里面这样):
pacman -Rns xorg-fonts-75dpi xorg-fonts-100dpi
pacman -S ttf-bitstream-vera
补充:中文用户,安装如下任意一个中文字体,带有很全的GBK字符集,需要打开community仓库
pacman -S wqy-bitmapfont 文泉驿点阵字体
pacman -S wqy-zenhei 文泉驿正黑字体
我有一些针对Gtk 2.2和以下版本编译的程序,字体仍然看起来很垃圾.
的确这个会发生.现在的Gtk程序默认开启了xft支持, 但是2.2字体以前就没有这样了. 也许这些程序应该升级到一个针对新Gtk的新版本了. 如果那不可能,那么就添加 export GDK_USE_XFT=1 到全局设置文件 (/etc/profile, /etc/profile.d/gnome.sh, ~/.xinitrc, 等,任选一个) 将会为老程序启用xft的支持.
我有的老的Qt基础的程序有同样的问题.
同上, 添加 export QT_XFT=true.
在用KDE桌面的时候,Gtk程序字体太小.
安装gtk-qt-engine:
pacman -Sy gtk-qt-engine
- 更改Gtk程序字体大小:`Control Center' -> `Appearance & Themes' -> `GTK Styles and Fonts'.
bytecode interpreter让我字体看起来很丑,但是我已经把它编译进去了,我需要重新编译么?
完全不需要. 只是Freetype内部的自动微调(auto-hinting)关闭了. 在某些distros(也许可以翻译成源)里面, bytecode interpreter 被编译进去而且默认开启了. 这样造成bytecode interpreter 替代了freetype的自动微调(autohinter) (这还是开发者比较得意的地方). 指定自动微调开启, 添加下面的段到/etc/fonts/local.conf 或者 ~/.fonts.conf
<match target="pattern">
<edit name="autohint" mode=
"assign">
<bool>true</bool>
</edit>
</match>
或者改变 /etc/fonts/conf.d目录, 即从conf.avail做一个10-autohint.conf的软链接到这里. 如下(第二个命令需要有超级用户权限).
cd /etc/fonts/conf.d
ln -s ../conf.avail/10-autohint.conf
问题: 我不明白,bytecode interpreter 会和自动微调(autohinter)冲突都有段时间了,所以我不知道为什么有人想要自动微调. 回答: 因为 bytecode interpreter 在2.3分支(branch)里面支持相当不好 . 这里有一个论坛帖子是关于这个的: http://bbs.archlinux.org/viewtopic.php?id=29976 那上面的代码让我的字体好看很多. 尽管我重启效果就会失效,我也不知道为什么.
自动微调(Autohint)运行的很好,但是我的字体的粗体就不行了,我怎样能针对粗体关闭它?
自动微调可以让字体很好看,但是有时也让字体变太宽. 特别是字体为粗体模式时尤其严重. 幸好你可以为粗体关闭微调,而为其他字体模式保留.
- First turn on autohinter (see above) and add the following to ~/.fonts.conf
<match target="font">
<test name="weight" compare=
"more">
<const>medium</const>
</test>
<edit name="autohint" mode=
"assign">
<bool>false</bool>
</edit>
</match>
我有一个使用DVI数据线的TFT/DFP/LCD显示器,字体看起来模糊不清晰
这是CRT和非CTR渲染的不同造成的. 为了解决这个问题,你应该开启次像素(sub-pixel)渲染. 编辑~/[[[.fonts.conf]]] 文件. 添加下面一小段开启用. 说明:这样并没有显示质量的提高,只是做了CRT显示器完成的一部分额外工作(NOTE that this will do nothing but a minor amount of extra work on CRTs and does not improve the display quality). 这里 const可能的值是- rgb, bgr, vrgb, bgrv, 等.
< !-- Enable sub-pixel rendering -->
<match target="font" >
<edit mode="assign" name="rgba" >
<const>rgb</const>
</edit>
</match>
我不希望我的字体在某些字号下反锯齿(或者叫边缘模糊 AA Antialiase).
一份例子是/etc/fonts/local.conf文件. 推荐这样做, 当然就像次像素渲染那一节一样写. 如果有任何改变,就应该改变 compare="less_eq" , 和<int>12</int>区域 - 这分别是渲染强弱和点大小.
<match target="pattern">
<test qual="any" name="size" compare="less_eq">
<int>12</int>
</test>
<edit name="antialias" mode="assign"><bool>false</bool></edit>
</match>
我使用MS的TrueType字体(verdana),想针对看起来有锯齿的大号字体开启反锯齿.
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="font" >
<test compare"more" name
"size" qual="any" >
<double>12</double>
</test>
<edit mode"assign" name
"antialias" >
<bool>true</bool>
</edit>
</match>
<match target="font" >
<test compare"more" name
"pixelsize" qual="any" >
<double>17</double>
</test>
<edit mode"assign" name
"antialias" >
<bool>true</bool>
</edit>
</match>
</fontconfig>
我想安装更多字体.
保存你的字体到一个目录然后到~/[[[.fonts.conf]]]添加路径
< !-- Additional font directories -->
<dir>/path/to/dir</dir>
我希望我的字体大小符合我的DPI设置.
照下面编辑~/[[[.fonts.conf]]]. 这个设置应该适合你xorg.conf里面的Dpi,或者startx命令. 使用xdpyinfo来查看你目前的DPI设置. 大多数人适合或者正在使用96或者100的值.应该依照这个文档Xorg DisplaySize/DPI来改变X的DPI值
<match target="pattern">
<edit name="dpi" mode=
"assign"><double>100</double></edit>
</match>
我不喜欢 <某个字体>希望用<另一个字体>替代它
最可靠的办法是同上面一样添加一段XML段落到 ~/.fonts.conf. 这会让Bitstream Vera Sans取代Helvetica:
<match target="pattern" name="family" >
<test name="family" qual="any" >
<string>Helvetica</string>
</test>
<edit mode="assign" name="family" >
<string>Bitstream Vera Sans</string>
</edit>
</match>
一个另类的办法是设置"更喜欢"字体,但这仅仅在原始字体不存在的时候生效,这样你设置的字体才能生效:
< !-- Replace Helvetica with Bitstream Vera Sans Mono -->
< !-- Note, an alias for Helvetica should already exist in default conf files -->
<alias>
<family>Helvetica</family>
<prefer><family>Bitstream Vera Sans Mono</family></prefer>
<default><family>fixed</family></default>
</alias>
我有一堆不想要的恶心的像素字体(pixel fonts)
只有两个字体你需要一定保留,否则X服务无法启动:'cursor' 和 'fixed', 他们都在/usr/share/fonts/misc目录. 如果你不想要除此之外所有的像素字体, 你可以删除那个目录下多数文件, 除了cursor.pcf.gz和所有类似9x18.pcf.gz或者9x18-ISO8859-1.pcf.gz. 我删除所有不需要字体后,misc目录还有大约337个文件, 所以如果你比这个数字少,那么在重启X之前你最好是还原删除的问题件.
译者补充:
- 我试过这种方法,不过我的文件是可以更少的,只需要保留cursor.pcf.gz和类似6x13- Iso8859-[1-10].pcf.gz就行了,没有实验能不能更少,其实没有必要删除这么多,系统还是会剩下某个字号的fiexd字体,可以利用上面提到的字体替换方法替换成你喜欢字体,避免任何程序调用.
- 如够你删除了所有文件,但是没有备份,那么可以
pacman -S xorg-fonts-misc
来重新安装这个字体,否则你的X是不能启动的,当然也可以解压你cache文件夹下相应包.
- 这种方法对于opera的中文字体难看问题有一定程度的解决
我的点阵字体被禁用了,我想使用它们.
默认的, fontconfig 2.3.2-4和更高版本会禁用点阵(bitmap)字体. 这个设置是被/etc/fonts/conf.d/10-no-bitmaps.conf管理的, 在更高版本里面是/etc/fonts/conf.d/10-bitmaps.conf. 启用点阵字体而且在升级fontconfig后也保持, 建立一个软链接从yes-bitmaps.conf到10-bitmaps.conf, 覆盖no-bitmaps.conf.
为没有粗斜体的字体构造粗体和斜体
Freetype已经具备这样的能力,但是如果不是程序要求,是不会这样作的 - 也就是说它自己无论如何也不会给正常字体添加粗斜体样式. 要是用这些样式,你需要手动编辑/usr/share/fonts/fonts.cache-1 (保留一份你的修改,因为fc-cache的更新会覆盖它). 假设你有一个字体叫Dupree:
"dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:....
复制这一行, 把 style=Regular改成style=Bold或者其他样式. 同时为斜体更改 slant=0 为 slant=100 , 为粗体更改weight=80为weight=200 (粗斜体则都更改):
"dupree.ttf" 0 "Dupree:style=Bold Italic:slant=100:weight=200:width=100:foundry=unknown:index=0:outline=True:....
添加必须的设置到~/.fonts.conf:
<match target="font">
<test name="family" qual="any">
<string>Dupree</string>
<!-- other fonts here .... -->
</test>
<test compare="more_eq" name="weight"><int>140</int></test>
<edit mode="assign" name="embolden"><bool>true</bool></edit>
</match>
<match target="font">
<test name="family" qual="any">
<string>Dupree</string>
<!-- other fonts here .... -->
</test>
<test compare="more_eq" name="slant"><int>80</int></test>
<edit mode="assign" name="matrix">
<times>
<name>matrix</name>
<matrix>
<double>1</double><double>0.2</double>
<double>0</double><double>1</double>
</matrix>
</times>
</edit>
</match>
(注意,现在你就能使用粗体了 - 或者把他们变得更粗)
~/.fonts.conf
一个网络开发者的.~/.fonts.conf,是论坛上来的. 备份你现有的这是,尝试一下.
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- the cathectic LCD tweaks, from linuxquestions.org,
http://www.linuxquestions.org/questions/showthread.php? postid=1361098#post1361098 -->
<fontconfig>
<!-- Disable sub-pixel rendering.
X detects it anyway, and if you set this as well, it just looks really horrible -->
<match target="font" >
<edit mode="assign" name="rgba" >
<const>none</const>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hintstyle">
<const>hintfull</const>
</edit>
</match>
<!-- The first part of the 'magic.'
This makes the fonts start to look nice,
but some of the shapes will be distorted, so hinting is needed still -->
<match target="font" >
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
<!-- Autohinter is not turned on automatically.
Only disable this if you have recompiled Freetype with the bytecode interpreter,
which is run automatically.<br /> -->
<match target="pattern" >
<edit mode="assign" name="autohint">
<bool>true</bool>
</edit>
</match>
<match target="font">
<test name="weight" compare="more">
<const>medium</const>
</test>
<edit name="autohint" mode="assign">
<bool>false</bool>
</edit>
</match>
<!-- Helvetica is a non true type font, and will look bad.
This replaces it with whatever is the default sans-serif font -->
<match target="pattern" name="family" >
<test name="family" qual="any" >
<string>Helvetica</string>
</test>
<edit mode="assign" name="family" >
<string>sans-serif</string>
</edit>
</match>
<dir>~/.fonts</dir>
</fontconfig>
http://blog.chinaunix.net/u2/71976/showart_1892342.html