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

From ArchWiki
Jump to navigation Jump to search
(introduction的翻译)
(改变所有内容)
Line 23: Line 23:
 
Arch Linux包含的字体渲染包支持有字节码解释器(BCI)的''freetype2''。为了更好的字体渲染,特别是在LCD显示器上,一些补丁包也添加到库中,参见下面的[[#Patched packages]]。[[#Infinality]]包同时支持自动微调和亚像素渲染,允许在无须重新编译的情况下微调LCD滤光器,而且在粗体字下自动微调仍然表现良好。
 
Arch Linux包含的字体渲染包支持有字节码解释器(BCI)的''freetype2''。为了更好的字体渲染,特别是在LCD显示器上,一些补丁包也添加到库中,参见下面的[[#Patched packages]]。[[#Infinality]]包同时支持自动微调和亚像素渲染,允许在无须重新编译的情况下微调LCD滤光器,而且在粗体字下自动微调仍然表现良好。
  
==X的字体配置和美化==
+
==Font paths==
:参见 [http://www.x.org/X11R6.8.2/doc/fonts.html Xorg Font Documentation] 查看所有细节。
 
:参见 the [http://freetype.sourceforge.net/freetype2/ FreeType2 Project Page] 查看关于 freetype X.org 模块的的细节。
 
:参见 [http://avi.alkalay.net/linux/docs/font-howto/Font.html Optimal Use of Fonts on Linux] 查看更多关于 Linux 字体的信息。
 
  
===xorg.conf模块===
+
For fonts to be known to applications, they must be cataloged for easy and quick access.
*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) 字体提供支持 ('''与freetype有冲突''')
 
*bitmap - 提供bitmap (bdf, pcf, snf) 的支持
 
  
如你所看到的,freetype提供了所有的支持.补充说明一点,xtt于freetype有冲突.
+
The font paths initially known to Fontconfig are: {{ic|/usr/share/fonts/}} and {{ic|~/.fonts/}} (of which Fontconfig will scan recursively). For ease of organization and installation, it is recommended to use these font paths when [[Fonts#Installation|adding fonts]].
  
==X.org字体路径和/etc/fonts/配置目录==
+
To see a list of known Fontconfig fonts:
===xorg.conf字体路径===
+
  $ fc-list : file
xorg.conf里面的字体路径是给非xft字体用的. 为大多数字体在这里指定路径是值得的. 那些不支持xft的程序会寻找X的字体路径.我个人来说,我在这里填写最少的字体路径-仅仅为了xterm和那一类程序使用.
 
  
===/etc/fonts/配置目录===
+
See {{ic|man fc-list}} for more out put format.
/etc/fonts下的配置文件 (fonts.conf and local.conf)是用来配置字体的(Xft fonts).  fonts.conf 不应该被更改, 如果要更改应该改local.conf(系统全局) 或者 ~/.fonts.conf (用户自定义).
 
在/etc/fonts/conf.d目录下的文件都是以一个数字开头,还有.conf结尾的一个软链接(指向/etc/fonts/conf.avail/).
 
  
在fonts.conf列出的目录会为字体配置而被fc-cache扫描 (/usr/share/fonts 和 ~/.fonts).  所有的字体都应该放在这些文件夹内. 如果安装一个新字体,运行'''fc-cache -fv'''会让改变生效.
+
Check for Xorg's known font paths by reviewing its log:
 +
$ grep /fonts /var/log/Xorg.0.log
  
===添加新字体===
+
{{Tip|You can also check the list of [[Xorg]]'s known font paths using the command {{ic|xset q}}.}}
当新字体被添加后,它们不过是系统里面的一些文件. 必须使用一些工具来告诉系统新字体已经被安装了.
 
/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.
+
Keep in mind that Xorg does not search recursively through the {{ic|/usr/share/fonts/}} directory like Fontconfig does. To add a path, the full path must be used:
 +
Section "Files"
 +
    FontPath    "/usr/share/fonts/local/"
 +
EndSection
  
===fc-list和xlsfont工具===
+
If you want font paths to be set on a per-user basis, you can add and remove font paths from the default by adding the following line(s) to {{ic|~/.xinitrc}}:
这两个工具将在命令行下用不同方式列出所有可用字体. fc-list将列出所有配置过的字体,而xlsfont则会列出所有的X字体. 如果同时使用grep效果会非常好,例如: "xlsfonts || grep -i bitstream" 可以看到所有可用的bitstream字体.
+
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
  
==一些字体的下载==
+
To see a list of known Xorg fonts use {{ic|xlsfonts}}, from the {{Pkg|xorg-xlsfonts}} package.
*[http://www.users.bigpond.net.au/gavindi/ Arkpandora TrueType fonts] - Replacements for Arial and Times New Roman.
 
*[http://themes.freshmeat.net/projects/ppantsfonts/ PPants Angular Font Collection]-Small collection of Angular-styled fonts with a general width of six pixels.
 
*[http://www.tobias-jung.de/seekingprofont/ Profont]-Programming font.
 
  
==Goodies==
+
==Fontconfig configuration==
===LCD的ClearType补丁===
 
[http://bbs.archlinux.org/viewtopic.php?id=33955 http://bbs.archlinux.org/viewtopic.php?id=33955]
 
  
===我的字体很难看.我都配置好了,但是好像是我缺少好看字体.===
+
Fontconfig is documented in the [http://fontconfig.org/fontconfig-user.html fonts.conf] man page.
建议你从pacman安装如下包来解决:
 
pacman -S ttf-ms-fonts ttf-cheapskate artwiz-fonts
 
  
另外一个方法是删除75/100dpi包然后安装Bitstream Vera.后者提供漂亮的等宽终端字体,也能是浏览网页字体更好看(至少是firefox里面这样):
+
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.
  pacman -Rns xorg-fonts-75dpi xorg-fonts-100dpi
+
{{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.}}
pacman -S ttf-bitstream-vera
 
  
补充:中文用户,安装如下任意一个中文字体,带有很全的GBK字符集,需要打开community仓库
+
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}}).
  pacman -S wqy-bitmapfont 文泉驿点阵字体
 
  pacman -S wqy-zenhei 文泉驿正黑字体
 
  
===我有一些针对Gtk 2.2和以下版本编译的程序,字体仍然看起来很垃圾.===
+
{{Note|For some desktop environments (such as [[GNOME]] and [[KDE]]) using the ''Font Control Panel'' will automatically create or overwrite the user font configuration file. For these desktop environments, it is best to match your already defined font configurations to get the expected behavior.}}
的确这个会发生.现在的Gtk程序默认开启了xft支持, 但是2.2字体以前就没有这样了. 也许这些程序应该升级到一个针对新Gtk的新版本了. 如果那不可能,那么就添加 '''export GDK_USE_XFT=1''' 到全局设置文件 (/etc/profile, /etc/profile.d/gnome.sh, ~/.xinitrc, 等,任选一个) 将会为老程序启用xft的支持.
 
  
===我有的老的Qt基础的程序有同样的问题.===
+
Fontconfig configuration files use [[Wikipedia:XML|XML]] format and need these headers:
同上, 添加 '''export QT_XFT=true'''.
 
  
===在用KDE桌面的时候,Gtk程序字体太小.===
+
{{bc|<nowiki>
安装gtk-qt-engine:
+
<?xml version="1.0"?>
  pacman -S gtk-qt-engine
+
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
*更改Gtk程序字体大小:`Control Center' -> `Appearance & Themes' -> `GTK Styles and Fonts'.
+
<fontconfig>
 +
 
 +
  <!-- settings go here -->
 +
 
 +
</fontconfig>
 +
</nowiki>}}
 +
 
 +
The configuration examples in this article omit these tags.
 +
 
 +
===Presets===
 +
 
 +
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.
 +
 
 +
For example, to enable sub-pixel RGB rendering globally:
  
===bytecode interpreter让我字体看起来很丑,但是我已经把它编译进去了,我需要重新编译么?===
+
# cd /etc/fonts/conf.d
完全不需要. 只是Freetype内部的自动微调(auto-hinting)关闭了. 在某些distros(也许可以翻译成源)里面, bytecode interpreter 被编译进去而且默认开启了. 这样造成bytecode interpreter 替代了freetype的自动微调(autohinter) (这还是开发者比较得意的地方). 指定自动微调开启, 添加下面的段到/etc/fonts/local.conf 或者 ~/.fonts.conf
+
# ln -s ../conf.avail/10-sub-pixel-rgb.conf
      <!-- Use the Autohinter -->
 
      <match target="pattern">
 
        <edit name=<code>"autohint" mode=</code>"assign">
 
            <bool>true</bool>
 
        </edit>
 
      </match>
 
  
或者改变 /etc/fonts/conf.d目录, 即从conf.avail做一个10-autohint.conf的软链接到这里.  如下(第二个命令需要有超级用户权限).
+
To do the same but instead for a per-user configuration:
cd /etc/fonts/conf.d
 
ln -s ../conf.avail/10-autohint.conf
 
  
问题: 我不明白,bytecode interpreter 会和自动微调(autohinter)冲突都有段时间了,所以我不知道为什么有人想要自动微调.  
+
$ mkdir $XDG_CONFIG_HOME/fontconfig/conf.d
回答: 因为 bytecode interpreter 在2.3分支(branch)里面支持相当不好 . 这里有一个论坛帖子是关于这个的: http://bbs.archlinux.org/viewtopic.php?id=29976 那上面的代码让我的字体好看很多. 尽管我重启效果就会失效,我也不知道为什么.
+
$ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d
  
===自动微调(Autohint)运行的很好,但是我的字体的粗体就不行了,我怎样能针对粗体关闭它?===
+
===Anti-aliasing===
自动微调可以让字体很好看,但是有时也让字体变太宽. 特别是字体为粗体模式时尤其严重. 幸好你可以为粗体关闭微调,而为其他字体模式保留.
 
*First turn on autohinter (see above) and add the following to ~/[[.fonts.conf]]
 
      <match target="font">
 
          <test name=<code>"weight" compare=</code>"more">
 
              <const>medium</const>
 
          </test>
 
          <edit name=<code>"autohint" mode=</code>"assign">
 
              <bool>false</bool>
 
          </edit>
 
      </match>
 
  
===我有一个使用DVI数据线的TFT/DFP/LCD显示器,字体看起来模糊不清晰===
+
[[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.
这是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 -->
+
{{bc|<nowiki>
<match target="font" >
+
  <match target="font">
  <edit mode="assign" name="rgba" >
+
    <edit name="antialias" mode="assign">
  <const>rgb</const>
+
      <bool>true</bool>
  </edit>
+
    </edit>
</match>
+
  </match>
 +
</nowiki>}}
 +
 
 +
===Hinting===
 +
 
 +
[[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.
  
===我不希望我的字体在某些字号下反锯齿(或者叫边缘模糊 AA Antialiase).===
+
====Byte-Code Interpreter (BCI)====
一份例子是/etc/fonts/local.conf文件. 推荐这样做, 当然就像次像素渲染那一节一样写. 如果有任何改变,就应该改变 '''compare="less_eq"''' , 和'''<int>12</int>'''区域 - 这分别是渲染强弱和点大小.
+
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.
      <!-- Disable anti-aliasing for fonts that are size <=12 -->
 
      <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),想针对看起来有锯齿的大号字体开启反锯齿.===
+
To enable normal hinting:
      <?xml version="1.0"?>
 
      <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
      <fontconfig>
 
  
      <match target="font" >
+
{{bc|<nowiki>
      <test compare<code>"more" name</code>"size" qual="any" >
+
  <match target="font">
      <double>12</double>
+
    <edit name="hinting" mode="assign">
      </test>
 
      <edit mode<code>"assign" name</code>"antialias" >
 
 
       <bool>true</bool>
 
       <bool>true</bool>
      </edit>
+
    </edit>
      </match>
+
  </match>
 +
</nowiki>}}
 +
 
 +
====Autohinter====
 +
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.
  
      <match target="font" >
+
To enable auto-hinting:
      <test compare<code>"more" name</code>"pixelsize" qual="any" >
+
 
      <double>17</double>
+
{{bc|<nowiki>
      </test>
+
  <match target="font">
      <edit mode<code>"assign" name</code>"antialias" >
+
    <edit name="autohint" mode="assign">
 
       <bool>true</bool>
 
       <bool>true</bool>
       </edit>
+
    </edit>
      </match>
+
  </match>
      </fontconfig>
+
</nowiki>}}
 +
 
 +
====Hint style====
 +
 
 +
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.
 +
 
 +
{{bc|<nowiki>
 +
  <match target="font">
 +
    <edit name="hintstyle" mode="assign">
 +
       <const>hintfull</const>
 +
    </edit>
 +
  </match>
 +
</nowiki>}}
 +
 
 +
===Subpixel rendering===
 +
 
 +
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.
 +
 
 +
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''
保存你的字体到一个目录然后到'''~/[[[.fonts.conf]]]'''添加路径
 
  
    < !-- Additional font directories -->
+
To enable subpixel rendering:
    <dir>/path/to/dir</dir>
 
  
===我希望我的字体大小符合我的DPI设置.===
+
{{bc|<nowiki>
照下面编辑'''~/[[[.fonts.conf]]]'''. 这个设置应该适合你[[xorg.conf]]里面的Dpi,或者startx命令. 使用xdpyinfo来查看你目前的DPI设置. 大多数人适合或者正在使用96或者100的值.应该依照这个文档[[Xorg#Display_Size.2FDPI|Xorg DisplaySize/DPI]]来改变X的DPI值
+
  <match target="font">
  <!-- Setup for DPI = 100 -->
+
    <edit name="rgba" mode="assign">
      <match target="pattern">
+
      <const>rgb</const>
        <edit name=<code>"dpi" mode=</code>"assign"><double>100</double></edit>
+
    </edit>
      </match>
+
  </match>
 +
</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.
  
最可靠的办法是同上面一样添加一段XML段落到 ~/[[.fonts.conf]]. 这会让Bitstream Vera Sans取代Helvetica:
+
====LCD filter====
  
  <match target="pattern" name="family" >
+
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.
  <test name="family" qual="any" >
 
  <string>Helvetica</string>
 
  </test>
 
  <edit mode="assign" name="family" >
 
  <string>Bitstream Vera Sans</string>
 
  </edit>
 
  </match>
 
  
 +
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.
  
 +
{{bc|<nowiki>
 +
  <match target="font">
 +
    <edit mode="assign" name="lcdfilter">
 +
      <const>lcddefault</const>
 +
    </edit>
 +
  </match>
 +
</nowiki>}}
  
一个另类的办法是设置"更喜欢"字体,'''但这仅仅在原始字体不存在的时候生效''',这样你设置的字体才能生效:
+
====Advanced LCD filter specification====
  
 +
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.
  
      < !-- Replace Helvetica with Bitstream Vera Sans Mono -->
+
First, refresh the freetype2 PKGBUILD as root:
      < !-- 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)===
+
# abs extra/freetype2
只有两个字体你需要一定保留,否则X服务无法启动:'cursor' 和 'fixed', 他们都在/usr/share/fonts/misc目录. 如果你不想要除此之外所有的像素字体, 你可以删除那个目录下多数文件, 除了'''cursor.pcf.gz'''和所有类似'''9x18.pcf.gz'''或者'''9x18-ISO8859-1.pcf.gz'''. 我删除所有不需要字体后,misc目录还有大约337个文件, 所以如果你比这个数字少,那么在重启X之前你最好是还原删除的问题件.
 
  
译者补充:
+
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:
*我试过这种方法,不过我的文件是可以更少的,只需要保留cursor.pcf.gz和类似6x13-Iso8859-[1-10].pcf.gz就行了,没有实验能不能更少,其实没有必要删除这么多,系统还是会剩下某个字号的fiexd字体,可以利用上面提到的字体替换方法替换成你喜欢字体,避免任何程序调用.
 
  
*如够你删除了所有文件,但是没有备份,那么可以
+
$ cd /var/abs/build
  pacman -S xorg-fonts-misc
+
  $ cp -r ../extra/freetype2 .
来重新安装这个字体,否则你的X是不能启动的,当然也可以解压你cache文件夹下相应包.
+
$ cd freetype2
 +
$ makepkg -o
  
*这种方法对于opera的中文字体难看问题有一定程度的解决
+
Edit the file {{ic|src/freetype-VERSION/src/base/ftlcdfil.c}} and look up the definition of the constant {{ic|default_filter[5]}}:
  
===我的点阵字体被禁用了,我想使用它们.===
+
static const FT_Byte  default_filter[5] =
默认的, fontconfig 2.3.2-4和更高版本会禁用点阵(bitmap)字体. 这个设置是被/etc/fonts/conf.d/10-no-bitmaps.conf管理的, 在更高版本里面是/etc/fonts/conf.d/10-bitmaps.conf.
+
    { 0x10, 0x40, 0x70, 0x40, 0x10 };
启用点阵字体而且在升级fontconfig后也保持, 建立一个软链接从yes-bitmaps.conf到10-bitmaps.conf, 覆盖no-bitmaps.conf.
 
  
===为没有粗斜体的字体构造粗体和斜体===
+
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:
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>
 
            &lt;!-- other fonts here .... --&gt;
 
        </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>
 
            &lt;!-- other fonts here .... --&gt;
 
        </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===
+
  $ makepkg -e
一个网络开发者的.~/[[.fonts.conf]],是论坛上来的. 备份你现有的这是,尝试一下.  
+
  $ sudo pacman -Rd freetype2
  <pre>
+
  $ sudo pacman -U freetype2-VERSION-ARCH.pkg.tar.xz
  <?xml version="1.0"?>
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
  
<!-- the cathectic LCD tweaks, from linuxquestions.org,
+
Reboot or restart X. The lcddefault filter should now render fonts differently.
http://www.linuxquestions.org/questions/showthread.php? postid=1361098#post1361098 -->
 
  
<fontconfig>
+
===Disable auto-hinter for bold fonts===
  
<!-- Disable sub-pixel rendering.
+
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:
X detects it anyway, and if you set this as well, it just looks really horrible -->
+
  ...
  <match target="font" >
+
  <match target="font">
<edit mode="assign" name="rgba" >
+
    <test name="weight" compare="more">
<const>none</const>
+
        <const>medium</const>
</edit>
+
    </test>
 +
    <edit name="autohint" mode="assign">
 +
        <bool>false</bool>
 +
    </edit>
 
  </match>
 
  </match>
  <match target="font" >
+
  ...
<edit mode="assign" name="hinting">
+
 
<bool>true</bool>
+
=== Enable anti-aliasing only for bigger fonts ===
</edit>
+
 
 +
''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>
 +
...
 +
<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>
 +
...
 +
</nowiki>}}
 +
 
 +
===Replace fonts===
 +
 
 +
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:
 +
...
 +
<match target="pattern" name="family" >
 +
    <test name="family" qual="any" >
 +
        <string>Helvetica</string>
 +
    </test>
 +
    <edit name="family" mode="assign">
 +
        <string>Bitstream Vera Sans</string>
 +
    </edit>
 
  </match>
 
  </match>
  <match target="font" >
+
...
<edit mode="assign" name="hintstyle">
+
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:
<const>hintfull</const>
+
...
</edit>
+
< !-- 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>
 +
...
 +
 
 +
===Disable bitmap fonts===
 +
 
 +
To disable bitmap fonts in fontconfig, use {{ic|70-no-bitmaps.conf}} (which is not placed by fontconfig by default):
 +
 
 +
# cd /etc/fonts/conf.d
 +
# rm 70-yes-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 ../conf.avail/29-replace-bitmap-fonts.conf
 +
 
 +
To disable embedded bitmap fonts for a specific font:
 +
 
 +
  <match target="font">
 +
  <test qual="any" name="family">
 +
    <string>Monaco</string>
 +
  </test>
 +
  <edit name="embeddedbitmap"><bool>false</bool></edit>
 
  </match>
 
  </match>
  
<!-- The first part of the 'magic.'
+
===Create bold and italic styles for incomplete fonts===
This makes the fonts start to look nice,
+
 
  but some of the shapes will be distorted, so hinting is needed still -->
+
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.
<match target="font" >
+
 
<edit mode="assign" name="antialias">
+
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}}.
<bool>true</bool>
+
 
</edit>
+
Assuming the Dupree font is installed:
</match>
+
"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''''':
 +
  "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}}:
 +
{{bc|<nowiki>
 +
...
 +
<match target="font">
 +
    <test name="family" qual="any">
 +
        <string>Dupree</string>
 +
        &lt;!-- other fonts here .... --&gt;
 +
    </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>
 +
        &lt;!-- other fonts here .... --&gt;
 +
    </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>
 +
...
 +
</nowiki>}}
 +
{{Tip| Use the value 'embolden' for existing bold fonts in order to make them even bolder.}}
 +
 
 +
===Change rule overriding===
 +
 
 +
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.
 +
 
 +
To guarantee that personal settings take precedence over any other rules, change their ordering:
 +
# cd /etc/fonts/conf.d
 +
# mv 50-user.conf 00-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.
 +
 
 +
===Example fontconfig configurations===
 +
 
 +
Example fontconfig configurations can be found on this [[Font_Configuration/fontconfig_Examples|page]].
 +
 
 +
A simple starting point:
  
<!-- Autohinter is not turned on automatically.
+
{{hc|/etc/fonts/local.conf|<nowiki>
Only disable this if you have recompiled Freetype with the bytecode interpreter,
+
<?xml version='1.0'?>
which is run automatically.<br />  -->
+
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<match target="pattern" >
+
<fontconfig>
<edit mode="assign" name="autohint">
 
<bool>true</bool>
 
</edit>
 
</match>
 
 
  <match target="font">
 
  <match target="font">
<test name="weight" compare="more">
+
 
<const>medium</const>
+
  <edit mode="assign" name="rgba">
</test>
+
  <const>rgb</const>
<edit name="autohint" mode="assign">
+
  </edit>
<bool>false</bool>
+
 
</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>
 
  </match>
<!-- Helvetica is a non true type font, and will look bad.
+
</fontconfig>
This replaces it with whatever is the default sans-serif font -->
+
</nowiki>}}
<match target="pattern" name="family" >
+
 
<test name="family" qual="any" >
+
==Patched packages==
<string>Helvetica</string>
+
 
</test>
+
These patched packages are available in the [[Arch User Repository|AUR]]. A few considerations:
<edit mode="assign" name="family" >
+
 
<string>sans-serif</string>
+
* Configuration is usually necessary.
</edit>
+
* The new font rendering will not kick in until applications restart.
  </match>
+
* Applications which [[Wikipedia:Static library|statically link]] to a library will not be affected by patches applied to the system library.
  <dir>~/.fonts</dir>
+
 
  </fontconfig>
+
=== ClearType packages ===
  </pre>
+
 
 +
These packages attempt to emulate ClearType, a type of font rendering that is used in Windows systems and is designed to work on both LCD and CRT monitors.
 +
 
 +
Install the patched packages from the [[Arch User Repository|AUR]]. Package names: {{AUR|freetype2-cleartype}} {{AUR|libxft-cleartype}} {{AUR|cairo-cleartype}}
 +
 
 +
===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.
 +
 
 +
*[http://www.infinality.net/blog/infinality-freetype-patches/ Home page].
 +
*[http://www.infinality.net/forum/ Forum].
 +
 
 +
Infinality's settings are all configurable at runtime via environment variables in {{ic|/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 [http://www.infinality.net/forum/viewtopic.php?f=2&t=19 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 {{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}}.
 +
 
 +
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:
 +
# 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 {{AUR|fontconfig-infinality}} 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 [[Arch User Repository|AUR]], the package names are: {{AUR|freetype2-ubuntu}} {{AUR|fontconfig-ubuntu}} {{AUR|libxft-ubuntu}} {{AUR|cairo-ubuntu}}.
 +
 
 +
The global configuration will need to be added. See [[#Example fontconfig configurations]] for a starting point.
 +
 
 +
===Reverting to unpatched packages===
 +
 
 +
To restore the unpatched packages, reinstall the originals:
 +
 
 +
  # pacman -S --asdeps freetype2 libxft cairo fontconfig
 +
 
 +
==Applications without fontconfig support==
 +
 
 +
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):
 +
 
 +
{{hc|~/.Xresources|<nowiki>
 +
Xft.autohint: 0
 +
Xft.lcdfilter: lcddefault
 +
Xft.hintstyle: hintfull
 +
Xft.hinting: 1
 +
Xft.antialias: 1
 +
Xft.rgba: rgb
 +
</nowiki>}}
 +
 
 +
Make sure the settings are loaded properly when X starts with {{ic|xrdb -q}} (see [[Xresources]] for more information).
 +
 
 +
==Troubleshooting==
  
===另一个.fonts.conf===
+
===Distorted fonts===
<pre>
+
{{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.}}
<?xml version="1.0"?>
 
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
 
  
<fontconfig>
+
If fonts are still unexpectedly large or small, poorly proportioned or simply rendering poorly, fontconfig may be using the incorrect DPI.
  
<!-- Info:
+
Fontconfig should be able to detect DPI parameters as discovered by the Xorg server. You can check the automatically discovered DPI with {{ic|xdpyinfo}}:
xeffects thread:  http://forums.gentoo.org/viewtopic-t-511382.html
 
http://wiki.archlinux.org/index.php/XOrg_Font_Configuration
 
http://antigrain.com/research/font_rasterization/index.html
 
http://fontconfig.org/fontconfig-user.html
 
-->
 
  
 +
{{hc|<nowiki>$ xdpyinfo | grep dots</nowiki>|  resolution:    102x102 dots per inch}}
  
<!-- http://bugs.gentoo.org/show_bug.cgi?id=130466 -->
+
{{Note|To use the ''xdpyinfo'' command, you must install the package {{pkg|xorg-xdpyinfo}}.}}
  
<alias>
+
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.
<family>serif</family>
 
  <prefer>
 
  <family>Bitstream Vera Serif</family>
 
  <family>DejaVu Serif</family>
 
  <family>WenQuanYi Micro Hei</family>
 
  <family>WenQuanYi Zen Hei</family>
 
  </prefer>
 
</alias>
 
  
<alias>
+
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:
<family>sans-serif</family>
 
  <prefer>
 
  <family>DejaVu Sans</family>
 
  <family>Bitstream Vera Sans</family>
 
  <family>WenQuanYi Micro Hei</family>
 
  <family>WenQuanYi Zen Hei</family>
 
  </prefer>
 
</alias>
 
  
<alias>
+
{{hc|<nowiki>$ xrdb -query | grep dpi</nowiki>|Xft.dpi: 102}}
<family>monospace</family>
 
  <prefer>
 
  <family>DejaVu Sans Mono</family>
 
  <family>Bitstream Vera Sans Mono</family>
 
  <family>WenQuanYi Micro Hei Mono</family>
 
  <family>WenQuanYi Zen Hei Mono</family>
 
  </prefer>
 
</alias>
 
  
<!-- Reject bitmap fonts in favour of Truetype, Postscript, etc. -->
+
Those still having problems can fall back to manually setting the DPI used by fontconfig:
<selectfont>
 
<rejectfont>
 
<pattern>
 
<patelt name="scalable">
 
<bool>false</bool>
 
</patelt>
 
</pattern>
 
</rejectfont>
 
</selectfont>
 
  
<!-- Replace Luxi Sans with a better-looking font - looks terrible at e.g. http://market-ticker.org/ -->
+
...
<match name="family" target="pattern">
+
<!-- Setup for DPI=96 -->
<test name="family" qual="any">
+
<match target="pattern">
<string>Luxi Sans</string>
+
    <edit name="dpi" mode="assign"><double>102</double></edit>
</test>
+
</match>
<edit name="family" mode="assign">
+
...
<string>Liberation Sans</string>
 
</edit>
 
</match>
 
  
<!-- Ubuntu options:  lcdnone, lcddefault, lcdlight, lcdlegacy -->
+
===Older GTK and QT applications===
<!-- hintnone, hintslight, hintmedium, hintfull -->
 
<!-- Keep autohint off -->
 
<!-- Blurry fonts:  Try rgb, bgr, vrgb, vbgr for "rgba" -->
 
<!-- Blurry:  http://forums.gentoo.org/viewtopic-p-5060979.html#5060979 -->
 
<match target="font">
 
<edit name="rgba" mode="assign"><const>rgb</const></edit>
 
<edit name="autohint" mode="assign"><bool>false</bool></edit>
 
<edit name="antialias" mode="assign"><bool>true</bool></edit>
 
<edit name="hinting" mode="assign"><bool>true</bool></edit>
 
<edit name="hintstyle" mode="assign"><const>hintmedium</const></edit>
 
<edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
 
</match>
 
  
    <!-- Tweak Courier -->
+
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 {{ic|~/.bashrc}}:
    <match name="family" target="pattern">
 
        <test name="family" qual="any">
 
            <string>Courier</string>
 
        </test>
 
<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
 
    </match>
 
  
    <!-- Tweak Courier New -->
+
export GDK_USE_XFT=1
    <match name="family" target="pattern">
 
        <test name="family" qual="any">
 
            <string>Courier New</string>
 
        </test>
 
<edit name="lcdfilter" mode="assign"><const>lcdlegacy</const></edit>
 
    </match>
 
  
</fontconfig>
+
For older QT applications:
  
 +
export QT_XFT=true
  
</pre>
+
==See also==
WikiMigration--[[User:Dlanor|dlanor]] 14:05, 23 Jul 2005 (EDT)
+
*[http://www.x.org/X11R6.8.2/doc/fonts.html Fonts in X11R6.8.2] - Official Xorg font information
 +
*[http://freetype.sourceforge.net/freetype2/ FreeType 2 Overview]
 +
*[https://forums.gentoo.org/viewtopic-t-723341.html Gentoo font-rendering thread]

Revision as of 14:30, 16 October 2012

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Font configuration (简体中文)#)

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki: Information on adding fonts and font recommendations Template:Article summary wiki: Fonts specific to Sun's Java machine Template:Article summary wiki: Adding Microsoft fonts and mimicking Windows' font settings Template:Article summary wiki Template:Article summary end

Fontconfig是一个库,它被设计用来为应用程序提供可用字体,或者用来配置字体渲染效果,参见包fontconfigWikipedia:Fontconfig。 Free type库(freetype2包)就是以此为配置基础来渲染字体。

尽管Fontconfig已经是当今Linux的标准库,但是仍有一部分应用程序构建在更加原始的字体分类法上:Xorg server配置。

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

Font paths

For fonts to be known to applications, they must be cataloged for easy and quick access.

The font paths initially known to Fontconfig are: /usr/share/fonts/ and ~/.fonts/ (of which Fontconfig will scan recursively). For ease of organization and installation, it is recommended to use these font paths when adding fonts.

To see a list of known Fontconfig fonts:

$ fc-list : file

See man fc-list for more out put format.

Check for Xorg's known font paths by reviewing its log:

$ grep /fonts /var/log/Xorg.0.log
Tip: You can also check the list of Xorg's known font paths using the command xset q.

Keep in mind that Xorg does not search recursively through the /usr/share/fonts/ directory like Fontconfig does. To add a path, the full path must be used:

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

If you want font paths to be set on a per-user basis, you can add and remove font paths from the default by adding the following line(s) to ~/.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

To see a list of known Xorg fonts use xlsfonts, from the xorg-xlsfonts package.

Fontconfig configuration

Fontconfig is documented in the fonts.conf man page.

Configuration can be done per-user through $XDG_CONFIG_HOME/fontconfig/fonts.conf, and globally with /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: ~/.fonts.conf, ~/.fonts.conf.d and ~/.fontconfig/*.cache-* are deprecated since fontconfig 2.10.1 (upstream commit) and will not be read by default in the future versions of package. Use instead $XDG_CONFIG_HOME/fontconfig/fonts.conf, $XDG_CONFIG_HOME/fontconfig/conf.d and $XDG_CACHE_HOME/fontconfig/*.cache-* respectively.

Fontconfig gathers all its configurations in a central file (/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 (/etc/fonts/local.conf), the configured presets in /etc/fonts/conf.d/, and the user configuration file ($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 file. For these desktop environments, it is best to match your already defined font configurations to get the expected behavior.

Fontconfig configuration files use XML format and need these headers:

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

  <!-- settings go here -->

</fontconfig>

The configuration examples in this article omit these tags.

Presets

There are presets installed in the directory /etc/fonts/conf.avail. They can be enabled by creating symbolic links to them, both per-user and globally, as described in /etc/fonts/conf.d/README. These presets will override matching settings in their respective configuration files.

For example, to enable sub-pixel RGB rendering globally:

# cd /etc/fonts/conf.d
# 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
$ ln -s /etc/fonts/conf.avail/10-sub-pixel-rgb.conf $XDG_CONFIG_HOME/fontconfig/conf.d

Anti-aliasing

Font rasterization converts vector font data to bitmap data so that it can be displayed. The result can appear jagged due to aliasing. anti-aliasing is enabled by default and increases the apparent resolution of font edges.

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

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 DPI or greater. Two types of hinting are available.

Byte-Code Interpreter (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.

To enable normal hinting:

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

Autohinter

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.

To enable auto-hinting:

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

Hint style

Hint style is the amount of influence the hinting mode has. Hinting can be set to: hintfull, hintmedium, hintslight and hintnone. With BCI hinting, hintfull should work best for most fonts. With the autohinter, hintslight is recommended.

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

Subpixel rendering

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.

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:

  <match target="font">
    <edit name="rgba" mode="assign">
      <const>rgb</const>
    </edit>
  </match>

If you notice unusual colors around font's borders, the wrong subpixel arrangement might be configured. The Lagom subpixel layout test web page can help identify it.

LCD filter

When using subpixel rendering, you should enable the LCD filter, which is designed to reduce colour fringing. This is described under LCD filtering in the FreeType 2 API reference. Different options are described under FT_LcdFilter, and are illustrated by this LCD filter test page.

The lcddefault filter will work for most users. Other filters are available that can be used in special situations: lcdlight; a lighter filter ideal for fonts that look too bold or fuzzy, lcdlegacy, the original Cairo filter; and lcdnone to disable it entirely.

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

Advanced LCD filter specification

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.

First, refresh the freetype2 PKGBUILD as root:

# abs extra/freetype2

This example uses /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:

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

Edit the file src/freetype-VERSION/src/base/ftlcdfil.c and look up the definition of the constant default_filter[5]:

static const FT_Byte  default_filter[5] =
    { 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:

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

Reboot or restart X. The lcddefault filter should now render fonts differently.

Disable auto-hinter for bold fonts

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:

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

Enable anti-aliasing only for bigger fonts

See also sharpfonts.co.cc for related information.

Some users prefer the sharper rendering that anti-aliasing does not offer:

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

Replace fonts

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:

...
<match target="pattern" name="family" >
    <test name="family" qual="any" >
        <string>Helvetica</string>
    </test>
    <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 -->
< !-- 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>
...

Disable bitmap fonts

To disable bitmap fonts in fontconfig, use 70-no-bitmaps.conf (which is not placed by fontconfig by default):

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

You may not need to remove 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 ../conf.avail/29-replace-bitmap-fonts.conf

To disable embedded bitmap fonts for a specific font:

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

Create bold and italic styles for incomplete fonts

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.

Start by editing /usr/share/fonts/fonts.cache-1 as explained below. Store a copy of the modifications on another file, because a font update with fc-cache will overwrite /usr/share/fonts/fonts.cache-1.

Assuming the Dupree font is installed:

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

Duplicate the line, change style=Regular to style=Bold or any other style. Also change slant=0 to slant=100 for italic, weight=80 to weight=200 for bold, or combine them for bold italic:

"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 $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>
...
Tip: Use the value 'embolden' for existing bold fonts in order to make them even bolder.

Change rule overriding

Fontconfig processes files in /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.

To guarantee that personal settings take precedence over any other rules, change their ordering:

# cd /etc/fonts/conf.d
# mv 50-user.conf 00-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.

Example fontconfig configurations

Example fontconfig configurations can be found on this page.

A simple starting point:

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

Patched packages

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.

ClearType packages

These packages attempt to emulate ClearType, a type of font rendering that is used in Windows systems and is designed to work on both LCD and CRT monitors.

Install the patched packages from the AUR. Package names: freetype2-cleartypeAUR libxft-cleartypeAUR cairo-cleartypeAUR

Infinality

Warning: Since the Fontconfig 2.10.1 update, Infinality users will receive multiple warnings similar to:

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: this article for more information.

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 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-git-infinalityAUR, lib32-freetype2-git-infinalityAUR.

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 cairo-ubuntuAUR.

The global configuration will need to be added. See #Example fontconfig configurations for a starting point.

Reverting to unpatched packages

To restore the unpatched packages, reinstall the originals:

# pacman -S --asdeps freetype2 libxft cairo fontconfig

Applications without fontconfig support

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

Troubleshooting

Distorted fonts

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

Older GTK and QT applications

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

See also