Sunday, June 25, 2006

Disabling bitmapped fonts

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...

7 comments:

Jason said...

Excellent timing. I had just installed Firefox recently and had given up on the fonts assuming that "that's just how it is." Now my screen is much easier on the eyes.

Anonymous said...

I had an opposite goal: my applications were using anti-aliased scalable fonts and i didn't like the fuzzy look. I wanted to use the bitmapped Helvetica font included with the X11 distribution, which is optimized for low resolution. So I've configured my .fonts.conf to prefer Helvetica if an application request sans-serif, and to my .gtkrc-2.0 I have added

style "default" {
font_name = "Helvetica 12"
}

Now the user interface elements are drawn using the bitmap font, which I find much more pleasant. For some reason I don't see the bitmapped fonts not rendered in their native size.

-- Pavel Cahyna

Anonymous said...

Hija Julio,

it works like a charm! Its even a lot faster on this old crumpy machine :) never thought that the rescaling of the bitmaps took more time than rendering.

Thanks again :)

Reinoud

Julio M. Merino Vidal said...

Pavel: I also saw very blurry fonts on my LCD until I enabled subpixel rendering (or something like that, cannot remember the name; it's in GNOME's font control panel). This has improved readability. And I also disable AA for very small fonts.

Reinoud: I wouldn't expect it could improve speed! Good to know :-)

ghen said...

Hm, I *thought* my fonts were ok, until I enabled your trick. They look much nicer now, thanks! :-)

Ricardo said...

Thanks for your trick :)

On NetBSD 3.1 I had to copy 70-no-bitmaps.conf from /usr/share.../fontconfig to /usr/pkg/etc/fontconfig. Doing that in /etc/fonts did not work.

It also seems faster for me.

Julio M. Merino Vidal said...

Ricardo: That's because you have two installations of FontConfig (as happens in NetBSD). One comes from the version bundled into XFree86/X.Org, and thus has its configuration files in /etc/fonts. The other comes from pkgsrc and has its files in /usr/pkg/etc/fonts. If you configure only one of them, some applications (those that use the bundled fontconfig) may not behave as you expect.