Using Font Smoothing

Font smoothing, aka anti-aliasing, is a font display technique in which some pixels that fall along the edge of a character are displayed as gray rather than black or white. The effect is that the text appears to be less jagged than it otherwise would. Some people like this effect, but others find that it makes text look blurry. Unfortunately, font smoothing in Linux is quite confusing because several approaches to the task have been developed since XFree86 4.0.2 was released. As a result, configuring font smoothing can be quite frustrating because what works on one system or environment doesn't work on another. What's more, the same tools that deliver smoothed fonts can also deliver fonts without font smoothing. An increasing number of programs are using these tools in addition to or even instead of X's traditional fonts, so configuring fonts to work with these tools can be important even if you don't want to use smoothed fonts.

Font Smoothing Principles

Until recently, X hasn't supported font smoothing at all. A few X applications, such as Adobe's Acrobat Reader, have implemented font smoothing by bypassing X's normal font-rendering mechanisms, but for the most part, Linux users have had no choice but to use unsmoothed fonts. This situation began to change with XFree86 4.0.2, which used a library known as Xft 1.0 to implement font smoothing. This library is an interface tool between X and the FreeType library (http://www.freetype.org), which was originally developed as a TrueType rendering system, although it now also handles Type 1 and other font formats. Unfortunately, Xft has undergone major changes with subsequent versions (1.1 and 2.0), which has contributed to font-smoothing chaos in Linux. Configuration methods vary greatly, and it's easy to find yourself with a system in which different applications deliver different sets of fonts because one program uses Xft, and hence Xft-delivered fonts, while another program uses X's traditional unsmoothed font-rendering mechanisms.

Note A few programs call FreeType directly, without the use of Xft. For instance, WINE (the Windows emulator) and OpenOffice.org both use FreeType independently of Xft. Such programs have their own font configuration systems, so you may need to install the same fonts half a dozen or more times. With any luck, Xft will become popular and obviate the need for some of these installations in the future.

In order to use smoothed fonts, an application calls the Xft libraries, which are typically installed along with X in a package called xshared, xlibs, XFree86-libs, or something similar. These libraries require direct access to font files, so you must normally point them to your font directories, as described in the next section, "Configuring Fonts in Xft." Once that's done, you can access smoothed fonts; however, the procedure for doing so varies from one program to another. Both the KDE and GNOME environments provide tools to help configure fonts, but these settings may not apply outside of the target environments. What's more, some programs work only with fonts delivered via Xft. This shortcoming is particularly common in GNOME applications. The result is that these programs won't work with fonts served via a standard X font server, although if the same fonts are made available via Xft, you may not notice this problem. Other programs can serve both smoothed fonts delivered from Xft and unsmoothed fonts delivered via X or a font server. When you use such a program, you may notice that some fonts are smoothed and others aren't. Some programs provide program-specific smoothed font configuration outside of the GNOME or KDE settings, so if you find that some programs don't use font smoothing, you may want to check the configuration options for the programs that don't deliver smoothed fonts.

Configuring Fonts in Xft

Xft font configuration varies with the Xft version. No matter the version, the most important steps are similar to those required for configuring X's standard font access, but the details differ. Configuring Fonts in Xft 1.x

Xft 1.0 and 1.1 are configured using a file called XftConfig, which is typically located in /etc/X11. The most important lines in this file set the Xft font path using the dir keyword:

dir "/usr/X11 R6/lib/X11/fonts/Type1" dir "/usr/X11 R6/lib/X11/fonts/TrueType"

Typically, you point to all the directories on your normal X font path that hold outline fonts. Although Xft can deliver bitmap fonts, it's most frequently used only for outline fonts, so directories that hold bitmap fonts are usually omitted from the Xft font path. If you've added your own fonts to some other directory, such as /usr/local/fonts/tt, you can edit the XftConfig file to reflect this fact.

Individuals may also specify font directories in a file called .xftconfig in their home directories. Typically, this file contains just dir lines, formatted just like equivalent lines in the system-wide XftConfig file. This setup enables users to add fonts that other users might not want or need.

Xft 1 .x uses a file called XftCache in each font directory as an index to the directory's font files. This file is similar in concept to the fonts.dir file used by XFree86 orxfs, but the two files have different formats. If your directory doesn't have this file, Xft will create a file called -/.xftcache in your home directory when you try to perform certain key operations; this file then substitutes for XftCache files in your font directories. If you prefer to create a global file for all users, type xftcache ./ as root in each font directory; this command creates the requisite cache file. Alternatively, you can type xftcache with no directory specification to have it create the XftCache file in each directory on the Xft font path.

Xft tries its best to detect changes you make to your font directories as you make them, so you shouldn't need to restart X when you add fonts. Typing xftcache may help, but it isn't strictly required, because Xft will create an -/.xftcache file if necessary. Running applications may not notice changes to available fonts until you restart them, though.

Configuring Fonts in Xft 2.0

Xft 2.0 uses a completely different type of configuration than does Xft 1 .x. The 2.0 version of the library uses a configuration file called fonts.conf, which is typically stored in /etc/fonts. This file is actually an Extensible Markup Language (XML) file, so if you're familiar with XML, you should be able to parse much of its content. Most of the file consists of aliases for and elaborated information about specific fonts—for instance, marking Times as a serif font and Helvetica as a sans serif font. Near the top of the file, though, you'll find several directories listed between <dir> and </dir> codes, like this:

