22 Comments

Better LCD Font Rendering

HeaderBetter font rendering in Linux has been a long time a ‘comin. The slow adoption of better font rendering in Linux has been because Apple and Microsoft have restrictive patents governing how they are rendered. Gradually though a few distro’s are implementing better font rendering that’s attempting to be non-patent restrictive. Ubuntu by default adds lcd-patched subpixel font rendering to Xft and cairo and a few other distro’s too. However for most other distributions, the lcd-specific FreeType API’s will need to be patched in.

First be sure that your xorg server DPI settings are correct for your monitor. Then you’ll need the updated and patched versions of freetype, fontconfig, libXft, and cairo.

Installing on Gentoo

For Gentoo users these updated packages are in the devnull overlay. Devnull uses mercurial:

emerge mercurial

To add an overlay, use layman to add it:

layman -a devnull

Read nico’s comment on preferred USE flags (Ubuntu’s) for best rendering. Then emerge these four programs.:

emerge -1 freetype fontconfig libXft cairo

Arch Install

For Arch I use the Ubuntu font rendering too. To install the Ubuntu font rendering do:

yaourt -S freetype2-ubuntu fontconfig-ubuntu cairo-ubuntu libxft-ubuntu

For other types, take a look at the Arch wiki page on Fonts.

Setting Up Fontconfig

Setting up fontconfig should be done as simple as possible. If you add too many options, fontconfig will use all of them and your fonts will become a mangled mess. Some font options are already set up in ‘/etc/fonts/conf.d’ and there more available in ‘/etc/fonts/conf.avail’. However, though you can choose to set up your font preferences here so that they are applied globally, I’ve discovered it’s better to create a local configuration (talked about below). If you want to set any of these options up, you’ll need to link them. For example, to replace bitmap fonts:

cd /etc/fonts
ln -s conf.avail/29-replace-bitmap-fonts.conf conf.d/

A fontconfig configuration file likely will need to be built to define how to render the fonts. This ideally shouldn’t be necessary as you should be able to set up most or all your settings by creating links to the fontconfig configuration directory. However, some Desktop control panels (yes, KDE and GNOME I’m talking about you) create a local configuration that overrides global settings. The local font configuration is a hidden file in the home directory called ‘.fonts.conf’ (~/.fonts.conf) and the one I provide here should work for most people:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>

<fontconfig>

 <!-- General Settings -->

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

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

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

<match target="pattern" >
  <edit mode="assign" name="autohint" >
   <bool>true</bool>
  </edit>
 </match>

 <match target="font" >
  <edit mode="assign" name="hintstyle" >
   <const>hintslight</const>
  </edit>
 </match>

 <match target="font" >
  <edit mode="assign" name="lcdfilter">
   <const>lcddefault</const>
  </edit>
 </match>

 <!-- Dots per Inch (DPI) -->
 <match target="pattern" >
  <edit mode="assign" name="dpi" >
   <double>96</double>
  </edit>
 </match>

 <!-- Fixes -->

 <!-- MS Fonts calibrations -->

 <!-- Consolas and Inconsolata are fuzzy -->
 <match target="font">
  <test compare="eq" name="family">
   <string>Consolas</string>
  </test>
  <edit mode="assign" name="hintstyle">
   <const>hintmedium</const>
  </edit>
 </match>

 <match target="font">
  <test compare="eq" name="family">
   <string>Inconsolata</string>
  </test>
  <edit mode="assign" name="hintstyle">
   <const>hintslight</const>
  </edit>
 </match>

 <!-- Calibri fix for jaggedness -->
  <!-- http://forums.fedoraforum.org/showthread.php?p=1045807#post1045807 -->
 <match target="font" >
  <edit mode="assign" name="embeddedbitmap" >
   <bool>false</bool></edit>
 </match>

 <!-- Arial and Impact fuzzy fix -->
 <match target="font">
  <test compare="eq" name="family">
   <string>Arial</string>
  </test>
  <edit mode="assign" name="hinting">
   <bool>true</bool>
  </edit>
  <edit mode="assign" name="hintstyle">
   <const>hintfull</const>
  </edit>
  <edit mode="assign" name="autohint">
   <bool>true</bool>
  </edit>
  <test compare="less" name="weight">
   <const>medium</const>
  </test>
 </match>

 <match target="font">
  <test compare="eq" name="family">
   <string>Impact</string>
  </test>
  <edit mode="assign" name="hinting">
   <bool>true</bool>
  </edit>
  <edit mode="assign" name="hintstyle">
   <const>hintfull</const>
  </edit>
  <edit mode="assign" name="autohint">
   <bool>false</bool>
  </edit>
 </match>

 <!-- Font Replacements -->

 <!-- Replace bitmap fonts -->
 <selectfont>
  <rejectfont>
   <pattern>
    <patelt name="scalable">
     <bool>false</bool>
    </patelt>
   </pattern>
  </rejectfont>
 </selectfont>

