Ubuntu, Font Hinting, & You: A Cautionary Tale

14 Responses · April 17, 2009

This post was writ­ten regar­ding Ubuntu 8.10, Intre­pid Ibex.

This isn’t the first time I’ve encoun­te­red hin­ting; I’ve seen it before in GIMP, even when I was using it in Win­dows, this font ren­de­ring option that was inex­pli­cably on by default, and resul­ted in horri­ble ker­ning and missha­pen let­ter­forms. I don’t claim to know a lot about the tech­ni­ca­li­ties of hin­ting, but everything I do unders­tand about it agrees that it is meant to improve the sha­pes of let­ters. If this is the case, some­body is doing something very, very wrong. I haven’t seen a hin­ted font that loo­ked anything other than sickly and disheveled.

I’ve com­plai­ned before about the typo­graphy in Ubuntu, but my con­ten­tion then was with the fonts that were in use by default, not with the way they were ren­de­red. What I didn’t rea­lize at the time is that the ren­de­ring is the bulk of the problem.

applicationsmenuI found this image on the Ubuntu site, and I am still in dis­be­lief that they choose to repre­sent them­sel­ves with font ren­de­ring like this. Look at that capi­tal ‘A’ and ‘V’; look at the way that lower-case ‘l’ towers over its neigh­bors, nothing more than a single-pixel-width ver­ti­cal line; look at the ker­ning in the ‘Rem’ of ‘Remove’ – it’s no won­der Ubuntu has about a 2% world­wide mar­ket share. They expect peo­ple to want to look at that every day of their lives? I know these are rela­ti­vely subtle details, but their effects are subli­mi­nal and, I believe, psycho­lo­gi­cally hazardous.

~/.fonts.conf

Of course, when it comes to Linux, for every pro­blem there are a few dozen solu­tions – or one very, very com­pli­ca­ted solu­tion. GNOME, the default desk­top for Ubuntu, arri­ves with a “Font Ren­de­ring Details” dia­log box in its appea­rance set­tings, to pla­cate the mouth-breathing phi­lis­ti­nes who need a GUI to get things done. And it doesn’t really help much. I knew I’d have to get my hands dirty in ~/.fonts.conf, this XML file that is capa­ble (and only capa­ble) of inc­re­dibly fine-tuned font tweaking.

[Fonts are] the #1 rea­son why Linux hasn’t seen any sig­ni­fi­cant adop­tion on the desktop/laptop yet. Robert Sco­ble

The trou­ble, as is the case with most Goo­gle results you get when loo­king for help with Linux, is that there is a glut of quick fixes, blocks of code direc­ted towards one spe­ci­fic per­son and their spe­ci­fic sys­tem, that they are then told to paste into a file or save into a direc­tory, with little to no expla­na­tion about why this solu­tion is going to work. Or there’s the tech­ni­cal docu­men­ta­tion that isn’t gea­red towards users. There’s no middle ground (unless you count the occa­sio­nal, ske­le­tal wiki that hasn’t been upda­ted since 2004).

Only after loo­king at count­less ~/.fonts.conf exam­ples was I able to glean what was going on inside them. The full power of this file allows you to tar­get with ama­zing pre­ci­sion any variant or size of any font your sys­tem might dis­play and give it its own uni­que pro­per­ties; but there are really only three(ish) of these pro­per­ties that you need to know about, and I am going to explain them here.

antia­lias

Anti-aliasing is the trick that makes your pixels not look like pixels. You’ve noti­ced this when you’ve seen poorly resi­zed ima­ges with jag­ged edges – they’re not pro­perly anti-aliased. Simi­larly, if fonts are not anti-aliased, they look like black Tetris pie­ces on a white back­ground. Anti-aliasing is going on all the time without you kno­wing about it, and you’d really have to make an effort not to have it, but it’s worth put­ting in your ~/.fonts.conf file for good mea­sure. You’ll want to apply it to all fonts on your sys­tem, so the syn­tax would be:

