A week ago or so I reinstalled NetBSD — 3.0_STABLE, not current — on my machine, finally replacing the previous unstable and out-of-control system. I had to do it to get some work done more easily than on Windows and to be able to keep up with my developer duties.

After a successful and painless installation, I built and installed Firefox and Windowmaker, both of which come handy from time to time (specially while rebuilding the entire GNOME Desktop). However, launching Firefox under a plain Windowmaker session greeted me with extremely ugly fonts. The GTK interface was OK, but web pages were rendered horribly in general. It was simply unusable.

At first I thought it had to do with the anti-aliasing configuration, but several attempts to change its details only resulted in worse fonts. The same happened when dealing with DPI settings. So what was happening? It turns out that Firefox was using bitmapped fonts instead of vector ones — and you know how ugly these look if they are not rendered in their native size.

Firefox was asking Fontconfig (X's font configuration and access library) to provide a font from the Serif family, without caring about which it could be. Fontconfig then provided it with a bitmapped font. (I still don't know why it preferred those over any other.)

The nice thing is that you can tell Fontconfig how to match generic font names to the fonts you really have. And this effectively means that you can force it to never use bitmapped fonts. All I had to do was to create a custom local.conf file in Fontconfig's configuration directory (/etc/pkg/fontconfig in my case):
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<include>conf.d/no-bitmaps.conf</include>
</fontconfig>
The curious thing is that GNOME seems to take care of this on its own because Firefox uses nice fonts under it even if you do not touch Fontconfig files.

Oh! Be aware that NetBSD has two Fontconfig installations: one from the native XFree86 installation and one from pkgsrc. These are configured in different directories: /etc/fonts and PKG_SYSCONFDIR/fontconfig respectively.

Don't know if this issue also happens in other operating systems if Fontconfig is not manually configured...