Beautiful Font Hinting in Ubuntu 8.10 and 9.04

Even though I have an LCD monitor, I always have the subpixel hinting switched off because it is just painfully ugly to my eyes. Even when hinting is switched to maximum, the fonts are quite blurry (if you don’t believe me, type xmag and take a screenshot of your font. You can see red and blue linese everywhere). My eyes hurt when I see this.

Thanks to Johan Kivinemi I have just found out how to bring back the excellent legacy subpixel hinting engine. This has a much more crisp hinting, and uses subpixels only where it really is an improvement:

Just open these files in your home directory, and copy the content into them:

~/.fonts.conf

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
  <match target="font">
    <edit name="antialias" mode="assign">
      <bool>true</bool>
    </edit>
    <edit name="hinting" mode="assign">
      <bool>true</bool>
    </edit>
    <edit name="hintstyle" mode="assign">
      <const>hintfull</const>
    </edit>
    <edit name="lcdfilter" mode="assign">
      <const>lcdlegacy</const>
    </edit>
    <edit name="rgba" mode="assign">
      <const>rgb</const>
    </edit>
  </match>
</fontconfig>

~/.Xresources

Xft.antialias:  true
Xft.hinting:    true
Xft.hintstyle:  hintfull
Xft.lcdfilter:  lcdlegacy
Xft.rgba:       rgb

This should work in Ubuntu 8.04, 8.10, and 9.04 too, and makes all fonts much more crisp. Of course, your mileage may vary.

UPDATE: Comparison Screenshots

As promised on reddit, I got back from an awesome snowboard trip so I am able to put up extensive comparison screenshots of the two subpixel hinting engines. Move your mouse over the following images to see the differences. Watch especially out for letters like “m” where the spacing between the lines is very small. You might have to wait a bit for the image to load.

I have used all of the most important fonts that I usually use, and just for fun I have added “Dijkstra”, which just looks cool.

Sans Fonts

Mouse to see the same fonts with the legacy hinter.

 

Mono Fonts

Mouse to see the same fonts with the legacy hinter.

 

Zoomed Comparison Screenhots

Here is an excerpt with 400% magnifications. Mouse over the pictures to see the legacy hinter.

Zoomed Sans

 

