Modern X Tech. Chinese Translation Project
[[about_xft_and_fontconfig]]
Last edit on
Mar 4, 2006
3:39 AM
by mxt
about xft and fontconfig: http://freedesktop.org/wiki/Software_2ffontconfig_2fAbout
About Fontconfig
Fontconfig can:
* discover new fonts when installed automatically, removing a common source of configuration problems.
* perform font name substitution, so that appropriate alternative fonts can be selected if fonts are missing.
* identify the set of fonts required to completely cover a set of languages.
* have GUI configuration tools built as it uses an XML-based configuration file (though with autodiscovery, we believe this need is minimized).
* efficiently and quickly find the fonts you need among the set of fonts you have installed, even if you have installed thousands of fonts, while minimzing memory usage.
* be used in concert with the X Render Extension and FreeType to implement high quality, anti-aliased and subpixel rendered text on a display.
Fontconfig does not:
* render the fonts themselves (this is left to FreeType or other rendering mechanisms)
* depend on the X Window System in any fashion, so that printer only applications do not have such dependencies
About Xft
The current version of Xft (2.0) provides a client-side font API for X applications. It uses Fontconfig to select fonts and the X protocol for rendering them. When available, Xft uses the Render extension to accelerate text drawing. When Render is not available, Xft uses the core protocol to draw client-side glyphs. This provides completely compatible support of client-side fonts for all X servers.
Drawing anti-aliased text with the core protocol involves fetching pixels from the destination, merging in the glyphs and shipping them back. This can be a performance problem when the latency between client and server is high. Drawing non-AA text with the core protocol can be done by just sending the glyphs from the client to the server. This eliminates any latency effects and makes rendering speed depend only on bandwidth. Careful protocol selection can make the bandwidth scale linearly with the pixel size of the glyphs, so performance is acceptable, even with relatively large glyphs.
When using legacy X servers (those without Render support) across a network, disabling anti-aliased text will improve text performance so that applications are reasonably usable even if completely dependent on client-side fonts.
The many faces of Xft
There are three very different libraries name Xft. The original 1.0 Xft library shipped with XFree86 4.0.2 and included a private configuration mechanism via the XftConfig file. For X servers without the Render extension, Xft 1.0 used core X fonts instead of client-side fonts. This was supposed to allow applications to code to a common API and run with all X servers.
Early in the deployment of Xft 1.0, it became abundantly clear that another custom X-specific font configuration mechanism was a really bad idea. Both KDE and Pango ended up stealing pieces of Xft to configure fonts. KDE created a GUI Xft configuration tool by stealing the XftConfig parsing code, Pango stole most of Xft so that the XftConfig file could be shared between the Xft and FreeType2 backends. Fontconfig was designed to solve both of these problems.
The other problem in Xft 1.0 was the use of core X fonts when the server wasn't blessed with the Render extension. This meant that applications couldn't count on client-side fonts when using the high-level Xft APIs. As client-side fonts provide significant value beyond anti-aliased glyphs, it again became obvious that this design was flawed.
The Xft 1.0 API abstracted configuration details sufficient to permit a binary compatible version, Xft 1.1, to be developed which replaces the XftConfig configuration file with calls in to the Fontconfig library. Unfortunately, the Xft 1.0 API didn't sufficiently hide the rendering details making it impossible to provide for client-side fonts in servers without the Render extension. This means that Xft 1.1 shares font configuration, but isn't really usable on servers without Render.
Xft 2.0 hides most of the underlying system details so that developers can confidently use it's API to access client-side fonts in any X environment. (copy from http://freedesktop.org/fontconfig/)
-- KeithPackard - 21 Sep 2003
译者:Connermo (中国linux公社)
Fontconfig是用来设定和配置访问字体的函数库。
关于 Fontconfig
Fontconfig 有以下几个功能: *当拷贝字体的时候,能自动发现新的字体,解决普遍存在的设置问题。 * 拥有字体替换功能,当所需字体不存的时候,可以换成恰当的替换字体。 * 可以识别覆盖特定语言所需的一套字体。 * 因为使用XML为基础的配置文件,所以它内含图形界面配置工具。(虽然我们直觉告诉我们它不是很重要)。 * 在你安装的所有字体中,可以有效而快速地查找所需的字体,哪怕你装了上千种,同时,内存的使用也是最小化的。 * 同X的渲染延伸模组和Freetype一起,在屏幕上实现具有高质量,反锯齿和子像素的文字。 Fontconfig 不负责的工作: * 不渲染字体(这些交给Freetype和其他渲染系统) * 不依赖于X windows 系统,使得只使用打印机的程序和fontconfig没有依赖关系。
关于Xft
xft 目前的版本(2.0) 为X程序提供了一个客户端的应用程序接口(API) 。它使用fontconfig选择字体,然后用X 协议渲染。可能的话,Xft会使用X的硬件渲染延伸模组来加速字体绘制。当渲染延伸模组不可用的时候,Xft使用X核心协议来渲染客户端的字形。这为所有的X服务器提供了完全兼容的客户端支持。
使用核心协议绘制反锯齿文字需要获得目标端的像素(服务器端),合成字形,然后再将它们送回去(服务器端)。当客户端和服务器端有延迟的时候,就会造成一个性能问题。用核心协议绘制非反锯齿文字的时候,就可以将字形直接从客户端送到服务器。这就可以消除任何的延迟反应并且是渲染速度只和带宽有关。精心选择的协议可以让带宽随着字形像素的大小线性变化。所以就算有相对较大的字形的时候,性能也是可以接受的。
当在网络上使用过时的X服务器(没有硬件渲染支持)时,禁用反锯齿功能会提高字体的渲染速度,使得应用程序就算在完全依赖客户端字体的时候也可以运行的比较畅顺。
多变的Xft
有三个差别很大的函数库叫Xft。和XFree86 4.02发表的原来的1.0 xft函数库包含了一个独立的配置方式,使用XftConfig文件。Xft当渲染延伸模组不存在的时候,使用X的核心字体代替客户端字体。这是为了让编写的程序使用一个共同的API并且可以运行在所有的X服务器上。
早期应用Xft1.0的时候,它不同与其他X风格的字体配置方式被充分证明是一个不好的想法。KDE和pango最后都拿了部分的xft来设置字体。KDE拿了Xft分解代码的建立了一个图形界面的Xft配置工具。Pango则拿了几乎所有的Xft代码,用来让XftConfig文件可以在Xft和FreeType2后端之间共享。Fontconfig最终被设计出来解决这两个问题。
Xft 1.0的另外一个问题就是当服务器没有渲染延伸模组的时候就会使用X核心字体。这意味着当使用高级Xft API时,应用程序不能够依靠客户端字体。显然这个设计是有缺陷的,因为这时客户端需要提供的信息比反锯齿字形还要多很多。
Xft 1.0 API详细充分的抽象化设置使一个二进制兼容版本,并且用调用Fontconfig函数库的方法取代了XftConfig设置文件的Xft 1.1得以开发。不幸的是,Xft 1.0 API没有有效的封装渲染细节,也就不可能在服务器端没有渲染延伸模组的时候提供客户端字体。这意味着Xft1.1 共享字体设置,但在没有渲染器的服务器上并不十分可用。
Xft 2.0封装了几乎所有的底层系统细节,使得开发者可以在任何X环境下放心的使用它的API来访问客户端字体。