Difference between revisions of "Font configuration (简体中文)"

From ArchWiki
Jump to: navigation, search
m (Fontconfig配置)
(flagged broken section links (interactive))
(Tag: wiki-scripts)
 
(59 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[[Category:X Server (简体中文)]]
+
[[Category:X server (简体中文)]]
 
[[Category:Fonts (简体中文)]]
 
[[Category:Fonts (简体中文)]]
[[en:Font Configuration]]
+
[[en:Font configuration]]
[[it:Font Configuration]]
+
[[it:Font configuration]]
[[ru:Font Configuration]]
+
[[ja:フォント設定]]
[[sr:Font Configuration]]
+
[[ru:Font configuration]]
[[tr:Yazıtipi_yapılandırması]]
+
[[sr:Font configuration]]
{{TranslationStatus (简体中文)|Font_Configuration|2012-10-20|229345}}
+
[[tr:Yazıtipi yapılandırması]]
 +
{{TranslationStatus (简体中文)|Font_Configuration|2014-06-07|229345}}
 
{{Translateme (简体中文)}}
 
{{Translateme (简体中文)}}
{{Article summary start|摘要}}
+
{{Related articles start (简体中文)}}
{{Article summary text|An overview of font configuration options and various techniques for improving the readability of fonts}}
+
{{Related2|Fonts (简体中文)|字体}}
{{Article summary heading|相关页面}}
+
{{Related|Java Runtime Environment Fonts}}
{{Article summary wiki|Fonts}}: Information on adding fonts and font recommendations
+
{{Related|MS Fonts}}
{{Article summary wiki|Java Runtime Environment Fonts}}: Fonts specific to Sun's Java machine
+
{{Related|Font configuration/Examples}}
{{Article summary wiki|MS Fonts}}: Adding Microsoft fonts and mimicking Windows' font settings
+
{{Related articles end}}
{{Article summary wiki|Font Configuration/fontconfig Examples}}
+
Fontconfig 是一个为应用程序提供可用 [[Fonts (简体中文)|字体]] 的程序库,也可用来配置字体渲染效果,参见{{Pkg|fontconfig}} 软件包和 [[Wikipedia:Fontconfig]]。Free type 库({{Pkg|freetype2}} 软件包)就是以此为配置基础来渲染字体。
{{Article summary end}}
+
  
Fontconfig是一个库,它被设计用来为应用程序提供可用[[Fonts (简体中文)|字体]],或者用来配置字体渲染效果,参见包{{Pkg|fontconfig}}和[[Wikipedia:Fontconfig]]。 Free type库({{Pkg|freetype2}}包)就是以此为配置基础来渲染字体。
+
尽管 Fontconfig 已经是当今 Linux 字体界的标准,但是仍有一部分应用使用更加原始的字体显示方法,[[X Logical Font Description]]。
  
尽管Fontconfig已经是当今Linux的标准库,但是仍有一部分应用程序构建在更加原始的字体分类法上:Xorg server配置。
+
Arch Linux 上的字体渲染包支持有字节码解释器(BCI)的''freetype2''。为了更好的字体渲染,特别是在 LCD 显示器上,一些补丁包也添加到库中,参见下面的 [[#补丁包]]。[[#Infinality]] 包同时支持自动微调和亚像素渲染,允许在无须重新编译的情况下微调LCD滤光器,而且在粗体字下自动微调仍然表现良好。
 
+
Arch Linux包含的字体渲染包支持有字节码解释器(BCI)的''freetype2''。为了更好的字体渲染,特别是在LCD显示器上,一些补丁包也添加到库中,参见下面的[[#补丁包]]。[[#Infinality]]包同时支持自动微调和亚像素渲染,允许在无须重新编译的情况下微调LCD滤光器,而且在粗体字下自动微调仍然表现良好。
+
  
 
==字体路径==
 
==字体路径==
Line 27: Line 25:
 
由于应用程序需要知道它们所使用的字体的位置,所以必须对字体做良好的编目,以便于应用程序更好更快的访问它们。
 
由于应用程序需要知道它们所使用的字体的位置,所以必须对字体做良好的编目,以便于应用程序更好更快的访问它们。
  
Fontconfig包含的字体路径是{{ic|/usr/share/fonts/}}和{{ic|~/.fonts/}}(Fontconfig会递归访问刚刚提到的目录)。为了简化管理和安装过程,当需要[[Fonts#Installation|添加字体]]时,推荐使用之前提到的路径。
+
Fontconfig包含的字体路径是{{ic|/usr/share/fonts/}}和{{ic|~/.fonts/}}(Fontconfig会递归访问上述目录)。为了简化管理和安装过程,当需要[[Fonts#Installation|添加字体]]时,推荐使用上述路径。
  
 
查看Fontconfig所包含的字体:
 
查看Fontconfig所包含的字体:
Line 52: Line 50:
 
==Fontconfig配置==
 
==Fontconfig配置==
  
Fontconfig的文档在[http://fontconfig.org/fontconfig-user.html fonts.conf]man页面中。
+
通过对{{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}的修改可以完成对某个用户的配置, 而对{{ic|/etc/fonts/local.conf}}的修改则可以完成对每一位用户的配置. 如果用户的单独配置和全局配置不同,系统优先使用前者这些文件共用相同的语法.
 
+
{{Note|配置文件和目录: {{ic|~/.fonts.conf}}, {{ic|~/.fonts.conf.d}} {{ic|~/.fontconfig/*.cache-*}} 从fontconfig 2.10.1开始已经被废弃([http://cgit.freedesktop.org/fontconfig/commit/?id=8c255fb185d5651b57380b0a9443001e8051b29d upstream commit]) 未来的版本也不会默认读取这些文件当作配置依据. 分别用 {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}, {{ic|$XDG_CONFIG_HOME/fontconfig/conf.d}} {{ic|$XDG_CACHE_HOME/fontconfig/*.cache-*}} 来代替.}}
Configuration can be done per-user through {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}, and globally with {{ic|/etc/fonts/local.conf}}.  The settings in the per-user configuration have precedence over the global configuration.  Both these files use the same syntax.
+
{{Note|Configuration files and directories: {{ic|~/.fonts.conf}}, {{ic|~/.fonts.conf.d}} and {{ic|~/.fontconfig/*.cache-*}} are deprecated since fontconfig 2.10.1 ([http://cgit.freedesktop.org/fontconfig/commit/?id=8c255fb185d5651b57380b0a9443001e8051b29d upstream commit]) and will not be read by default in the future versions of package. Use instead {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}, {{ic|$XDG_CONFIG_HOME/fontconfig/conf.d}} and {{ic|$XDG_CACHE_HOME/fontconfig/*.cache-*}} respectively.}}
+
  
Fontconfig gathers all its configurations in a central file ({{ic|/etc/fonts/fonts.conf}}).  This file is replaced during fontconfig updates and shouldn't be edited. Fontconfig-aware applications source this file to know available fonts and how they get rendered.  This file is a conglomeration of rules from the global configuration ({{ic|/etc/fonts/local.conf}}), the configured presets in {{ic|/etc/fonts/conf.d/}}, and the user configuration file ({{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}).
+
Fontconfig 把所有的配置都放在一个中心文件中 ({{ic|/etc/fonts/fonts.conf}}).  这个文件会在fontconfig更新时被替换,注意你不应该编辑这个文件. 字体设置重要的程序会引用这个文件以获得当前字体配置和渲染配置.这个文件是一系列配置规则的集合包括全局配置文件({{ic|/etc/fonts/local.conf}}), 预设的配置 {{ic|/etc/fonts/conf.d/}}, 和用户的配置文件 ({{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}).
  
{{Note|For some desktop environments (such as [[GNOME]] and [[KDE]]) using the ''Font Control Panel'' will automatically create or overwrite the user font configuration fileFor these desktop environments, it is best to match your already defined font configurations to get the expected behavior.}}
+
{{Note|有一些桌面环境 (比如说 [[GNOME]] [[KDE]]) 使用 ''Font Control Panel'' 会自动生成和重写用户字体配置文件对于这些桌面环境, 最好配合已定义的字体配置来得到需要的显示效果.}}
  
Fontconfig configuration files use [[Wikipedia:XML|XML]] format and need these headers:
+
配置文件使用[[Wikipedia:XML|XML]]格式并且需要一些格式头:
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 73: Line 69:
 
</nowiki>}}
 
</nowiki>}}
  
The configuration examples in this article omit these tags.
+
文中的配置示例省略了这些标签.
 +
 
 +
在线的字体配置请点击[http://wenq.org/cloud/fcdesigner_local.html 此处]。
  
 
===预设===
 
===预设===
  
There are presets installed in the directory {{ic|/etc/fonts/conf.avail}}. They can be enabled by creating [[Wikipedia:Symbolic link|symbolic link]]s to them, both per-user and globally, as described in {{ic|/etc/fonts/conf.d/README}}.  These presets will override matching settings in their respective configuration files.
+
预设配置放在目录{{ic|/etc/fonts/conf.avail}}. 当给它们创建了[[Wikipedia:Symbolic link|符号链接]], 这些配置就被激活了.不管是对某一个用户还是全局配置, 这一规则是相同的.在{{ic|/etc/fonts/conf.d/README}}中有描述这些预设会通过匹配它们原先它们的单独设置文件来覆盖配置.
  
For example, to enable sub-pixel RGB rendering globally:
+
举个例子,为了打开全局亚像素RGB渲染:
  
 
  # cd /etc/fonts/conf.d
 
  # cd /etc/fonts/conf.d
 
  # ln -s ../conf.avail/10-sub-pixel-rgb.conf
 
  # ln -s ../conf.avail/10-sub-pixel-rgb.conf
  
To do the same but instead for a per-user configuration:
+
为单个独立用户配置:
  
 
  $ mkdir $XDG_CONFIG_HOME/fontconfig/conf.d
 
  $ mkdir $XDG_CONFIG_HOME/fontconfig/conf.d
 
  $ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d
 
  $ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d
  
===反锯齿===
+
===抗锯齿===
  
[[Wikipedia:Font rasterization|Font rasterization]] converts vector font data to bitmap data so that it can be displayed. The result can appear jagged due to [[Wikipedia:Aliasing|aliasing]]. [[Wikipedia:Anti-aliasing|anti-aliasing]] is enabled by default and increases the apparent resolution of font edges.
+
[[Wikipedia:Font rasterization|字体光栅化]]将矢量字体数据转化为位图数据以显示在屏幕上. 最后的效果可能由于[[Wikipedia:Aliasing|走样]]会出现锯齿. [[Wikipedia:Anti-aliasing|抗锯齿]]默认被打开,这样可以增加字体边缘的分辨率.
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 103: Line 101:
 
===微调===
 
===微调===
  
[[Wikipedia:Font hinting|Font hinting]] (also known as instructing) is the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid, such as the pixel grid in a display. Fonts will not line up correctly without hinting until displays have 300 [[Wikipedia:Dots per inch|DPI]] or greater. Two types of hinting are available.
+
[[Wikipedia:Font hinting|字体微调]] (也叫做instructing) 是利用精确的指令来调整字体显示的轮廓,这样就可以用离散的网格来显示我们需要的线条, 比如说像素网格.字体在[[Wikipedia:Dots per inch|DPI]]达到300之前不可能正确的显示.我们有两种微调的方法可以用.
  
 
====字节码解释器(BCI)====
 
====字节码解释器(BCI)====
Using normal hinting, TrueType hinting instructions in the font are interpreted by freetype's Byte-Code Interpreter. This works best for fonts with good hinting instructions.
+
当用BCI方法时,TrueType字体里的指令就会被唤醒并用FreeTypes的解释器来渲染,这在自带良好微调指令的字体上工作的很好.
  
To enable normal hinting:
+
打开normal hinting:
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 119: Line 117:
  
 
====自动微调器====
 
====自动微调器====
Auto-discovery for hinting. This looks worse than normal hinting for fonts with good instructions, but better for those with poor or no instructions. The autohinter and subpixel rendering are not designed to work together and should not be used in combination.
+
自动微调器方法就是微调全自动并且忽视任何内嵌的微调指令,起初这种方法是缺省配置的,因为以前的TrueType2字体都是有专利保护限制,没办法用BCI方法微调,但是现在这些专利都已经过期,所以限制也就没有了,当然也就是没有多大意义用自动微调这种方法了。但是它对内嵌微调指令不完整或者干脆没有的字体非常管用,相对的,如果字体自身有良好的微调指令,这种方法就绝对不提倡了。现如今,一般字体都有不错的微调指令,所以自动微调器这种方法就没多大用武之地。
  
To enable auto-hinting:
+
打开自动微调(auto-hinting):
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 131: Line 129:
 
</nowiki>}}
 
</nowiki>}}
  
====微调字体====
+
====微调样式====
  
Hint style is the amount of influence the hinting mode has.  Hinting can be set to: {{ic|hintfull}}, {{ic|hintmedium}}, {{ic|hintslight}} and {{ic|hintnone}}. With BCI hinting, hintfull should work best for most fonts. With the autohinter, hintslight is recommended.
+
微调样式就是微调时可以采用的款式,包括{{ic|hintfull}}, {{ic|hintmedium}}, {{ic|hintslight}} 还有 {{ic|hintnone}}。至于效果,{{ic|hintslight}}可以较好的保持字体的形态但是在像素网格里的排列会有些模糊,{{ic|hintfull}}则相反,排列清晰但字体的体态就不慎清楚。所以如果用BCI微调法,就推荐用{{ic|hintfull}},自动微调的话就{{ic|hintslight}}了。
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 142: Line 140:
 
   </match>
 
   </match>
 
</nowiki>}}
 
</nowiki>}}
 +
 +
{{Note|Some applications, like [[GNOME|GNOME 3]] may [[#Troubleshooting|override default hinting settings.]]{{Broken section link}}}}
  
 
===亚像素渲染===
 
===亚像素渲染===
  
Subpixel rendering effectively triples the horizontal (or vertical) resolution for fonts by making use of subpixels. The autohinter and subpixel rendering are not designed to work together and should not be used in combination without the [[#Infinality]] patch set.
+
如今生产的显示器大部分用的是红绿蓝(RGB)规范,也有用'''BGR''', '''V-RGB''' (vertical), 或者 '''V-BGR'''规范的(具体什么类型可以[http://www.lagom.nl/lcd-test/subpixel.php 这里]查看)。为了正确显示字体,Fontconfig得知道你的显示器具体类型。
 
+
Most monitors manufactured today use the Red, Green, Blue (RGB) specification. Fontconfig will need to know your monitor type to be able to display your fonts correctly.
+
 
+
''RGB (most common), BGR, V-RGB (vertical), or V-BGR''
+
  
To enable subpixel rendering:
+
打开亚像素渲染:
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 161: Line 157:
 
</nowiki>}}
 
</nowiki>}}
  
If you notice unusual colors around font's borders, the wrong subpixel arrangement might be configured.  The [http://www.lagom.nl/lcd-test/subpixel.php Lagom subpixel layout test] web page can help identify it.
+
{{Note|Subpixel rendering effectively triples the horizontal (or vertical) resolution for fonts by making use of subpixels. The autohinter and subpixel rendering are not designed to work together and should not be used in combination without the [[#Infinality: the generic way|Infinality]]{{Broken section link}} patch set.}}
  
====LCD滤光器====
+
====LCD过滤器====
  
When using subpixel rendering, you should enable the LCD filter, which is designed to reduce colour fringing.  This is described under [http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html LCD filtering] in the FreeType 2 API reference.  Different options are described under [http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html#FT_LcdFilter FT_LcdFilter], and are illustrated by this [http://www.spasche.net/files/lcdfiltering/ LCD filter test] page.
+
当使用亚像素渲染时,你最好启用LCD过滤器,这个是设计用来减少彩色边纹现象的,具体解释参见FreeType 2 API参考里的[http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html LCD filtering]。它的各个不同选项的描述位于[http://www.freetype.org/freetype2/docs/reference/ft2-lcd_filtering.html#FT_LcdFilter FT_LcdFilter],具体实例看[http://www.spasche.net/files/lcdfiltering/ LCD filter test]
  
The {{ic|lcddefault}} filter will work for most users. Other filters are available that can be used in special situations: {{ic|lcdlight}}; a lighter filter ideal for fonts that look too bold or fuzzy, {{ic|lcdlegacy}}, the original Cairo filter; and {{ic|lcdnone}} to disable it entirely.
+
{{ic|lcddefault}}这个选项对大多数用户都适用,其他选项则都有某一特定的用途:{{ic|lcdlight}}对那些字体看起来太粗或者模糊的超管用,{{ic|lcdlegacy}}嘛可用来对付Cairo字体,而{{ic|lcdnone}}的意思则是完全禁用{{ic|LCD过滤器}}功能。
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 177: Line 173:
 
</nowiki>}}
 
</nowiki>}}
  
====高级LCD滤光器说明====
+
====高级LCD过滤器说明====
  
If the available, built-in LCD filters are not satisfactory, it is possible to tweak the font rendering very specifically by building a custom freetype2 package and modifying the hardcoded filters. The [[Arch Build System]] can be used to build and install packages from source.
+
如果对内置的{{ic|LCD过滤器}}不满意,那可以自己对字体渲染来一个360度微调,只要修改下硬编码了的过滤器|filters并创建一个自定义的freetype2软件包就可以了。[[Arch Build System]]就是用来从源文件创建并安装软件包的一个工具。
  
First, refresh the freetype2 PKGBUILD as root:
+
首先,以root用户刷新下freetype2的PKGBUILD文件:
  
 
  # abs extra/freetype2
 
  # abs extra/freetype2
  
This example uses {{ic|/var/abs/build}} as the build directory, substitute it according to your personal ABS setup. Download and extract the freetype2 package as a regular user:
+
{{Note|下面这个示例以{{ic|/var/abs/build}}作为编译目录,请根据各自的ABS设置值来替换。}}
 +
 
 +
然后切换回普通用户,下载并解压freetype2软件包:
  
 
  $ cd /var/abs/build
 
  $ cd /var/abs/build
Line 192: Line 190:
 
  $ makepkg -o
 
  $ makepkg -o
  
Edit the file {{ic|src/freetype-VERSION/src/base/ftlcdfil.c}} and look up the definition of the constant {{ic|default_filter[5]}}:
+
接着编辑一下{{ic|src/freetype-VERSION/src/base/ftlcdfil.c}}这个文件,看看{{ic|default_filter[5]}}这个变量是怎么定义的:
  
 
  static const FT_Byte  default_filter[5] =
 
  static const FT_Byte  default_filter[5] =
 
     { 0x10, 0x40, 0x70, 0x40, 0x10 };
 
     { 0x10, 0x40, 0x70, 0x40, 0x10 };
  
This constant defines a low-pass filter applied to the rendered glyph. Modify it as needed. Save the file, build and install the custom package:
+
上面这个变量定义了一个应用于rendered glyph的低通过滤器|filter,请根据需要修改,然后保存、创建并安装这个自定义软件包:
  
 
  $ makepkg -e
 
  $ makepkg -e
Line 203: Line 201:
 
  $ sudo pacman -U freetype2-VERSION-ARCH.pkg.tar.xz
 
  $ sudo pacman -U freetype2-VERSION-ARCH.pkg.tar.xz
  
Reboot or restart X. The lcddefault filter should now render fonts differently.
+
最后重启机器或者重启X服务器,{{ic|lcddefault}}这个过滤器字体渲染的效果应该就出来了。
  
 
===取消粗体字的自动微调功能===
 
===取消粗体字的自动微调功能===
  
The auto-hinter uses sophisticated methods for font rendering, but often makes bold fonts too wide. Fortunately, a solution can be turning off the autohinter for bold fonts while leaving it on for the rest:
+
{{ic|自动微调}}使用了很复杂的方法来渲染字体,但常常把粗体字弄得太宽了,好在有一个方法,可以让{{ic|自动微调}}在粗体字上不起作用的同时而不影响其他字体:
 
  ...
 
  ...
 
  <match target="font">
 
  <match target="font">
Line 221: Line 219:
 
===只对较大的字体打开反锯齿功能===
 
===只对较大的字体打开反锯齿功能===
  
''See also [http://sharpfonts.co.cc/ sharpfonts.co.cc] for related information.''
+
有些用户更偏爱锐利一点的渲染效果而不是反锯齿那样的:
 
+
Some users prefer the sharper rendering that anti-aliasing does not offer:
+
  
 
{{bc|<nowiki>
 
{{bc|<nowiki>
Line 253: Line 249:
 
</nowiki>}}
 
</nowiki>}}
  
===替换字体===
+
===字体替换===
  
The most reliable way to do this is to add an XML fragment similar to the one below. This will cause Bitstream Vera Sans to be used in place of Helvetica:
+
最可靠的方法是添加像下面那样的一个XML片段。关键点在于''使用“binding”属性可以有更好的效果'',例如在Firefox你可能只想替换字体但并不想改变被替换字体的属性。下面的例子演示的是Georgia如何被Ubuntu字体替换掉的:
 
  ...
 
  ...
<match target="pattern" name="family" >
+
  <match target="pattern">
    <test name="family" qual="any" >
+
    <test qual="any" name="family"><string>georgia</string></test>
        <string>Helvetica</string>
+
    <edit name="family" mode="assign" binding="same"><string>Ubuntu</string></edit>
    </test>
+
  </match>
    <edit name="family" mode="assign">
+
        <string>Bitstream Vera Sans</string>
+
    </edit>
+
</match>
+
 
  ...
 
  ...
An alternate approach is to set the "preferred" font, but ''this only works if the original font is not on the system'', in which case the one specified will be substituted:
+
另外一种方法是设置“优先”字体,但是''这只有在原字体系统缺失的情况下才有效'',这种情况真发生了的话,设定的字体就会把它换了:
 
  ...
 
  ...
 
  < !-- Replace Helvetica with Bitstream Vera Sans Mono -->
 
  < !-- Replace Helvetica with Bitstream Vera Sans Mono -->
Line 279: Line 271:
 
===禁用点阵字型===
 
===禁用点阵字型===
  
To disable bitmap fonts in fontconfig, use {{ic|70-no-bitmaps.conf}} (which is not placed by fontconfig by default):
+
想禁用点阵字体(这个经常是在因为字体缺失而被回滚使用,却导致字体被渲染得很像素化)可以使用{{ic|70-no-bitmaps.conf}}(fontconfig缺省情况没有内置这个文件):
  
 
  # cd /etc/fonts/conf.d
 
  # cd /etc/fonts/conf.d
Line 285: Line 277:
 
  # ln -s ../conf.avail/70-no-bitmaps.conf
 
  # ln -s ../conf.avail/70-no-bitmaps.conf
  
You may not need to remove {{ic|70-yes-bitmaps.conf}} if it does not exist. You can choose which fonts to replace bitmaps fonts with (Helvetica, Courier and Times bitmap mapts to TTF fonts) by:
+
下面的就一行效果也一样:
  
  # cd /etc/fonts/conf.d
+
  # ln -s /etc/fonts/conf.avail/70-no-bitmaps.conf /etc/fonts/conf.d/
# ln -s ../conf.avail/29-replace-bitmap-fonts.conf
+
  
To disable embedded bitmap fonts for a specific font:
+
可能你并没有{{ic|70-yes-bitmaps.conf}}这个文件,所以也就无须什么删除了。 利用下面这个配置文件,你就可以决定用什么字体来替换点阵字体了:
 +
 
 +
{{hc|~/.config/fontconfig/conf.d/29-replace-bitmap-fonts.conf|<nowiki>
 +
<?xml version="1.0"?>
 +
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 +
<fontconfig>
 +
    <!-- Replace generic bitmap font names by generic font families -->
 +
    <match target="pattern" name="family">
 +
        <test name="family" qual="any">
 +
            <string>Helvetica</string>
 +
        </test>
 +
        <edit mode="assign" name="family">
 +
            <string>Arial</string>
 +
            <string>Liberation Sans</string>
 +
            <string>sans-serif</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern" name="family">
 +
        <test name="family" qual="any">
 +
            <string>Courier</string>
 +
        </test>
 +
        <edit mode="assign" name="family">
 +
            <string>Courier New</string>
 +
            <string>Liberation Mono</string>
 +
            <string>monospace</string>
 +
        </edit>
 +
    </match>
 +
    <match target="pattern" name="family">
 +
        <test name="family" qual="any">
 +
            <string>Times</string>
 +
        </test>
 +
        <edit mode="assign" name="family">
 +
            <string>Times New Roman</string>
 +
            <string>Liberation Serif</string>
 +
            <string>serif</string>
 +
        </edit>
 +
    </match>
 +
</fontconfig>
 +
</nowiki>}}
 +
 
 +
<div id="EmbeddedBitmap">禁用所有字体里的点阵字型:<div>
 +
 
 +
{{hc|~/.config/fontconfig/conf.d/20-no-embedded.conf|<nowiki>
 +
<?xml version="1.0"?>
 +
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 +
<fontconfig>
 +
  <match target="font">
 +
    <edit name="embeddedbitmap" mode="assign">
 +
      <bool>false</bool>
 +
    </edit>
 +
  </match>
 +
</fontconfig>
 +
</nowiki>}}
 +
 
 +
只禁用特定字体里的点阵字型:
  
 
  <match target="font">
 
  <match target="font">
Line 299: Line 344:
 
  </match>
 
  </match>
  
===为不完善的字体构建粗体风格和意大利体风格===
+
=== 禁用点阵字体的缩放 ===
 +
 
 +
如果要禁用点阵字体的缩放功能(这个经常会把字搞得很模糊),请删除 {{ic|/etc/fonts/conf.d/10-scale-bitmap-fonts.conf}}.
 +
 
 +
===为不完善的字体构建粗体风格和斜体风格===
  
Freetype has the ability to automatically create ''italic'' and '''bold''' styles for fonts that do not have them, but only if explicitly required by the application. Given programs rarely send these requests, this section covers manually forcing generation of missing styles.
+
Freetype字体可以自动为没有''斜体'''''粗体'''的字体创建''斜体''和'''粗体''',但这只会在应用程序明确地提出这样请求下生效。但现有的程序很少会发出这样的请求,这版讲述如何手动强制生成缺少的字体风格。
  
Start by editing {{ic|/usr/share/fonts/fonts.cache-1}} as explained below. Store a copy of the modifications on another file, because a font update with {{ic|fc-cache}} will overwrite {{ic|/usr/share/fonts/fonts.cache-1}}.
+
按照如下描述编辑{{ic|/usr/share/fonts/fonts.cache-1}}。因为执行{{ic|fc-cache}}时会覆盖{{ic|/usr/share/fonts/fonts.cache-1}},所以编辑前请先备份{{ic|/usr/share/fonts/fonts.cache-1}}到其他地方。
  
Assuming the Dupree font is installed:
+
假设已经安装了Dupree字体:
 
  "dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:''etc...''
 
  "dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:''etc...''
  
Duplicate the line, change {{ic|<nowiki>style=Regular</nowiki>}} to {{ic|<nowiki>style=Bold</nowiki>}} or any other style. Also change {{ic|<nowiki>slant=0</nowiki>}} to {{ic|<nowiki>slant=100</nowiki>}} for italic, {{ic|<nowiki>weight=80</nowiki>}} to {{ic|<nowiki>weight=200</nowiki>}} for bold, or combine them for '''''bold italic''''':
+
复制上面一行,并将{{ic|<nowiki>style=Regular</nowiki>}}改为{{ic|<nowiki>style=Bold</nowiki>}}或者其他你想要的字体风格(粗体用Bold,斜体用Italic)。同时,若需要斜体的将{{ic|<nowiki>slant=0</nowiki>}}改为{{ic|<nowiki>slant=100</nowiki>}},需要粗体的将{{ic|<nowiki>weight=80</nowiki>}} 改为{{ic|<nowiki>weight=200</nowiki>}},或者你可以将两句组合起来来生成'''''粗体和斜体'''''的风格,其中一个示例如下:
 
  "dupree.ttf" 0 "Dupree:style=Bold Italic:slant=100:weight=200:width=100:foundry=unknown:index=0:outline=True:''etc...''
 
  "dupree.ttf" 0 "Dupree:style=Bold Italic:slant=100:weight=200:width=100:foundry=unknown:index=0:outline=True:''etc...''
  
Now add necessary modifications to {{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}:
+
现在将以下内容添加到{{ic|$XDG_CONFIG_HOME/fontconfig/fonts.conf}}文件中:
 
{{bc|<nowiki>
 
{{bc|<nowiki>
 
...
 
...
Line 341: Line 390:
 
...
 
...
 
</nowiki>}}
 
</nowiki>}}
{{Tip| Use the value 'embolden' for existing bold fonts in order to make them even bolder.}}
+
{{小贴士| 使用了参数 'embolden' 可以令原来就存在粗体的字体变得更粗}}
  
 
===改变规则重定义机制===
 
===改变规则重定义机制===
  
Fontconfig processes files in {{ic|/etc/fonts/conf.d}} in reverse numerical order. This enables rules or files to override one another, but often confuses users about what file gets parsed last.
+
Fontconfig按照文件名中的数字顺序来处理{{ic|/etc/fonts/conf.d}}里的文件,这样子数值高的规则或者文件就可以覆盖掉低的,但是有时容易让人对什么文件最后处理产生疑惑。
 +
 
 +
依照下例所示改变一下顺序,以确保“个人配置文件”永远被最后处理:
  
To guarantee that personal settings take precedence over any other rules, change their ordering:
 
 
  # cd /etc/fonts/conf.d
 
  # cd /etc/fonts/conf.d
  # mv 50-user.conf 00-user.conf
+
  # mv 50-user.conf 99-user.conf
  
This change seems however to be unnecessary for the most of the cases, because a user is given enough control by default to set up own font preferences, hinting and antialiasing properties, alias new fonts to generic font families, etc.
+
上面这个更改在大部分情况下是非必要的,因为用户本来就被赋予了足够的控制权来设置他喜欢的字体属性、微调和反锯齿,以及把某个字体设置为一个普通字体家族的别名等等。
  
 
===fontconfig配置的例子===
 
===fontconfig配置的例子===
  
Example fontconfig configurations can be found on this [[Font_Configuration/fontconfig_Examples|page]].
+
Fongconfig的配置文件示例请参考这个[[Font configuration/Examples|页面]].
  
A simple starting point:
+
下面是一个简单的上手例子:
  
 
{{hc|/etc/fonts/local.conf|<nowiki>
 
{{hc|/etc/fonts/local.conf|<nowiki>
Line 398: Line 448:
  
 
===Infinality===
 
===Infinality===
{{Warning|1=Since the [http://www.archlinux.org/news/fontconfig-2101-update-manual-intervention-required/ Fontconfig 2.10.1 update], Infinality users will receive multiple warnings similar to:
 
{{ic|Fontconfig warning: "/etc/fonts/infinality/conf.d/60-group-non-tt-fonts.conf", line 483: Having multiple values in <test> isn't supported and may not works as expected}}
 
Rule adjustments are currently being worked on. See: [http://www.infinality.net/forum/viewtopic.php?f=2&t=254 this article] for more information.}}
 
 
 
The infinality patchset aims to greatly improve freetype2 font rendering. It adds multiple new capabilities.
 
The infinality patchset aims to greatly improve freetype2 font rendering. It adds multiple new capabilities.
  
*[http://www.infinality.net/blog/infinality-freetype-patches/ Home page].
+
* [http://www.infinality.net/blog/infinality-freetype-patches/ Home page]
*[http://www.infinality.net/forum/ Forum].
+
* [http://www.infinality.net/forum/ Forum]
 +
* [http://www.webupd8.org/2013/06/better-font-rendering-in-linux-with.html Short article about infinality (contains screenshots)]
  
 
Infinality's settings are all configurable at runtime via environment variables in {{ic|/etc/profile.d/infinality-settings.sh}}, and include the following:
 
Infinality's settings are all configurable at runtime via environment variables in {{ic|/etc/profile.d/infinality-settings.sh}}, and include the following:
Line 421: Line 468:
 
A number of presets are included and can be used by setting the USE_STYLE variable in {{ic|/etc/profile.d/infinality-settings.sh}}.
 
A number of presets are included and can be used by setting the USE_STYLE variable in {{ic|/etc/profile.d/infinality-settings.sh}}.
  
{{AUR|freetype2-infinality}} can be installed from the [[Arch User Repository|AUR]]. Additionally, if you are using {{pkg|lib32-freetype2}} from [multilib], replace it with {{AUR|lib32-freetype2-infinality}} from the AUR. The AUR also contains a Git version of freetype2 that builds the latest development snapshot of freetype2 with the Infinality patchset: {{AUR|freetype2-git-infinality}}, {{AUR|lib32-freetype2-git-infinality}}.
+
{{AUR|freetype2-infinality}} can be installed from the [[Arch User Repository|AUR]]. Additionally, if you are using {{pkg|lib32-freetype2}} from [multilib], replace it with {{AUR|lib32-freetype2-infinality}}{{Broken package link|{{aur-mirror|lib32-freetype2-infinality}}}} from the AUR. The AUR also contains a Git version of freetype2 that builds the latest development snapshot of freetype2 with the Infinality patchset: {{AUR|freetype2-infinality-git}}{{Broken package link|{{aur-mirror|freetype2-infinality-git}}}}, {{AUR|lib32-freetype2-infinality-git}}{{Broken package link|{{aur-mirror|lib32-freetype2-infinality-git}}}}.
  
 
It is recommended to also install {{AUR|fontconfig-infinality}} to enable selection of predefined font substitution styles and antialiasing settings, apart from the rendering settings of the engine itself. After doing so, you can select the font style (win7, winxp, osx, linux, ...) with:
 
It is recommended to also install {{AUR|fontconfig-infinality}} to enable selection of predefined font substitution styles and antialiasing settings, apart from the rendering settings of the engine itself. After doing so, you can select the font style (win7, winxp, osx, linux, ...) with:
Line 438: Line 485:
 
Ubuntu adds extra configurations, and occasionally patches to the font rendering libraries.
 
Ubuntu adds extra configurations, and occasionally patches to the font rendering libraries.
  
Install the patched packages from the [[Arch User Repository|AUR]], the package names are: {{AUR|freetype2-ubuntu}} {{AUR|fontconfig-ubuntu}} {{AUR|libxft-ubuntu}} {{AUR|cairo-ubuntu}}.
+
Install the patched packages from the [[Arch User Repository|AUR]], the package names are: {{AUR|freetype2-ubuntu}} {{AUR|fontconfig-ubuntu}} {{AUR|libxft-ubuntu}}{{Broken package link|{{aur-mirror|libxft-ubuntu}}}} {{AUR|cairo-ubuntu}}.
  
The global configuration will need to be added. See [[#Example fontconfig configurations]] for a starting point.
+
The global configuration will need to be added. See [[#Example fontconfig configurations]]{{Broken section link}} for a starting point.
  
 
===恢复到未打补丁的包===
 
===恢复到未打补丁的包===
Line 450: Line 497:
 
==没有fontconfig支持的应用程序==
 
==没有fontconfig支持的应用程序==
  
Some applications like [[URxvt]] will ignore fontconfig settings. This is very apparent when using the infinality patches which are heavily reliant on proper configuration. You can work around this by using {{ic|~/.Xresources}}, but it is not nearly as flexible as fontconfig. Example (see [[#Fontconfig configuration]] for explanations of the options):
+
Some applications like [[URxvt]] will ignore fontconfig settings. This is very apparent when using the infinality patches which are heavily reliant on proper configuration. You can work around this by using {{ic|~/.Xresources}}, but it is not nearly as flexible as fontconfig. Example (see [[#Fontconfig configuration]]{{Broken section link}} for explanations of the options):
  
 
{{hc|~/.Xresources|<nowiki>
 
{{hc|~/.Xresources|<nowiki>
Line 476: Line 523:
 
{{Note|To use the ''xdpyinfo'' command, you must install the package {{pkg|xorg-xdpyinfo}}.}}
 
{{Note|To use the ''xdpyinfo'' command, you must install the package {{pkg|xorg-xdpyinfo}}.}}
  
If the DPI is detected incorrectly (usually due to an incorrect monitor EDID), you can specify it manually in the Xorg configuration, see [[Xorg#Display Size and DPI]]. This is the recommended solution, but it may not work with buggy drivers.
+
If the DPI is detected incorrectly (usually due to an incorrect monitor EDID), you can specify it manually in the Xorg configuration, see [[Xorg#Display size and DPI]]. This is the recommended solution, but it may not work with buggy drivers.
  
 
Fontconfig will default to the Xft.dpi variable if it is set. Xft.dpi is usually set by desktop environments (usually to Xorg's DPI setting) or manually in {{ic|~/.Xdefaults}} or {{ic|~/.Xresources}}. Use xrdb to query for the value:
 
Fontconfig will default to the Xft.dpi variable if it is set. Xft.dpi is usually set by desktop environments (usually to Xorg's DPI setting) or manually in {{ic|~/.Xdefaults}} or {{ic|~/.Xresources}}. Use xrdb to query for the value:

Latest revision as of 15:31, 6 August 2016

翻译状态: 本文是英文页面 Font_Configuration翻译,最后翻译时间:2014-06-07,点击这里可以查看翻译后英文页面的改动。

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.

Fontconfig 是一个为应用程序提供可用 字体 的程序库,也可用来配置字体渲染效果,参见fontconfig 软件包和 Wikipedia:Fontconfig。Free type 库(freetype2 软件包)就是以此为配置基础来渲染字体。

尽管 Fontconfig 已经是当今 Linux 字体界的标准,但是仍有一部分应用使用更加原始的字体显示方法,X Logical Font Description

Arch Linux 上的字体渲染包支持有字节码解释器(BCI)的freetype2。为了更好的字体渲染,特别是在 LCD 显示器上,一些补丁包也添加到库中,参见下面的 #补丁包#Infinality 包同时支持自动微调和亚像素渲染,允许在无须重新编译的情况下微调LCD滤光器,而且在粗体字下自动微调仍然表现良好。

字体路径

由于应用程序需要知道它们所使用的字体的位置,所以必须对字体做良好的编目,以便于应用程序更好更快的访问它们。

Fontconfig包含的字体路径是/usr/share/fonts/~/.fonts/(Fontconfig会递归访问上述目录)。为了简化管理和安装过程,当需要添加字体时,推荐使用上述路径。

查看Fontconfig所包含的字体:

$ fc-list : file

参见man fc-list以获得更多输出格式方面的信息。

通过考察Xorg的log文件来检查Xorg包含的字体路径:

$ grep /fonts /var/log/Xorg.0.log
小贴士: 你也可以通过命令xset q检查Xorg包含的字体路径。

需要明确的是,Xorg不会像Fontconfig一样递归搜索/usr/share/fonts/目录。如果要增加一个目录,必须使用一个完整目录:

Section "Files"
    FontPath     "/usr/share/fonts/local/"
EndSection

如果你想把字体路径设置到每一位用户,你可以通过添加下面的配置代码到文件~/.xinitrc,这样可以将字体路径添加进或者移除出默认的路径中:

xset +fp /usr/share/fonts/local/           # Prepend a custom font path to Xorg's list of known font paths
xset -fp /usr/share/fonts/sucky_fonts/     # Remove the specified font path from Xorg's list of known font paths

如果要查看Xorg包含的字体,可以使用这个命令xlsfonts, 这个命令来自包xorg-xlsfonts

Fontconfig配置

通过对$XDG_CONFIG_HOME/fontconfig/fonts.conf的修改可以完成对某个用户的配置, 而对/etc/fonts/local.conf的修改则可以完成对每一位用户的配置. 如果用户的单独配置和全局配置不同,系统优先使用前者. 这些文件共用相同的语法.

Note: 配置文件和目录: ~/.fonts.conf, ~/.fonts.conf.d~/.fontconfig/*.cache-* 从fontconfig 2.10.1开始已经被废弃(upstream commit) 未来的版本也不会默认读取这些文件当作配置依据. 分别用 $XDG_CONFIG_HOME/fontconfig/fonts.conf, $XDG_CONFIG_HOME/fontconfig/conf.d$XDG_CACHE_HOME/fontconfig/*.cache-* 来代替.

Fontconfig 把所有的配置都放在一个中心文件中 (/etc/fonts/fonts.conf). 这个文件会在fontconfig更新时被替换,注意你不应该编辑这个文件. 字体设置重要的程序会引用这个文件以获得当前字体配置和渲染配置.这个文件是一系列配置规则的集合包括全局配置文件(/etc/fonts/local.conf), 预设的配置 /etc/fonts/conf.d/, 和用户的配置文件 ($XDG_CONFIG_HOME/fontconfig/fonts.conf).

Note: 有一些桌面环境 (比如说 GNOMEKDE) 使用 Font Control Panel 会自动生成和重写用户字体配置文件. 对于这些桌面环境, 最好配合已定义的字体配置来得到需要的显示效果.

配置文件使用XML格式并且需要一些格式头:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <!-- settings go here -->

</fontconfig>

文中的配置示例省略了这些标签.

在线的字体配置请点击此处

预设

预设配置放在目录/etc/fonts/conf.avail中. 当给它们创建了符号链接, 这些配置就被激活了.不管是对某一个用户还是全局配置, 这一规则是相同的.在/etc/fonts/conf.d/README中有描述. 这些预设会通过匹配它们原先它们的单独设置文件来覆盖配置.

举个例子,为了打开全局亚像素RGB渲染:

# cd /etc/fonts/conf.d
# ln -s ../conf.avail/10-sub-pixel-rgb.conf

为单个独立用户配置:

$ mkdir $XDG_CONFIG_HOME/fontconfig/conf.d
$ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d

抗锯齿

字体光栅化将矢量字体数据转化为位图数据以显示在屏幕上. 最后的效果可能由于走样会出现锯齿. 抗锯齿默认被打开,这样可以增加字体边缘的分辨率.

  <match target="font">
    <edit name="antialias" mode="assign">
      <bool>true</bool>
    </edit>
  </match>

微调

字体微调 (也叫做instructing) 是利用精确的指令来调整字体显示的轮廓,这样就可以用离散的网格来显示我们需要的线条, 比如说像素网格.字体在DPI达到300之前不可能正确的显示.我们有两种微调的方法可以用.

字节码解释器(BCI)

当用BCI方法时,TrueType字体里的指令就会被唤醒并用FreeTypes的解释器来渲染,这在自带良好微调指令的字体上工作的很好.

打开normal hinting:

  <match target="font">
    <edit name="hinting" mode="assign">
      <bool>true</bool>
    </edit>
  </match>

自动微调器

自动微调器方法就是微调全自动并且忽视任何内嵌的微调指令,起初这种方法是缺省配置的,因为以前的TrueType2字体都是有专利保护限制,没办法用BCI方法微调,但是现在这些专利都已经过期,所以限制也就没有了,当然也就是没有多大意义用自动微调这种方法了。但是它对内嵌微调指令不完整或者干脆没有的字体非常管用,相对的,如果字体自身有良好的微调指令,这种方法就绝对不提倡了。现如今,一般字体都有不错的微调指令,所以自动微调器这种方法就没多大用武之地。

打开自动微调(auto-hinting):

  <match target="font">
    <edit name="autohint" mode="assign">
      <bool>true</bool>
    </edit>
  </match>

微调样式

微调样式就是微调时可以采用的款式,包括hintfull, hintmedium, hintslight 还有 hintnone。至于效果,hintslight可以较好的保持字体的形态但是在像素网格里的排列会有些模糊,hintfull则相反,排列清晰但字体的体态就不慎清楚。所以如果用BCI微调法,就推荐用hintfull,自动微调的话就hintslight了。

  <match target="font">
    <edit name="hintstyle" mode="assign">
      <const>hintfull</const>
    </edit>
  </match>
Note: Some applications, like GNOME 3 may override default hinting settings.[broken link: invalid section]

亚像素渲染

如今生产的显示器大部分用的是红绿蓝(RGB)规范,也有用BGR, V-RGB (vertical), 或者 V-BGR规范的(具体什么类型可以这里查看)。为了正确显示字体,Fontconfig得知道你的显示器具体类型。

打开亚像素渲染:

  <match target="font">
    <edit name="rgba" mode="assign">
      <const>rgb</const>
    </edit>
  </match>
Note: Subpixel rendering effectively triples the horizontal (or vertical) resolution for fonts by making use of subpixels. The autohinter and subpixel rendering are not designed to work together and should not be used in combination without the Infinality[broken link: invalid section] patch set.

LCD过滤器

当使用亚像素渲染时,你最好启用LCD过滤器,这个是设计用来减少彩色边纹现象的,具体解释参见FreeType 2 API参考里的LCD filtering。它的各个不同选项的描述位于FT_LcdFilter,具体实例看LCD filter test

lcddefault这个选项对大多数用户都适用,其他选项则都有某一特定的用途:lcdlight对那些字体看起来太粗或者模糊的超管用,lcdlegacy嘛可用来对付Cairo字体,而lcdnone的意思则是完全禁用LCD过滤器功能。

  <match target="font">
    <edit mode="assign" name="lcdfilter">
      <const>lcddefault</const>
    </edit>
  </match>

高级LCD过滤器说明

如果对内置的LCD过滤器不满意,那可以自己对字体渲染来一个360度微调,只要修改下硬编码了的过滤器|filters并创建一个自定义的freetype2软件包就可以了。Arch Build System就是用来从源文件创建并安装软件包的一个工具。

首先,以root用户刷新下freetype2的PKGBUILD文件:

# abs extra/freetype2
Note: 下面这个示例以/var/abs/build作为编译目录,请根据各自的ABS设置值来替换。

然后切换回普通用户,下载并解压freetype2软件包:

$ cd /var/abs/build
$ cp -r ../extra/freetype2 .
$ cd freetype2
$ makepkg -o

接着编辑一下src/freetype-VERSION/src/base/ftlcdfil.c这个文件,看看default_filter[5]这个变量是怎么定义的:

static const FT_Byte  default_filter[5] =
    { 0x10, 0x40, 0x70, 0x40, 0x10 };

上面这个变量定义了一个应用于rendered glyph的低通过滤器|filter,请根据需要修改,然后保存、创建并安装这个自定义软件包:

$ makepkg -e
$ sudo pacman -Rd freetype2
$ sudo pacman -U freetype2-VERSION-ARCH.pkg.tar.xz

最后重启机器或者重启X服务器,lcddefault这个过滤器字体渲染的效果应该就出来了。

取消粗体字的自动微调功能

自动微调使用了很复杂的方法来渲染字体,但常常把粗体字弄得太宽了,好在有一个方法,可以让自动微调在粗体字上不起作用的同时而不影响其他字体:

...
<match target="font">
    <test name="weight" compare="more">
        <const>medium</const>
    </test>
    <edit name="autohint" mode="assign">
        <bool>false</bool>
    </edit>
</match>
...

只对较大的字体打开反锯齿功能

有些用户更偏爱锐利一点的渲染效果而不是反锯齿那样的:

...
<match target="font">
    <edit name="antialias" mode="assign">
        <bool>false</bool>
    </edit>
</match>

<match target="font" >
    <test name="size" qual="any" compare="more">
        <double>12</double>
    </test>
    <edit name="antialias" mode="assign">
        <bool>true</bool>
    </edit>
</match>

<match target="font" >
    <test name="pixelsize" qual="any" compare="more">
        <double>16</double>
    </test>
    <edit name="antialias" mode="assign">
        <bool>true</bool>
    </edit>
</match>
...

字体替换

最可靠的方法是添加像下面那样的一个XML片段。关键点在于使用“binding”属性可以有更好的效果,例如在Firefox你可能只想替换字体但并不想改变被替换字体的属性。下面的例子演示的是Georgia如何被Ubuntu字体替换掉的:

...
 <match target="pattern">
   <test qual="any" name="family"><string>georgia</string></test>
   <edit name="family" mode="assign" binding="same"><string>Ubuntu</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>
...

禁用点阵字型

想禁用点阵字体(这个经常是在因为字体缺失而被回滚使用,却导致字体被渲染得很像素化)可以使用70-no-bitmaps.conf(fontconfig缺省情况没有内置这个文件):

# cd /etc/fonts/conf.d
# rm 70-yes-bitmaps.conf
# ln -s ../conf.avail/70-no-bitmaps.conf

下面的就一行效果也一样:

# ln -s /etc/fonts/conf.avail/70-no-bitmaps.conf /etc/fonts/conf.d/

可能你并没有70-yes-bitmaps.conf这个文件,所以也就无须什么删除了。 利用下面这个配置文件,你就可以决定用什么字体来替换点阵字体了:

~/.config/fontconfig/conf.d/29-replace-bitmap-fonts.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <!-- Replace generic bitmap font names by generic font families -->
    <match target="pattern" name="family">
        <test name="family" qual="any">
            <string>Helvetica</string>
        </test>
        <edit mode="assign" name="family">
            <string>Arial</string>
            <string>Liberation Sans</string>
            <string>sans-serif</string>
        </edit>
    </match>
    <match target="pattern" name="family">
        <test name="family" qual="any">
            <string>Courier</string>
        </test>
        <edit mode="assign" name="family">
            <string>Courier New</string>
            <string>Liberation Mono</string>
            <string>monospace</string>
        </edit>
    </match>
    <match target="pattern" name="family">
        <test name="family" qual="any">
            <string>Times</string>
        </test>
        <edit mode="assign" name="family">
            <string>Times New Roman</string>
            <string>Liberation Serif</string>
            <string>serif</string>
        </edit>
    </match>
</fontconfig>
禁用所有字体里的点阵字型:
~/.config/fontconfig/conf.d/20-no-embedded.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="font">
    <edit name="embeddedbitmap" mode="assign">
      <bool>false</bool>
    </edit>
  </match>
</fontconfig>

只禁用特定字体里的点阵字型:

<match target="font">
  <test qual="any" name="family">
    <string>Monaco</string>
  </test>
  <edit name="embeddedbitmap"><bool>false</bool></edit>
</match>

禁用点阵字体的缩放

如果要禁用点阵字体的缩放功能(这个经常会把字搞得很模糊),请删除 /etc/fonts/conf.d/10-scale-bitmap-fonts.conf.

为不完善的字体构建粗体风格和斜体风格

Freetype字体可以自动为没有斜体粗体的字体创建斜体粗体,但这只会在应用程序明确地提出这样请求下生效。但现有的程序很少会发出这样的请求,这版讲述如何手动强制生成缺少的字体风格。

按照如下描述编辑/usr/share/fonts/fonts.cache-1。因为执行fc-cache时会覆盖/usr/share/fonts/fonts.cache-1,所以编辑前请先备份/usr/share/fonts/fonts.cache-1到其他地方。

假设已经安装了Dupree字体:

"dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:etc...

复制上面一行,并将style=Regular改为style=Bold或者其他你想要的字体风格(粗体用Bold,斜体用Italic)。同时,若需要斜体的将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:etc...

现在将以下内容添加到$XDG_CONFIG_HOME/fontconfig/fonts.conf文件中:

...
<match target="font">
    <test name="family" qual="any">
        <string>Dupree</string>
         <!-- other fonts here .... -->
     </test>
     <test name="weight" compare="more_eq"><int>140</int></test>
     <edit name="embolden" mode="assign"><bool>true</bool></edit>
</match>

<match target="font">
    <test name="family" qual="any">
        <string>Dupree</string>
        <!-- other fonts here .... -->
    </test>
    <test name="slant" compare="more_eq"><int>80</int></test>
    <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>
</match>
...
小贴士: 使用了参数 'embolden' 可以令原来就存在粗体的字体变得更粗

改变规则重定义机制

Fontconfig按照文件名中的数字顺序来处理/etc/fonts/conf.d里的文件,这样子数值高的规则或者文件就可以覆盖掉低的,但是有时容易让人对什么文件最后处理产生疑惑。

依照下例所示改变一下顺序,以确保“个人配置文件”永远被最后处理:

# cd /etc/fonts/conf.d
# mv 50-user.conf 99-user.conf

上面这个更改在大部分情况下是非必要的,因为用户本来就被赋予了足够的控制权来设置他喜欢的字体属性、微调和反锯齿,以及把某个字体设置为一个普通字体家族的别名等等。

fontconfig配置的例子

Fongconfig的配置文件示例请参考这个页面.

下面是一个简单的上手例子:

/etc/fonts/local.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <match target="font">
  
  <edit mode="assign" name="rgba">
   <const>rgb</const>
  </edit>

  <edit mode="assign" name="hinting">
   <bool>true</bool>
  </edit>

  <edit mode="assign" name="hintstyle">
   <const>hintfull</const>
  </edit>

  <edit mode="assign" name="antialias">
   <bool>true</bool>
  </edit>

  <edit mode="assign" name="lcdfilter">
    <const>lcddefault</const>
  </edit>
 
 </match>
</fontconfig>

补丁包

These patched packages are available in the AUR. A few considerations:

  • Configuration is usually necessary.
  • The new font rendering will not kick in until applications restart.
  • Applications which statically link to a library will not be affected by patches applied to the system library.

Infinality

The infinality patchset aims to greatly improve freetype2 font rendering. It adds multiple new capabilities.

Infinality's settings are all configurable at runtime via environment variables in /etc/profile.d/infinality-settings.sh, and include the following:

  • Emboldening Enhancement: Disables Y emboldening, producing a much nicer result on fonts without bold versions. Works on native TT hinter and autohinter.
  • Auto-Autohint: Automatically forces autohint on fonts that contain no TT instructions.
  • Autohint Enhancement: Makes autohint snap horizontal stems to pixels. Gives a result that appears like a well-hinted truetype font, but is 100% patent-free (as far as I know).
  • Customized FIR Filter: Select your own filter values at run-time. Works on native TT hinter and autohinter.
  • Stem Alignment: Aligns bitmap glyphs to optimized pixel boundaries. Works on native TT hinter and autohinter.
  • Pseudo Gamma Correction: Lighten and darken glyphs at a given value, below a given size. Works on native TT hinter and autohinter.
  • Embolden Thin Fonts: Embolden thin or light fonts so that they are more visible. Works on autohinter.
  • Force Slight Hinting: Force slight hinting even when programs want full hinting. If you use the local.conf I provide (included in infinality-settings fedora package) you will notice nice improvements on @font-face fonts.
  • ChromeOS Style Sharpening: ChromeOS uses a patch to sharpen the look of fonts. This is now included in the infinality patchset.

A number of presets are included and can be used by setting the USE_STYLE variable in /etc/profile.d/infinality-settings.sh.

freetype2-infinalityAUR can be installed from the AUR. Additionally, if you are using lib32-freetype2 from [multilib], replace it with lib32-freetype2-infinalityAUR[broken link: archived in aur-mirror] from the AUR. The AUR also contains a Git version of freetype2 that builds the latest development snapshot of freetype2 with the Infinality patchset: freetype2-infinality-gitAUR[broken link: archived in aur-mirror], lib32-freetype2-infinality-gitAUR[broken link: archived in aur-mirror].

It is recommended to also install fontconfig-infinalityAUR to enable selection of predefined font substitution styles and antialiasing settings, apart from the rendering settings of the engine itself. After doing so, you can select the font style (win7, winxp, osx, linux, ...) with:

# infctl setstyle

If you set e.g. win7 or osx you need the corresponding fonts installed.

Note: Default infinality settings can cause some programs to display fonts at 72 DPI instead of 96. If you notice a problem open /etc/fonts/infinality/infinality.conf search for the section on DPI and change 72 to 96. This problem can specifically affect conky causing the fonts to appear smaller than they should. Thus not aligning properly with images.
Note: The README for fontconfig-infinalityAUR says that /etc/fonts/local.conf should either not exist, or have no infinality-related configurations in it. The local.conf is now obsolete and completely replaced by this configuration.

for more information see this article: http://www.infinality.net/forum/viewtopic.php?f=2&t=77

Ubuntu

Ubuntu adds extra configurations, and occasionally patches to the font rendering libraries.

Install the patched packages from the AUR, the package names are: freetype2-ubuntuAUR fontconfig-ubuntuAUR libxft-ubuntuAUR[broken link: archived in aur-mirror] cairo-ubuntuAUR.

The global configuration will need to be added. See #Example fontconfig configurations[broken link: invalid section] for a starting point.

恢复到未打补丁的包

To restore the unpatched packages, reinstall the originals:

# pacman -S --asdeps freetype2 libxft cairo fontconfig

没有fontconfig支持的应用程序

Some applications like URxvt will ignore fontconfig settings. This is very apparent when using the infinality patches which are heavily reliant on proper configuration. You can work around this by using ~/.Xresources, but it is not nearly as flexible as fontconfig. Example (see #Fontconfig configuration[broken link: invalid section] for explanations of the options):

~/.Xresources
Xft.autohint: 0
Xft.lcdfilter:  lcddefault
Xft.hintstyle:  hintfull
Xft.hinting: 1
Xft.antialias: 1
Xft.rgba: rgb

Make sure the settings are loaded properly when X starts with xrdb -q (see Xresources for more information).

字体问题解决方法

字体扭曲

Note: 96 DPI is not a standard. You should use your monitor's actual DPI to get proper font rendering, especially when using subpixel rendering.

If fonts are still unexpectedly large or small, poorly proportioned or simply rendering poorly, fontconfig may be using the incorrect DPI.

Fontconfig should be able to detect DPI parameters as discovered by the Xorg server. You can check the automatically discovered DPI with xdpyinfo:

$ xdpyinfo | grep dots
  resolution:    102x102 dots per inch
Note: To use the xdpyinfo command, you must install the package xorg-xdpyinfo.

If the DPI is detected incorrectly (usually due to an incorrect monitor EDID), you can specify it manually in the Xorg configuration, see Xorg#Display size and DPI. This is the recommended solution, but it may not work with buggy drivers.

Fontconfig will default to the Xft.dpi variable if it is set. Xft.dpi is usually set by desktop environments (usually to Xorg's DPI setting) or manually in ~/.Xdefaults or ~/.Xresources. Use xrdb to query for the value:

$ xrdb -query | grep dpi
Xft.dpi:	102

Those still having problems can fall back to manually setting the DPI used by fontconfig:

...
<match target="pattern">
   <edit name="dpi" mode="assign"><double>102</double></edit>
</match>
...

较旧的GTK和QT应用程序

Modern GTK apps enable Xft by default but this was not the case before version 2.2. If it is not possible to update these applications, force Xft for old GNOME applications by adding to ~/.bashrc:

export GDK_USE_XFT=1

For older QT applications:

export QT_XFT=true

资源