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:

Python 2.6.2 and Pygame 1.8.1

After an unfortunate incident with Ubuntu Jaunty, I am back to a fresh install of Ubuntu Intrepid. I still have most of my user folder, but I have to reinstall everything. And I'll probably have to do it again. This blog is to keep a record of what I had to install.

First up, Python 2.6 and Pygame, because I have a little project that is dependent on both. There's no package for Python 2.6 in Intrepid, so I'm installing from source. As far as I can tell there's no risk of upsetting anything else on the system so long as you don't replace the /usr/bin/python symlink.

Getting the source
Python 2.6.2: http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
Pygame 1.8.1: http://www.pygame.org/ftp/pygame-1.8.1release.tar.gz

Getting dependencies for Python
sudo apt-get build-dep python2.5
sudo apt-get install tk8.5-dev


Dependencies for Pygame
sudo apt-get install libsdl-ttf2.0-dev
sudo apt-get install libsdl-image1.2-dev


Build and install Python
tar -xvf Python-2.6.2.tgz
cd Python-2.6.2/
./configure
make
sudo make altinstall
cd ..


Build and install Pygame
tar -xvf pygame-1.8.1release.tar.gz
cd pygame-1.8.1release/
sudo python2.6 setup.py install
cd ..