[Update 2011-06-25: Confirmed. Updating Iceweasel from http://mozilla.debian.net/ fixes fonts. See this post for more info. So there's no longer any real need to do what's below.]
[Update 2011-06-24: This whole business may be unnecessary as it appears installing a recent version of Iceweasel from http://mozilla.debian.net/ also installs new libcairo2 with decent font rendering. I've yet to do careful comparisons, but it's possible that this solves both "ugly rendering in general" as well as "ugly rendering in Firefox" issues.]
[Update 2011-03-08:] Reader datSilencer points out that the location of the Arch patch has moved. Therefore, the process for extracting and applying the Arch patch won't work. I am updating the script but I won't be updating this post. If you want to do things manually, please consult the script for the needed changes.]
[Update 2010-09-23: I made a script to semi-automate a lot of the following.]
I love Debian. I really do. But one thing I don't love about Debian is the way it renders fonts in GTK. Or rather, the way Ubuntu renders fonts has spoiled me. After reading about how some people have successfully patched their libraries to use the same changes used by Ubuntu, I've finally succeeded myself. It's been so gratifying and such a good learning experience that I wanted to share.
The process below is based on information from the
CrunchBang Linux Forums and from one
quanliking. Huge, huge thanks to those people.
To get Ubuntu font rendering in Debian Squeeze, we need to download, patch, rebuild, and reinstall the libcairo2 package.
If this breaks your system don't sue me. I am not an expert nor do I play one on TV.
Pre-production
Begin by making sure downloading of package sources is enabled for apt. The line below should be in
/etc/apt/sources.list and not commented out:
deb-src http://ftp.us.debian.org/debian/ squeeze main non-free contrib
The actual address will differ depending on which mirror you set up your system to use, but there should be a line that begins "deb-src", has a mirror's address in the middle, and ends with "squeeze main non-free contrib" or "testing main non-free contrib".
Install the needed build tools (as root):
# apt-get install build-essential devscripts fakeroot
# apt-get build-dep cairo
As a regular user, create a new directory called
patched-packages in your home directory.
Get the patches
Open the
patched-packages directory you created above in a terminal (i.e., the prompt should read something like
username@computername:~/patched-packages$).
At the command prompt:
mkdir libcairo2
cd libcairo2
mkdir downloaded-patches
We now need to get two sets of patches, one from Ubuntu and the other from Arch Linux. To get the Ubuntu patches, go to
http://packages.ubuntu.com/lucid/libcairo2 and look at the list of links on the right. We want the file
cairo_1.8.10-{#}ubuntu1.debian.tar.gz. Download it into
~/patched-packages/downloaded-patches and expand it. This should produce a new directory inside
~/patched-packages/downloaded-patches called
debian (i.e., you should now have a
~/patched-packages/downloaded-patches/debian).
I'm not yet sure what the original source of the Arch Linux patch is, but apparently we need it. So go to
http://aur.archlinux.org/packages.php?ID=17327 and download the file
cairo-respect-fontconfig.patch into
~/patched-packages/downloaded-patches
You're done getting patches.
Get the sources
We now need to get the Debian source package for libcairo2. In a terminal inside
~/patched-packages/libcario2,
mkdir deb-sources
cd deb-sources
apt-get source cairo
cd ./cairo-*
Then copy the patches we downloaded earlier to the Debian package's patches directory:
cp ../../downloaded-patches/cairo-respect-fontconfig.patch ./debian/patches/
cp ../../downloaded-patches/debian/patches/04_lcd_filter.patch ./debian/patches/
cp ../../downloaded-patches/debian/patches/06_Xlib-Xcb-Hand-off-EXTEND_PAD-to-XRender.patch ./debian/patches/
Next, apply the patches to the sources:
patch -p1 -i ./debian/patches/cairo-respect-fontconfig.patch
patch -p1 -i ./debian/patches/04_lcd_filter.patch
patch -p1 -i ./debian/patches/06_Xlib-Xcb-Hand-off-EXTEND_PAD-to-XRender.patch
We now need to modify the changelog to indicate that we've diddled with the package and set a version increment:
dch -i
This will open a text editor. Once there, add
David Turner's ClearType-like LCD filtering patch and fix.
after the asterisk at the top and then save and exit.
(Note: Instead of dch -i above you can also use dch -l {your initials}.)
Build and install
Time to build it. Continuing from where we were in the terminal above (i.e., inside something like
~/patched-packages/libcairo2/deb-sources/cairo-1.8.10) do
dpkg-buildpackage -rfakeroot -us -uc
The result should be a bunch of new packages inside
~/patched-packages/libcairo2/deb-sources/
Look if you don't believe me. All that's left is to install. Open a root terminal and go to the
~/patched-packages/libcairo2/deb-sources/ directory. Then do:
# dpkg -i *.deb
This will install all the debs that were made, of which you may actually only need a subset. Apart from taking up some disk space the extra packages won't hurt anything, and if you install a package in the future that needs one of these, you'l be glad you installed them now.
Congrats. You should now have (IMHO) much improved font rendering. This should hold you until Debian releases a new libcairo2. If the new libcairo2 release doesn't have the "Ubuntu patches" already built in, you'll have to repeat the above process, making sure you get patches that are appropriate for the new version and that there are no additional patch files. (If there are, you will need to copy/add them before rebuilding.)
Rolling back your system to the original Debian packages should be as easy as using Synaptic to "Package -> Force Version..." to the original libcairo2 packages.
Happy building.