Zoomed Mono

 
  • don

    Screenshots?

  • http://www.knisely.org T. Shawn

    Just a question/suggestion..after this little hack is in place does one need to restart X for it to work?

  • SrcnShooter

    Before & after screenshots?

  • http://www.pluckypigeon.com James Gibbs

    I’m sure it should be lcdlegacy and not lcdfilterlegacy…

  • ochs

    The red and blue lines you get in xmag are a result of subpixel rendering… they look crappy if you magnify them, but better in normal resolution IF you have a LCD and the right subpixel ordering is configured.

    http://en.wikipedia.org/wiki/Subpixel_rendering

  • http://martin.ankerl.com/ Martin Ankerl

    Thanks James, I have fixed this.

  • Baughn

    Thanks, this helped a lot!

    But I wonder, why isn’t this the default?

  • http://johan.kiviniemi.name/ ion

    ochs,

    Translucent pixels or subpixels where they aren’t needed mean blurry text. Subpixel rendering or not, horizontal and vertical lines should only consist of 100% transparent and 100% opaque (sub)pixels.

  • krt

    Look at the “x” in Verdana 11; it has faded lines which only get worse when you mouse over it . . . The fix helps in many cases, but I have noticed some instances on particular letters such as “k”, “x”, etc., where the diagonal lines actually fade worse when using the improved rendering scheme . . . ? The problem seems to varie tremendously depending on the font size and font type.

  • http://martin.ankerl.com/ Martin Ankerl

    Hi krt, you are right it really looks as if the x is fading. I think it looks a bit better with the default renderer because it is more bold in general. I think the x looks so bad because the hinting information is not very good for this font size, so the font designer could have done a better job.

  • http://ahorabeta.com/ Felipe

    Hi there Martin,

    I just got here and tried your instructions. They worked fine, although I tried something else I found here and I feel it works even better, here it is:
    http://ubuntuforums.org/showpost.php?p=5024418&postcount=6

    Maybe you can try that and see if you like it better.

    Cheers
    Felipe

  • Juamez

    While lcdlegacy may make the fonts less blurry, the settings also makes the font “tingle” in a visual way. I have problem with it because to me the lcdlegacy setting makes the rgb subpixel hinting a lot more visible, with all sorts of weird colours appearing at the edges of fonts. This isn’t the case when I have it set to lcddefault. I’m using an LCD screen btw.

    Another question: is there a way to force grayscale smoothing instead of rgb smoothing in .fonts.conf or .Xresources? I already googled for it some hours, but nothing ever shows up.

  • http://julienpecqueur.com JPEC

    THANK YOU for the Tips!
    :)

  • James

    Happy (or shall I say disappointed) to say these tricks still work (and are required) in 9.04.

    Thanks! I’m beginning to think some of the Ubuntu developers are typography blind.

  • Vlad

    Doesn’t work in 9.04

  • http://personal.inet.fi/cool/l33tmmx/ uberl33t

    By the way, KDE doesn’t like the above .fonts.conf file format, it wants all the edit-tags separately between their own match-tags, like this:

    true

    true

    and so on.

    I don’t know why KDE is nitpicking on this. The example file works if you don’t touch anything, but if you experiment with KDE Control Center font settings, the file gets overwritten if it isn’t already in the correct format. So, could you please ‘fix’ the example .fonts.conf file so it works with KDE without trouble?

  • http://personal.inet.fi/cool/l33tmmx/ uberl33t

    Argh, the system tried to interpret the XML tags… Here’s an example without the arrows

    match target=”font”
    edit name=”antialias” mode=”assign”
    bool true /bool
    /edit
    /match
    match target=”font”
    edit name=”hinting” mode=”assign”
    bool true /bool
    /edit
    /match

  • http://na unbuntufied

    another way to fix how the font looks is to calibrate lcd monitor. goto http://www.lagom.nl/lcd-test/ to calibrate and the fonts will look better after

  • Pingback: Michael Alan Miller » Font of some wisdom

  • 6205

    Thank you very much.. It has helped me a lot in Ubuntu 9.04

  • Paladin

    Help me guys, it doesn’t work on my Ubuntu 9.04 :(

  • John

    Thank you so much Martin for the past couple of days I have been straining my eyes trying to figure out how to fix my font. Everything was red green and blue. Ubuntu must have change something, or maybe it was my new Nvidia GTX 285 card. I’ve never had a problem like this before, fonts have always been super crisp on Ubuntu. Thanks a bunch.

    Oh by the way I had a little trouble copying the code you had in this article. I had to go back and delete all the line numbers down the left side. You might want to change that especially if you post really long code on your site. It could be problematic in cases like that.

  • http://martin.ankerl.com/ Martin Ankerl

    Hi John, to copy the code to the clipboard click on “copy to clipboard” :-)
    Or, if this does not work, click “view plain” and copy the content from the popup window.

  • Josh S.

    Thanks for your help, Martin. Your files worked for me with Ubuntu 9.04, but they don’t work in Ubuntu 9.10. I changed “lcdlegacy” to “lcdnone” in both files in Ubuntu 9.10, and now the font rendering seems to look like it did in Ubuntu 9.04 after I used your files.

  • YChao

    Thanks a lot for the info. Just that it stops working after u/g to 9.10. Some how it’s always set to lcddefault when checked with “xrdb -query”. Would be great if this can be fixed.

  • http://n/a Erik

    Many Thanks Martin,

    Works perfectly in Ubuntu 10.04.

  • Pingback: Insanity « Igor's Blog

  • Pingback: Xft.lcdfilter on Fedora « Alex's Notes

  • MM

    I had a feeling that my fonts in Ubuntu 10.10 are broken on my laptop. Your solution works greatly on my Ubuntu 10.10 . Thank YOU.