<match target="font">
 <edit name="antialias" mode="assign">
  <bool>true</bool>
 </edit>
</match>

You can pro­bably figure out what these things mean, but I will link to a com­plete manual for ~/.fonts.conf syn­tax at the end of this post.

rgba

This one is a mat­ter of per­so­nal pre­fe­rence, I guess. I don’t see how any­body of sound mind could stand to have pink, beige, and tur­quoise pixels sprin­kled around the edges of their let­ters – the result of “sub-pixel ren­de­ring” – but I guess the argu­ment is that it allows them to be shar­per. Whatever.

Trust me when I say that things look best if you tell ~/.fonts.conf to disa­ble sub-pixel ren­de­ring, which is done like so:

<match target="font">
 <edit name="rgba" mode="assign">
  <const>none</const>
 </edit>
</match>

If you hap­pen to be schi­zoph­re­nic, or color­blind or wha­te­ver, then yes, fine, you can turn on sub-pixel ren­de­ring by chan­ging none to rgb, to reflect the com­po­si­tion of your monitor’s sub­pi­xels (which are almost cer­tainly in the order Red-Green-Blue, from left to right). Have fun scratching your eye­balls out.

rgba=rgb

rgba=rgb

rgba=none

rgba=none

Admit­tedly it would be nice if there were some antialiasstyle pro­perty you could set to antialiasslight or something, to ligh­ten up those gray pixels a little bit.

hin­ting / autohint / hintstyle

Put it on my tombs­tone: Turn Off Hin­ting. I’m beg­ging you. If some­body tries to tell you that this is a mat­ter of pre­fe­rence, they are lying to you, and are not your friend, and are pro­bably ban­ging your girl­friend. If you leave hin­ting on, Geor­gia will not look like Geor­gia, Lucida will not look like Lucida, and Nim­bus will not look like Helvetica.

hintstyle=hintnone

hintstyle=hintnone

hinting=true, autohint=true

hinting=true, autohint=true

Here is how you Turn Off Hinting®:

<match target="font">
 <edit name="hinting" mode="assign">
  <bool>false</bool>
 </edit>
 <edit name="autohint" mode="assign">
  <bool>false</bool>
 </edit>
 <edit name="hintstyle" mode="assign">
  <const>hintnone</const>
 </edit>
</match>

Alter­na­ti­vely, if you posi­ti­vely demand more “crisp­ness” from your fonts, even at the expense of aesthe­tics, you might want to give slight hin­ting a try. From the above code, change hinting and autohint to true, and hintstyle to hintslight:

hintstyle=hintslight

hintstyle=hintslight

That’s it, roughly spea­king. It’s my unders­tan­ding that some spe­ci­fic fonts do look bet­ter if spe­ci­fi­cally tar­ge­ted and adjus­ted with maybe slight hin­ting. But that’s for another day. If you do as I’ve ins­truc­ted, things will be so much bet­ter for you. Leave a com­ment if you want my Pay­Pal address.

This post would not have been pos­si­ble without the help of these sites:

  • Arch­Wiki: I know nothing about Arch Linux, but this wiki page has a lot of good info.
  • fontconfig.org: the most com­plete and recent ~/.fonts.conf refe­rence I’ve found.
  • Ubuntu Wiki: con­tains an exam­ple of a very com­prehen­sive (if dated) ~/.fonts.conf file. Study it and learn how to do other stuff.
  • The Mas­ter­plan: another sam­ple ~/.fonts.conf file, and the only other one that I know of that turns off hin­ting and sub­pi­xel rendering.

Thanks for the font twea­king tip. It really impro­ved the look of my Ubuntu Jaunty — in com­bi­na­tion with a font size of 9 (from the default of 10), the fonts look beau­ti­ful now.

Biju Kunjummen · May 18, 2009

