[OpenBSD]

Anti-aliasing and TrueType Fonts on OpenBSD

Table of Contents


xterm screenshot

xterm(1) with aliased and anti-aliased fonts side-by-side:
[Standard and anti-aliased xterm]

Konqueror screenshot

Still not convinced? Let's have a look at this.

The Konqueror Web browser with aliased and anti-aliased fonts side-by-side:

[Standard and anti-aliased Konqueror]

How does it work?

In order to support anti-aliased fonts, X has introduced in 2001 a new, client-side font rendering engine. The anti-aliasing calculations are done by FreeType, a free font engine that is used by a library called Xft(3), the X FreeType interface, The Render extension provides the compositing operations that are needed to blend the sup-pixel font shapes on the application background.

In addition X.Org uses the fontconfig(3) library to manage the installed fonts, including their names and properties.

What needs to be done to get it?

Basically, nothing. OpenBSD ships X.org with the X Render extension enabled in all video card drivers at 8 bit per pixel and more.

You can verify that the Render extension is enabled by running:

$ /usr/X11R6/bin/xdpyinfo | grep RENDER RENDER

In addition to the Bitstream Vera fonts family that ship with OpenBSD, a collection of popular True Type fonts has been compiled and is available in the OpenBSD ports tree, in /usr/ports/x11/msttcorefonts. They can be installed by doing the following:

# cd /usr/ports/x11/msttcorefonts # make install

The ports collection also include other TrueType fonts packages, especially the liberation fonts that can be used as a replacement for the Microsoft Web fonts above and are distributed with a more acceptable license.

Which applications can use anti-aliased fonts?

Any application that interfaces with the Xft library can display anti-aliased fonts. This includes QT 3.x (KDE 3.x) and GTK+2 (Gnome 2.x) applications. Standard X programs that use this interface include xterm(1), xclock, and a few others.

xterm

xterm can be invoked with arguments that enable Xft rendering of fonts:
$ xterm -fa 'Mono' -fs 14
These options are:
Option Resource Meaning ---------------------------------------- -fa XTerm*faceName Font face name -fs XTerm*faceSize Font size
Alternatively, X resources can be used. They are by default placed in $HOME/.Xdefaults and are controlled through the xrdb(1) program.

Some TrueType fonts (such as Arial, Georgia, and Verdana, for example) don't work well in xterm. This is because xterm uses the maximum width of all characters in the specified font to display each character. With a monospace font, the widths of all the characters are the same, and everything works. With a proportional font, such as the ones just mentioned, xterm fits each character into a cell the size of the maximum width, creating unreadable large gaps between characters.

QT 3.x/KDE 3.x applications

Applications that use QT 3.x, such as any KDE 3.5.x applications, including Konqueror, use Xft rendering by default.

GTK+2 applications

GTK+2 applications also use Xft by default now.

How can I add fonts manually?

Adding a TrueType font "to X" requires registering the font with both the fontconfig library and the X server since both keep track of fonts separately.

Client-side font rendering system

Fonts installed as package from the ports collection are registered automatically to the fontconfig system. Fontconfig uses the file /etc/fonts/fonts.conf for its main system-wide configuration, but since this file will be replaced on subsequent X upgrades, /etc/fonts/local.conf should be used instead to manage system-wide changes. Fontconfig searches for fonts in all sub-directories of the directories listed in fonts.conf. So there's no need to edit this file when new fonts are added in those hierarchies.

After the directory is added, the font cache for the directory will need to be regenerated. The following command instructs fontconfig to rebuild the font caches for all directories specified in its configuration:

# /usr/X11R6/bin/fc-cache -v
These changes will take effect in the current X session, so X itself will not need to be restarted, but running applications will.

The fc-list command can be used to list all know fonts to the system. Beware, this command outputs international fonts names encoded in UTF-8. So it's better to run it in an UTF-8 capable terminal emulation program, such as uxterm.

The server-side rendering system

Font paths (i.e., directories containing fonts) are managed either directly by the X server in /etc/X11/xorg.conf or by a separate program such as xfs(1). To add a font, add the directory where it resides to /etc/X11/xorg.conf:
Section "Files" FontPath "/usr/X11R6/lib/X11/fonts/TTF/" FontPath "/usr/local/lib/X11/fonts/myfonts/" ... EndSection
Or, if using xfs, add the directory to /etc/X11/fs/config:
catalogue = /usr/X11R6/lib/X11/fonts/TTF/, /usr/local/lib/X11/fonts/myfonts/
Next, the X server must be made aware of the font in that directory's font index, i.e., the file fonts.dir. Traditionally, all available sizes of a font were listed in the font index, generated by the mkfontdir(1) command. But since TrueType fonts can be scaled to any size, listing every possible size is not required. Instead, scalable fonts are listed in the file fonts.scale which is recognized by mkfontdir when generating fonts.dir indexes.

To build a fonts.scale file, the program mkfontscale(1) can be used:

# cd /usr/local/lib/X11/fonts/myfonts # /usr/X11R6/bin/mkfontscale # /usr/X11R6/bin/mkfontdir
Finally, to apply the changes to the current X session, instead of restarting X, the following command can be used to re-examine the currently registered font paths for changes:
$ xset fp rehash
Or, if a new font path was added:
$ xset +fp /usr/local/lib/X11/fonts/myfonts
If xfs is being used, following should be used instead:
# pkill -HUP xfs

[back] www@openbsd.org
$OpenBSD: truetype.html,v 1.18 2007/08/26 10:03:59 matthieu Exp $