Friday, March 4, 2011

Improved Font Rendering With Lcd Filter Patches In Cairo

In a former post I wrote about a rebuilt libcairo2 with David Turner's patch to get better font rendering. Fonts looked great to my opinion, but maybe a little fuzzy to others.

So I have been looking a little bit further and came across these two pages :

I don't think any patching of libxft2 in Debian Squeeze is needed, so I describe here what I've done to patch libcairo2 :

(1) Go to : and download cairo-ubuntu.tar.gz.
tar xf cairo-ubuntu.tar.gz will yield a folder cairo-ubuntu containing cairo-respect-fontconfig.patch.
(2) Go to : and download cairo_1.8.10-2ubuntu1.debian.tar.gz.
tar xf tar xf cairo_1.8.10-2ubuntu1.debian.tar.gz will yield a folder debian/patches.
Inside are : 04_lcd_filter.patch and 06_Xlib-Xcb-Hand-off-EXTEND_PAD-to-XRender.patch.

Install packages needed to compile :
As root : apt-get install build-essential devscripts fakeroot
apt-get build-dep cairo

Make a folder in your home directory where all the work gets done :
mkdir source && cd source Inside source : mkdir cairo-patches cairo
Move these three patches from above to folder cairo-patches :

Getting source and patching :
cd cairo
apt-get source cairo
cd ./cairo-*
cp ../../cairo-patches/* ./debian/patches/
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

Modify the changelog :
dch -i
A text editor will open ( in my case nano ) and write something after the asterisk (*) :
Additional lcd filter patches
Save and close.
Compile packges and copy it to debs folder:
dpkg-buildpackage -rfakeroot -us -uc
Move one folder up : cd ..
The one we need : libcairo2_1.8.10-6.1_amd64.deb ( in my case on a amd64 )
As root : dpkg -i libcairo2_1.8.10-6.1_amd64.deb

Enable the lcd filter :
<!-- lcdnone, lcddefault, lcdlight, lcdlegacy -->
<match target="font">
<edit mode="assign" name="lcdfilter">

My complete .fonts.conf


  1. Do I need to patch libcairo2 1.10.2-1 the same way you did with version 1.8.10-6? Or it is already patched?

  2. No need to patch version 1.10.2-1, see :

  3. Thanks!!! and Thanks again!!!

    very useful tip, and it works like a charm!

    I wonder that this is not default in debian.

  4. Gracias hermano. Buscando el tutorial en foros y blogs español, y nada.

    Ésta es la única solución que encontré y funciona perfecto.

    Eres un genio en éstas cosas. Gracias por compartirlo.

  5. @1antares1 : Thanks for the complement. I had to go to for a translation. Here is your comment in English : "Thanks brother. Looking for the tutorial in Spanish blogs and forums, and nothing. This is the only solution I found and it works perfect. You are a genius at these things. Thanks for sharing."

  6. After reading and reading and searching. The only method that worked for me, along with the patch sources and fontconfig (many who had the net) was this ....

    Indeed, a big hello and thanks for putting this tutorial. I just had to cross the "antialias" - hintfull, for firefox I see perfect.

    Greetings brother, perfect and complete tutorial.

  7. r@ngf ~/source/cairo/cairo-1.10.2 $ patch -p1 -i ./debian/patches/06_Xlib-Xcb-Hand-off-EXTEND_PAD-to-XRender.patch
    patching file src/cairo-xcb-surface.c
    Hunk #1 FAILED at 844.
    1 out of 1 hunk FAILED -- saving rejects to file src/cairo-xcb-surface.c.rej
    patching file src/cairo-xlib-surface.c
    Hunk #1 FAILED at 1424.
    1 out of 1 hunk FAILED -- saving rejects to file src/cairo-xlib-surface.c.rej
    r@ngf ~/source/cairo/cairo-1.10.2 $

  8. @Anonymous

    No need to patch version 1.10.2-1, see :

  9. I want to apply a patch to libxft in Debian Squeeze
    How to impose these patches ?
    Please !

  10. + I want to apply a patch to freetype in Debian Squeeze
    How to impose these patches ?
    Please !

    1. Ask your question in the Debian forum ( ). Enough people to help you.