<dir>/usr/X11 R6/lib/X11/fonts</dir> <dir>/usr/share/fonts</dir>

These lines tell Xft to look for fonts in the specified directories and all their subdirectories. For instance, the first line shown here handles all the standard X font locations, and the second line handles /usr/share/fonts and its subdirectories.

It's not uncommon to see a directory such as -/.fonts included in the fonts.conf file. This entry enables users to add fonts by placing them in their -/.fonts directories. Xft 2.0 also looks for a secondary configuration file called -/.fonts.conf, so users can fine-tune their configurations.

Xft 2.0 uses a configuration file called font.cache-1. This file's format is the same as that of the XftCache file used by Xft 1 .x, and can be created with a utility called Fontconfig. Type fc-cache /font/dir, where /font/dir is the directory in which you've stored fonts, to generate a fonts.cache-1 file in /font/dir that describes the fonts in the directory. If you don't do this, Xft will create a .fonts.cache-1 file in each user's home directory that replaces the fonts.cache-1 files. As with Xft 1 .x, version 2.0 tries to spot changes to the font directories and implement them as soon as possible, so if you add or change files, you may see -/.fonts.cache-1 files appear or grow.

If you want to use Xft, but don't want it to apply font smoothing, you can tell the system to deliver unsmoothed fonts. To do so, add the following lines to your /etc/fonts/fonts.conf file:

<match target="font">

<edit name-'antialias" mode="assign"> <bool>false</bool>

If you want to use font smoothing for most, but not all, fonts, you can disable smoothing on a font-by-font basis using similar code. For instance, the following lines disable font smoothing for the Bitstream Vera Sans font:

<match target="font">

<test qual="any" name="family">

<string>Bitstream Vera Sans</string> </test>

<edit name-'antialias" mode="assign">

<bool>false</bool> </edit> </match>

Similar options are accessible from GUI tools for particular applications, as described in the next section, "Using Smoothed Fonts in Applications." Setting these options in the global fonts.conf file may be more convenient, though. The GUI methods also don't support font-by-font changes, as does the fonts.conf method.

Using Smoothed Fonts in Applications

KDE provides a pair of tools in its Control Center that relate to fonts. You can launch the Control Center from an item in the K Menu from the KDE Panel, or you can type kcontrol in an xterm to launch the program. The first tool is the Appearance & Themes O Fonts tool, which is shown in Figure 16.3. (This tool may be accessed under a different name in some distributions' KDE implementations.) The upper portion of this tool provides settings for the font you want to use for assorted common elements, such as the default ("general") font, the font used in menus, and so on. Click Choose to change any of these fonts. The bottom portion of this tool provides font smoothing options, in the Anti-Aliasing area. Check the Use Anti-Aliasing for Fonts option to enable font smoothing in KDE applications. You can also select a couple of sub-options. First, you can exclude a range of font sizes from font smoothing. You might do this if you like font smoothing in general, but not at some font sizes. Second, you can check the Use Sub-Pixel Hinting box to use this technique, which can improve the appearance of fonts on some liquid crystal display (LCD) monitors.

Figure 16.3: KDE provides tools to enable font smoothing for KDE applications.

The second tool available from the KDE Control Center is accessible from the System Administration Ó Font Installer index option. This tool helps automate font management. By default, it allows you to install fonts in the ~/.kde/share/fonts directory and its subdirectories. You can use this tool to copy fonts to this directory, whereupon the system automatically creates a fonts.dir file and tells various font systems, such as Xft and X, to use the fonts in this directory.

Note The KDE Control Center's Font Installer sometimes holds files open after accessing them. This feature means that installing a font directly from a CD-ROM may make it impossible to unmount the CD-ROM. KDE typically closes the files after a minute or two, so this problem corrects itself if you give it some time.

GNOME provides a font configuration tool known as Font Preferences. You can launch it by selecting the Applications Ó Desktop Preferences Ó Font menu item from the GNOME Panel or by typing gnome-font-properties in an xterm window. The result is the window shown in Figure 16.4. As with the equivalent KDE tool, this program enables you to set font preferences for applications that use it—mostly GNOME programs. You can set the default application font, the font used by desktop icons, and so on. The Font Rendering area includes options related to font smoothing, although that term isn't used. The Monochrome option disables font smoothing and the remaining options enable it, but with variations that work well for different types of displays. In particular, the Subpixel Smoothing (LCDs) option is worth trying on LCD monitors and notebooks. Clicking Details brings up another dialog box with more options, such as the extent to which GNOME applications use hinting and some details related to the subpixel smoothing option.

Figure 16.4: GNOME'S Font Preferences dialog box enables you to select GNOME fonts and set font-smoothing options.

Other programs can use Xft independently of KDE or GNOME, and so they may have their own font configuration tools. Even KDE and GNOME programs may have application-specific font-setting tools. These options may set the font used in a document, as in a word processor's or web browser's display; or they may set display options, such as the font used in dialog boxes or menus. It's not always obvious whether a program is using Xft for such options, though; a program can use X fonts, Xft fonts, or even fonts it renders itself or by calling FreeType directly.

Team LiB

4 PREVIOUS

Team LiB

^ previous

0 0

Post a comment