Glad to know it hel­ped, Biju. I’m still very plea­sed with the way this makes things look. It’s also use­ful to browse through all your font pre­fe­ren­ces — in Appea­ran­ces, in Fire­fox, etc. — and make sure everything is set to a good font; DejaVu ins­tead of Sans, for ins­tance. UnDo­tum makes a great tit­le­bar font.

Jay · May 18, 2009

Thanks ever so much for this help­ful post. I’ve been searching linux forums in vain for a pro­per fonts.conf set­ting. Ever­yone seems per­fectly happy with rgba tur­ned on and hint­full — I, howe­ver, found myself get­ting hea­daches from all the color halos and awful ker­ning. In fact, when I first arri­ved at your site, the let­ters were smashed together from a disas­trous hin­ting set­ting. Now, everything looks very ele­gant — and no more headaches!

Matt · May 18, 2009

Although you put something to extre­mity, I agree with most of this post. I did tune much accor­ding to your post with fonts.conf, yet finally I just use the easiest way: choose “best con­trast” (which means gray-scale, hin­ting full), I thus tur­ned off rgb hin­ting and use only gray-scale hin­ting and I’m rather happy. Being a gdi++ fan, I still think there’s huge job left for Linux deve­lo­pers, though.

Thanks.

kmc · May 20, 2009

The sub-pixel ren­de­ring blow-up isn’t really a fair repre­sen­ta­tion unless you cut the blown up pixels into R, G and B stri­pes. The blue stripe on the lower case L in Goo­gle is really 2/3 black with a blue stripe in the last third of the pixel. Who sits close enough to their screen to see indi­vi­dual pixel com­po­nents, anyway?

Abe · June 3, 2009

Abe: You are right, it was a little lazy of me to do blow-ups like that. They weren’t so much to “prove” that sub­pi­xel ren­de­ring looks bad as they were to see more clo­sely what’s going on. I sup­pose I could have been clea­rer about what we’re loo­king at, though per­so­nally I think the normal-sized text is enough to show that sub­pi­xel ren­de­ring looks bad.

Jay · June 8, 2009

To me this is the wrong way around. On 8.10, if I turn off hin­ting, I get the kind of rub­bish that you pos­ted from the ubuntu web­site. Bad ker­ning, unba­lan­ced let­te­ring, wildly var­ying den­sity of text when you squint at a para­graph, etc.

Are you using fire­fox 3.5beta? Ive noti­ced the beta is very sig­ni­fi­cantly defi­cient when it comes to font ren­de­ring — par­ti­cu­larly if you have rgb sub­pi­xel ren­de­ring tur­ned on. On FF3.0.5 with rgb, antia­lias, autohint, hint­full, you can barely detect color frin­ging. On 3.5beta, it looks appa­lling, par­ti­cu­larly light text on a dark back­ground, or when you select text. The balance is OK, but the color frin­ging is terrible.

Jack · June 18, 2009

Actually, Ie noti­ced this varies a lot depen­ding up the zoom fac­tor I use in fire­fox. The other point is that Iḿ run­ning on Crunch­Bang linux, and I think the libs have the pro­prie­tary hin­ting code ena­bled, so hin­ting pro­bably looks much bet­ter than the stock ubuntu libs.

Jack · June 18, 2009

Thanks for finally making font ren­de­ring clear. Every serif font loo­ked awful! I mostly blame autohint… and I agree with you: turn it off already!

Flavio · June 18, 2009

@Jack: Yeah, I am run­ning Fire­fox 3.5. When I wrote this I was pro­bably run­ning 3.1 beta 3 or something. But the pro­blems with frin­ging and hin­ting see­med to extend beyond Fire­fox, so who knows. And I think it was in 8.10 that I was tes­ting these things out. There are too many varia­bles to really sin­gle anything out as the cul­prit, although because I am run­ning a pretty stock ins­tall of Ubuntu, I am assu­ming that most novi­ces like me will pro­bably be get­ting the same results.

