Ubuntu, Font Hinting, & You: A Cautionary Tale

This post was writ­ten regard­ing Ubun­tu 8.10, Intre­pid Ibex.

This isn’t the first time I’ve encoun­tered hint­ing; I’ve seen it before in GIMP, even when I was using it in Win­dows, this font ren­der­ing option that was inex­plic­a­bly on by default, and result­ed in hor­ri­ble kern­ing and mis­shapen let­ter­forms. I don’t claim to know a lot about the tech­ni­cal­i­ties of hint­ing, but every­thing I do under­stand about it agrees that it is meant to improve the shapes of let­ters. If this is the case, some­body is doing some­thing very, very wrong. I haven’t seen a hint­ed font that looked any­thing oth­er than sick­ly and disheveled.

I’ve com­plained before about the typog­ra­phy in Ubun­tu, but my con­tention then was with the fonts that were in use by default, not with the way they were ren­dered. What I didn’t real­ize at the time is that the ren­der­ing is the bulk of the prob­lem.

applicationsmenuI found this image on the Ubun­tu site, and I am still in dis­be­lief that they choose to rep­re­sent them­selves with font ren­der­ing like this. Look at that cap­i­tal ‘A’ and ‘V’; look at the way that low­er-case ‘l’ tow­ers over its neigh­bors, noth­ing more than a sin­gle-pix­el-width ver­ti­cal line; look at the kern­ing in the ‘Rem’ of ‘Remove’ – it’s no won­der Ubun­tu 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 rel­a­tive­ly sub­tle details, but their effects are sub­lim­i­nal and, I believe, psy­cho­log­i­cal­ly haz­ardous.

~/.fonts.conf

Of course, when it comes to Lin­ux, for every prob­lem there are a few dozen solu­tions – or one very, very com­pli­cat­ed solu­tion. GNOME, the default desk­top for Ubun­tu, arrives with a “Font Ren­der­ing Details” dia­log box in its appear­ance set­tings, to pla­cate the mouth-breath­ing philistines who need a GUI to get things done. And it doesn’t real­ly 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 incred­i­bly fine-tuned font tweak­ing.

[Fonts are] the #1 rea­son why Lin­ux hasn’t seen any sig­nif­i­cant adop­tion on the desktop/laptop yet. Robert Scoble

The trou­ble, as is the case with most Google results you get when look­ing for help with Lin­ux, is that there is a glut of quick fix­es, blocks of code direct­ed towards one spe­cif­ic per­son and their spe­cif­ic sys­tem, that they are then told to paste into a file or save into a direc­to­ry, with lit­tle to no expla­na­tion about why this solu­tion is going to work. Or there’s the tech­ni­cal doc­u­men­ta­tion that isn’t geared towards users. There’s no mid­dle ground (unless you count the occa­sion­al, skele­tal wiki that hasn’t been updat­ed since 2004).

Only after look­ing at count­less ~/.fonts.conf exam­ples was I able to glean what was going on inside them. The full pow­er of this file allows you to tar­get with amaz­ing pre­ci­sion any vari­ant or size of any font your sys­tem might dis­play and give it its own unique prop­er­ties; but there are real­ly only three(ish) of these prop­er­ties that you need to know about, and I am going to explain them here.

antialias

Anti-alias­ing is the trick that makes your pix­els not look like pix­els. You’ve noticed this when you’ve seen poor­ly resized images with jagged edges – they’re not prop­er­ly anti-aliased. Sim­i­lar­ly, if fonts are not anti-aliased, they look like black Tetris pieces on a white back­ground. Anti-alias­ing is going on all the time with­out you know­ing about it, and you’d real­ly have to make an effort not to have it, but it’s worth putting 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 prob­a­bly fig­ure out what these things mean, but I will link to a com­plete man­u­al for ~/.fonts.conf syn­tax at the end of this post.

rgba

This one is a mat­ter of per­son­al pref­er­ence, I guess. I don’t see how any­body of sound mind could stand to have pink, beige, and turquoise pix­els sprin­kled around the edges of their let­ters – the result of “sub-pix­el ren­der­ing” – but I guess the argu­ment is that it allows them to be sharp­er. What­ev­er.

Trust me when I say that things look best if you tell ~/.fonts.conf to dis­able sub-pix­el ren­der­ing, which is done like so:

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

If you hap­pen to be schiz­o­phrenic, or col­or­blind or what­ev­er, then yes, fine, you can turn on sub-pix­el ren­der­ing by chang­ing none to rgb, to reflect the com­po­si­tion of your monitor’s sub­pix­els (which are almost cer­tain­ly in the order Red-Green-Blue, from left to right). Have fun scratch­ing your eye­balls out.

rgba=rgb

rgba=rgb

rgba=none

rgba=none

Admit­ted­ly it would be nice if there were some antialiasstyle prop­er­ty you could set to antialiasslight or some­thing, to light­en up those gray pix­els a lit­tle bit.

hinting / autohint / hintstyle

Put it on my tomb­stone: Turn Off Hint­ing. I’m beg­ging you. If some­body tries to tell you that this is a mat­ter of pref­er­ence, they are lying to you, and are not your friend, and are prob­a­bly bang­ing your girl­friend. If you leave hint­ing on, Geor­gia will not look like Geor­gia, Luci­da will not look like Luci­da, and Nim­bus will not look like Hel­veti­ca.

hintstyle=hintnone

hintstyle=hintnone

hinting=true, autohint=true

hinting=true, autohint=true

Here is how you Turn Off Hint­ing®:

<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­tive­ly, if you pos­i­tive­ly demand more “crisp­ness” from your fonts, even at the expense of aes­thet­ics, you might want to give slight hint­ing a try. From the above code, change hinting and autohint to true, and hintstyle to hintslight:

hintstyle=hintslight

hintstyle=hintslight

That’s it, rough­ly speak­ing. It’s my under­stand­ing that some spe­cif­ic fonts do look bet­ter if specif­i­cal­ly tar­get­ed and adjust­ed with maybe slight hint­ing. But that’s for anoth­er day. If you do as I’ve instruct­ed, 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 with­out the help of these sites:

  • Arch­Wi­ki: I know noth­ing about Arch Lin­ux, but this wiki page has a lot of good info.
  • fontconfig.org: the most com­plete and recent ~/.fonts.conf ref­er­ence I’ve found.
  • Ubun­tu Wiki: con­tains an exam­ple of a very com­pre­hen­sive (if dat­ed) ~/.fonts.conf file. Study it and learn how to do oth­er stuff.
  • The Mas­ter­plan: anoth­er sam­ple ~/.fonts.conf file, and the only oth­er one that I know of that turns off hint­ing and sub­pix­el ren­der­ing.