Since the advent of GTK2 I hadn't really bothered with this old, seemingly outdated, beast called GTK 1. However, there are some useful applications which are linked against it and I'd like to use them. Most prominently, it's the Lazarus IDE (the GTK2 interface is buggy and the Qt interface requires tons of hacks to work). The most proinent problem I just couldn't stand is that the default font used in GTK1 apps looks ugly, so ugly it hurts my eyes and renders GTK1 applications unusuable. Fortunately, changing the default font is almost easy; you do have to edit some configuration files.

These instructions have been tested with Mandriva Linux 2009.0, but similar - if not identical - steps should be performed on other Linux distributions as well.

GTK1 stores its master configuration files in /etc/gtk. There are dozens of files in there. To find the correct one, you must know your locale settings. To do so, open a console and issue the locale command. The output on my system looks like this:

LANG=el_GR.UTF-8
	LC_CTYPE=el_GR.UTF-8
	LC_NUMERIC=el_GR.UTF-8
	LC_TIME=el_GR.UTF-8
	LC_COLLATE=el_GR.UTF-8
	LC_MONETARY=el_GR.UTF-8
	LC_MESSAGES=el_GR.UTF-8
	LC_PAPER=el_GR.UTF-8
	LC_NAME=el_GR.UTF-8
	LC_ADDRESS=el_GR.UTF-8
	LC_TELEPHONE=el_GR.UTF-8
	LC_MEASUREMENT=el_GR.UTF-8
	LC_IDENTIFICATION=el_GR.UTF-8
	LC_ALL=

Find the LC_MESSAGES line. The part after the equals sign is your locale. On my system it is el_GR.UTF-8 as you can see. Now, go to the /etc/gtk directory and edit the file named gtkrc.yourlocale where yourlocale is the locale you found above! On my system this would be gtkrc.el_GR.UTF-8.

This file's contents look like this:

style "gtk-default" {
fontset = "
	-*-kerkis-medium-r-normal--12-*-*-*-p-*-iso10646-1,
	-*-clearlyu-medium-r-normal--17-*-*-*-p-*-iso10646-1,
	-*-r-*-iso10646-1,*"
}
class "GtkWidget" style "gtk-default"

As you can see, the font definitions are in an obscure format which was used many, many years ago. Finding the correct font definition for your system looks hard, but no, it's just tricky.

Your system stores fonts definitions inside the fonts.dir files which reside in your fonts' directories. On Mandriva Linux 2009.0 I found that the great-looking Liberation family's font files reside in /usr/share/fonts/TTF/liberation. So, all I had to do was to open the fonts.dir file from that directory!

The next step is locating the correct font definition. If your locale is using the UTF-8 encoding (the most common these days), you have to find a font definition for the iso10646-1 encoding. The reason is simple: ISO10646-1 is the Unicode encoding! Browsing through the file, I was able to locate the definition line for Liberation Sans, regular. It looked something like:

LiberationSans-Regular.ttf -misc-Liberation Sans-medium-r-normal--0-0-0-0-p-0-iso10646-1

The part after the font file name (in this case -misc-Liberation Sans-medium-r-normal--0-0-0-0-p-0-iso10646-1) is what you need!

Go back to the GTK file you were editing. Right below the fontset=" line, paste the font definition you just found and append the , line continuation sequence. If you fail to do this last part, you're screwed. So, the file would now look something like this:

style "gtk-default" {
fontset = "
	misc-Liberation Sans-medium-r-normal--0-0-0-0-p-0-iso10646-1,
	-*-kerkis-medium-r-normal--12-*-*-*-p-*-iso10646-1,
	-*-clearlyu-medium-r-normal--17-*-*-*-p-*-iso10646-1,
	-*-r-*-iso10646-1,*"
}
class "GtkWidget" style "gtk-default"

Still, this is not 100% correct because we haven't defined a font size and we are forcing other properties (bold, italics) to be cleared as well. In order to fix this, we have to change the 0-0-0-0-p-0 part of the font definition to 12-*-*-*-p-* (you can use different values than 12 to suit your taste, it's the font's height in pixels so just toy around). The file would now look something like this:

style "gtk-default" {
	fontset = "
	misc-Liberation Sans-medium-r-normal--12-*-*-*-p-*-iso10646-1,
	-*-kerkis-medium-r-normal--12-*-*-*-p-*-iso10646-1,
	-*-clearlyu-medium-r-normal--17-*-*-*-p-*-iso10646-1,
	-*-r-*-iso10646-1,*"
	}
	class "GtkWidget" style "gtk-default"

You are done! Save the file and (re)start your GTK1-based apps!

No thoughts on “Changing the GTK 1 font”