</fontconfig>

Be sure you check your monitor’s subpixel type by looking at this page. You might also want to experiment with the hintslight, hintmedium, and hintfull options (hintslight is preferable to most people). After you have done this you should restart your xorg server (logout/login should do). Technically font effects should take place immediately but applications that are already loaded (panel, window manager…) will need to be restarted to get the effect.

Again, keep it simple! Get too complicated and bad things happen.

A Note About Desktops

Desktops have previously handled font rendering and can over-ride the local fontconfig configuration. In the KDE and Gnome control panels, match your ~/.fonts.conf settings (this is a little easier in KDE because the settings match the options in ~/.fonts.conf, I don’t know about Gnome but I do know you should set your DPI accordingly then adjust the font size).

Resources

The Arch wiki has a good article on this.

About these ads

About Todd Partridge (Gently)

Good times, good people, good fun.

22 comments on “Better LCD Font Rendering

  1. >> Let’s get going. I’d like to thank bi3l who has been building the ebuilds, and also to whomever runs the devnull overlay.

    heh, you’re welcome

  2. Nice article.
    @Sebastian: Thanks for the feedback (I’m from devnull overlay :)

  3. Nice article. Am sure will help many people get the crsytal clear viewing that lcd’s are meant to give

  4. We from devnull overlay stopped using IUSE defaults in the font ebuilds. There are 2 useflags which affect font rendering now – cleartype and ubuntu. I suggest you to update your post that it says to use the cleartype useflag (1. this is what portage uses 2. ubuntu one does not work for me for some reason, but others report it works well). I would say that the ubuntu useflag is for more experienced users.

  5. Danke nico. Good tip, thanks for adding it.

  6. I don’t quite follow what Nico is pointing out. I’ve added the devnull overlay but when I attempted to `emerge freetype fontconfig libXft cairo` I was greeted with this lovely error message that I don’t quite grok:

    emerge: there are no ebuilds built with USE flags to satisfy “>=media-libs/freetype-2.2.1[cleartype,-ubuntu]“.
    !!! One of the following packages is required to complete your request:
    - media-libs/freetype-2.3.8 (Missing IUSE: cleartype ubuntu)
    - media-libs/freetype-2.3.7-r1 (Missing IUSE: cleartype ubuntu)
    - media-libs/freetype-2.3.7 (Missing IUSE: cleartype ubuntu)
    (dependency required by “media-libs/fontconfig-2.6.0-r2″ [ebuild])
    (dependency required by “fontconfig” [argument])

    I don’t mean to be asking for support here but if it’s a problem with a recent update or the guide, just thought I’d let you know…

  7. Solved it.

    I reread it a few times and did some further reading about ebuilds. I’m new to overlays and didn’t realize that make.conf and package.use flags effected overlay’d ebuilds.

    The obvious solution was to unmask and add the “cleartype” flag as seen below.

    # echo media\-libs\/freetype ~x86
    # echo media\-libs\/freetype cleartype >> /etc/portage/package.use

  8. Yep, that’s exactly how you do it.

  9. Ack, I must have been exhausted when I wrote that, the correct solution is:

    # echo media-libs/freetype ~x86 >> /etc/portage/package.keywords
    # echo media-libs/freetype cleartype >> /etc/portage/package.use

  10. Gen2ly facepalms.

    heh, i missed that first part.

  11. It should be emerge mercurial and not emerge mecurial (there is a typo above)

    Thanks!
    Prateek

  12. Ahhhhh, yes. Good catch Prateek. Fixed.

  13. Todd Patridge……. great note buddy that helps out

  14. Updated a few details.

  15. Great post. It is very useful to me.

  16. Hey, you have a great blog here! I’m definitely going to bookmark you! Thank you for your info.

  17. If you are looking for some fresh content on viewsonic monitor, you are at the right place. That is what this article has to offer to its readers.http://viewsonicmonitor.deutschenshop.com/

  18. great blog here with some excellent content, thanks

  19. LCD TVs can really save you from high electricity bills and office space -`-

  20. Thank you for compiling this fontconfig! The Calibri fix in particular is fantastic.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 52 other followers