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

 

24 Responses to “Beautiful Font Hinting in Ubuntu 8.10 and 9.04”

  1. don on January 23rd, 2009 7:53 pm

    Screenshots?

  2. T. Shawn on January 23rd, 2009 8:41 pm

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

  3. SrcnShooter on January 23rd, 2009 9:16 pm

    Before & after screenshots?

  4. James Gibbs on January 24th, 2009 2:48 am

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

  5. ochs on January 24th, 2009 8:20 am

    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

  6. Martin Ankerl on January 25th, 2009 11:37 pm

    Thanks James, I have fixed this.

  7. Baughn on January 27th, 2009 7:46 pm

    Thanks, this helped a lot!

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

  8. ion on February 3rd, 2009 2:23 am

    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.

  9. krt on February 26th, 2009 7:51 pm

    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.

  10. Martin Ankerl on February 26th, 2009 8:12 pm

    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.

  11. Felipe on February 27th, 2009 1:01 am

    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

  12. Juamez on February 27th, 2009 8:43 am

    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.

  13. JPEC on April 3rd, 2009 12:50 pm

    THANK YOU for the Tips!

    :)

  14. James on April 28th, 2009 2:22 pm

    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.

  15. Vlad on May 1st, 2009 6:11 pm

    Doesn’t work in 9.04

  16. uberl33t on June 24th, 2009 5:34 am

    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?

  17. uberl33t on June 24th, 2009 7:27 am

    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

  18. unbuntufied on June 24th, 2009 9:21 pm

    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

  19. Michael Alan Miller » Font of some wisdom on July 3rd, 2009 10:04 am

    [...] Here’s how you can change it, too. [...]

  20. 6205 on July 6th, 2009 2:08 pm

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

  21. Paladin on July 8th, 2009 6:22 pm

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

  22. John on July 22nd, 2009 11:09 pm

    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.

  23. Martin Ankerl on July 24th, 2009 2:21 pm

    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.

  24. Josh S. on November 28th, 2009 5:13 am

    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.

Leave a Reply