Monday, 15 June 2009

Bitmap fonts

Much as I love sub-pixel font rendering, I found that I was not impressed with the blurry mess that comes out when using small font sizes for Terminal windows. I had a look for good terminal fonts that clearly distinguish 0 (zero), O (capital O), I (capital I), l (lower case l) and 1 (one), and settled on Monte Carlo. However, Ubuntu disables bitmap fonts by default.

Enabling bitmap fonts
/etc/fonts/conf.d/ contains a bunch of symlinks to files in /etc/fonts/conf.avail/. One of these is 70-no-bitmaps.conf. I removed it and added a symlink to 70-yes-bitmaps.conf:

sudo rm /etc/fonts/conf.d/70-no-bitmaps.conf
sudo ln -s /etc/fonts/conf.avail/70-yes-bitmaps.conf /etc/fonts/conf.d/
sudo dpkg-reconfigure fontconfig


Note that I think I could have instead followed the instructions here to achieve the same thing in a slightly more pleasant way.

Installing the fonts
I put the font files, MonteCarloBold.pcf and MonteCarloMedium.pcf into the ~/.fonts/ directory. Then I rebuilt the font cache:

sudo fc-cache -v -f

Somewhere in the output there should be a line something like this:

/home/weeble/.fonts: caching, new cache contents: 4 fonts, 0 dirs

(I have some other fonts in there too.)

I needed to log out and in again to see the results.

My eyes, they burn!
Once you've done all that, you will sooner or later discover why bitmap fonts are disabled by default. There are a bunch of nasty bitmap fonts installed with names like "Helvetica" and "Times". These appear when applications or web pages request those font names expecting to get a lovely outline font. To fix this, you can either remove those fonts entirely or add rules to stop them from being used. I went with the latter option, creating a ~/.fonts.conf file:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- ~/.fonts.conf for per-user font configuration -->
<fontconfig>

<!--
    Private font directory
-->
<dir>~/.fonts</dir>

<rejectfont>
    <glob>/usr/share/fonts/X11/*</glob>
</rejectfont>

</fontconfig>


NOTE:I previously had a much more complicated .fonts.conf file which I didn't fully understand but had constructed by trial and error. Every so often I'd find a web-page that used some new obscure font that happened to be included in with the bitmap fonts, and have to add something for it. This new one just blacklists all the built-in bitmap fonts, so only the news ones I've installed to ~/.fonts will be available.

You do not need to rerun fc-cache or reboot after updating .fonts.conf, but you may need to restart an application before it will pick up the correct fonts.

When I was messing around with .fonts.conf, I found the fc-match command invaluable. If you give it a font-name it will tell you what font would actually be rendered. If you also specify --sort, it will list all the fonts that could match in order of preference. Be careful not to mistype font names in the .fonts.conf file, it took me ages to realise my rules weren't firing because I'd mistyped "Bitstream" as "Bitsteam".

Monte Carlo in a terminal window:

No comments:

Post a Comment