Present - Programming - XFT/GTK2 configuration

XFT/GTK2 configuration

Table of Contents

Introduction

XFT and GTK2 enable X11 applications to draw antialiased fonts. However, they're new and fairly poorly documented, especially for users. This is my attempt to fix some of that.

This page is primarily aimed at users of free Unix-like operating systems which use XFree86 as their X server, such as Linux and FreeBSD. Filenames beginning with a dot, for instance .gtkrc, are located in each user's home directory. Other files, such as XftConfig, are elsewhere, which may vary by distribution. The command locate XftConfig should be able to find it.

XFT configuration

While some people think antialiased fonts are the most wonderful thing since transistors, I'm certainly not one of them. They're nice for certain size ranges, improving readability on small fonts and not hurting it on large ones. However, XFT's default is to antialias everything, which tends to butcher fonts near 12 points in size. (I object to having pieces of 2 and Z disappear.) This section is about making XFT stop antialiasing a certain size range. Subpixel rendering for LCD displays is covered elsewhere; either in a comment in fonts.conf for XFT 2, or on the Web.

Courtesy of Google, I found the following code snippet for XFT 1's XftConfig file from many sources:

# Turn off antialiasing for fonts in the 9-14 pt. range
match
	any size > 8
	any size < 15
edit
	antialias = false;

XFT 2 switched to an XML-based configuration file, which looks totally different. The following code snippet, which provides equivalent functionality to the one above, is nowhere else on the web at the time of posting. Add this to /etc/fonts/local.conf:

<!-- Turn off antialiasing for fonts in the 9-14 pt. range -->
	<match target="font">
		<test qual="all" name="size" compare="more">
			<int>8</int>
		</test>
		<test qual="all" name="size" compare="less">
			<int>15</int>
		</test>
		<edit name="antialias" mode="assign">
			<bool>false</bool>
		</edit>
	</match>

For much more detailed information on fonts and XFree86 in general, please see the Font De-Uglification HOWTO.

GTK2 configuration

GTK has also had a major overhaul, with most things becoming incompatible. Instead of ".gtkrc", GTK now uses ".gtkrc-2.0" for its configuration. To change the default font on GTK 2, insert the following in .gtkrc-2.0:

gtk-font-name = "Times New Roman 14"
Note that GTK 2 is using XFT 2, so fonts are specified in a simpler form than the old baroque XFLD system.

The include keyword is unchanged, so setting a GTK 2 theme is identical to setting a GTK 1 theme. Simply include the gtkrc for the desired theme, for instance:

include "/usr/local/share/themes/H2O-Saphire/gtk-2.0/gtkrc"
The quotes are necessary.

A word on GNOME2 and GTK2

GNOME 2 applies its own settings to GTK 2 programs with gnome-settings-daemon. When the daemon is running, GTK 2 programs will use the GNOME settings instead of those present in .gtkrc-2.0 for anything GNOME overrides.


This page is Copyright 2003 C. Daelhousen <loonxtall@hotmail.com> and covered by the legal page for the Present.