Thursday, April 16, 2015

Fixing Gimp font rendering with fontconfig-infinality

Leading a UI team in my company, I tend to use Gimp tool from time to time. However I had some issue with font rendering in Gimp - it worked really awful for me, especially when rendering a bright color text on the darker background. Consider this:
This is Droid Sans, 50pt for the larger "Shalom" and 18pt for the smaller one - white color. If with the larger font you can see at least some reference to white color, the smaller one looks completely green-ish to me.

Zooming in, I saw that the issue seems to be related to subpixel rendering. You can see that the smaller version of the "Shalom" is "subpixeled to death".
Does everyone in Ubuntu has this problem and lives with it? - It can not be. Using Google powers, I've found that this issue is related to my Infinality font settings. I wrote about Infinality - the FreeType patches and configuration files that make fonts on Linux look like never before. Two years after, I'm still blown away with how good fonts look. Glancing at Windows Cleartype I fill really sorry for Windows users :) But... its doing no good to Gimp font rendering.

So I tried to disabling subpixel rendering system-wide to see if it helps - it does! Now Gimp renders fonts very good!
And the zoomed version:
Nice, aah? Gimp only uses hinting, i.e. adding different tones of the base font color around the main outline of the letters. The Gimp font tool even has a control to manage the amount of hinting or disable it all together. I wish they had a control to just disable subpixel rendering.

So the solution is to disable subpixel rendering for Gimp (and for Gimp only). Easy as it may sound it took me a while to figure out how to do it - font-config system has no generic way to make the application-specific settings. Obviously I did not want to disable it globally, since it clearly crippled the beautiful font rendering I came to love so much:
Two samples of Firefox rendering kubuntu.org. On the right, subpixel rendering is disabled. Look at the difference in zoomed versions - without subpixel rendering letters look more dull and square (especially note the vertical bar of the "K" and "b" letters). Letters on the left look juicy and sharp all together - and that's hard to achieve. Usually its either "juicy but blurry" or "sharp but harsh". Infinality's way of configuring this struck the chord (for me).

Anyways, back to Gimp. After all, I found nice article in ArchLinux wiki - they have a complete article on Infinality with related issues and workarounds and it had a solution to my gimp problem. As another mailing list said, applications may support their own way for overriding font-config configuration. And in fact, gimp does support this by reading ~/.gimp-2.8/fonts.conf file. So I've placed the following into this file:
<fontconfig>
  <match target="font">
    <edit name="rgba" mode="assign">
      <const>none</const>
    </edit>
  </match>
</fontconfig>
(Looks like fontconfig files refer to "subpixel rendering" term just as "rgba"). Now I can enjoy rendering text in Gimp without sacrifices :)

This is the only issue with Infinality that I've encountered so far. Otherwise fonts look so so so so much better to me. If you have issues with Infinality, make sure to check the ArchLinux wiki article on the subject.

No comments:

Post a Comment