@Flavio: Glad to help! I was also enor­mously relie­ved to finally be happy with the way text loo­ked in Ubuntu. It’s ama­zing what a dif­fe­rence it makes.

Jay · June 19, 2009

Nice! I find font hin­ting (on both Win­dows and Ubuntu) so bad that some­ti­mes I strug­gle to deter­mine whether a space is an inter-character space as oppo­sed to an inter-word space.

The other major ren­de­ring issue is the lack of gamma correc­tion. (I ima­gine using a deco­ding gamma of 2.5, blen­ding and re-encoding with gamma=1/2.5 should work well, since font ren­de­ring is not sub­ject to the ren­de­ring intent of the enco­ding gamma of 1/2.2 for ima­ges view in dim surroundings.)

As it is, font stroke weights vary accor­ding to their orien­ta­tion and posi­tion. It’s hard to tell what is meant to be bold and what is not. Some­ti­mes in order read a bit of text I have to make a screen snapshot and apply the correc­tion in Pho­toshop myself (mainly with Adobe’s Acro­bat Rea­der). A black ver­ti­cal line one pixel wide exactly cen­tred on the boun­dary of two adja­cent pixel columns should have values RGB(193,193,193) in each column.

Obviously this will ligh­ten the ove­rall text somewhat. That’s because the font weight was cho­sen to look as best as pos­si­ble on ren­de­ring sys­tems with no gamma correction.

It’s kinda odd that most peo­ple don’t rea­lise they are wor­king with com­pres­sed ima­ges. (They are gamma-compressed.) All image arith­me­tic — sca­ling, blen­ding, dithe­ring and trans­pa­rency hand­ling — needs to be done with uncom­pres­sed images.

Daniel · July 8, 2009

As someone who cares a lot about font dis­play and typo­graphy in gene­ral I sym­pathize with these frus­tra­tions, but I’m pretty sure nothing was done by edi­ting the font con­fig file that isn’t easier for most users to accom­plish through the Appea­rance Pre­fe­ren­ces GUI (Fonts tab … but then click ‘details’).

The effec­ti­ve­ness of sub­pi­xel ren­de­ring varies depen­ding on the moni­tor and, to some extent, the way the font hap­pens to line up against the pixel grid. On both of my com­pu­ters, it works beau­ti­fully, a major boost to the hori­zon­tal reso­lu­tion. I’ve seen that headache-inducing aura on some screens, but peo­ple who com­plain that sub­pi­xel ren­de­ring is une­qui­vo­cally a nui­sance should con­si­der that their hard­ware may not repre­sent the typi­cal expe­rience (i.e., no, your eyes aren’t more sen­si­tive than ours). (Disc­lai­mer: I don’t mean to sug­gest the author thinks this.)

I find myself occa­sio­nally switching bet­ween no-hinting and slight-hinting. Neither is quite right. What would be great (for sub­pi­xel users any­way) would be something like “ver­ti­cal hin­ting only.” Using slightly lar­ger font sizes than is stan­dard can make things look a whole lot bet­ter, if you’re willing to adjust to it. The more recent MS fonts are of exce­llent qua­lity and carry over beautifully.

bath · October 19, 2009

These ins­truc­tions are fan­tas­tic if you enjoy text that looks like it was writ­ten on a paper towel with a felt tip pen. If, on the other hand, you actually read text and don’t just con­si­der it deco­ra­tion, you’ll want to skip this and let the “crisp­ness” win out over the “aesthe­tics” that gives the author the vapours.

Disciple of "Bob" · October 20, 2009

Do not lis­ten to this man! He means to deceive you!

@Bath: Actually, choo­sing “None” in the hin­ting sec­tion of font appea­ran­ces doesn’t truly remove hin­ting, it only redu­ces it to slight. Weird, huh?

Jay · October 20, 2009

Leave a Comment or Subscribe