Comprehensive Ubuntu Font Configuration Guide: Gutsy 7.10 edition

Even with the latest and greatest release of Ubuntu Gutsy Gibbon, font configuration in Linux can range anywhere from somewhat confusing to downright difficult. On top of the configuration difficulty, nobody can agree on what makes fonts look good. This article aims to document several approaches to font rendering, and the appropriate configuration settings to implement each approach.

I'm not going to go into which approach I think is the best, since that's a fairly personal matter. Each approach has its strengths and weaknesses, and come on, this is Linux. It's not about forcing people into choices they don't want.

Terminology

First I'll introduce some basic terminology that I will use in this article:

  • Glyph: A glyph is simply the "image" for a character in a font. The term glyph is used becomes some glyphs might be for symbols that you might not traditionally think of as a character.
  • Bitmap Fonts: Bitmap fonts are the simplest kind of font files. They are files that specify bit for bit representations (like small images) for each glyph.
  • Outlines: Fundametally, the outline is the mathematical representaiton of a glyphs shape. Typically these are specified using techniques such as bezier curve segments. Exactly how they are specified depends on the font format.
  • Scalable fonts: "Scalable" is used to denote the fact that the font is specified as outlines, rather than bitmaps. Because the font shapes are specified by mathematical equations, a single representation can be rendered at many different sizes.
  • Anti-aliasing: Outlines in scalable fonts can be said to have infinite resolution. They are not sampled representations of an image, rather, they are pure mathematical functions that can be evaluated at any resolution. However, such shapes are rendered on screen, the renderer is limited to the number pixels available. Anti-aliasing is a standard technique that takes a high-resolution signal and approximates it with a few number of samples. In terms of font rendering, it is the part of the process that colros some pixels gray instead of completely black and white, in order to smooth the appearance of diagonals and curves.
  • Hinting: Generically, hinting refers to the process of adjusting outlines at small sizes. The outlines are adjusted in such a way that when anti-aliasing is performed, the results produced are easier to read. Typically this is achieved by adjusting the outlines so that hard edges align well with pixel boundaries.
  • Truetype fonts: Truetype fonts are the standard font format you'll find on the web and other sources today (as well as OpenType). While all the details of truetype format are not relevant for this article, one can think of it as a container file format for information.
  • Truetype bytcode hinting: Truetype fonts can contain optional hinting information to supplement the outlines contained in the font. This hinting information is supplied in the form of small programs, expressed in a special bytecode format. Interpreting these bytecode programs correctly allows truetype rendering systems to perform hinting on outlines of fonts at particular sizes.
  • Embedded bitmaps: Embedded bitmaps essentially bitmap fonts that are embedded into a scalable font file. They can be used at specific sizes in place of the outline information. Sometimes the creating of bytecode hinting programs can be extremely time consuming. Take for example, a Japanese font, which of thousands of glpyhs. For such fonts, font authors can provide hand-tuned bitmaps of all the glyphs at the small sizes which usually require hinting.
  • Freetype: Freetype is the open source font loading and rasterization library. It is used in Linux and a number of other platforms. This library is capable of understanding truetype files (and a bunch of other file formats) and can also create rendered glyphs from outlines.
  • Freetype autohinting: Autohinting is a technique by which a rendering library adjusts outlines of a glyph automatically and heuristically. A common idea, for example, is to attempt to align vertical edges in a font with the vertical pixel boundaries of a display. The key difference between Autohinting and bytecode hinting is that autohinting is completely automated. The font author does not need to provide any hinting bytecodes. Autohinting can also be applied to outlines fonts which come with no manually created hinting information.
  • Subpixel filtering/rendering: This refers a technique which takes advantage of the fact that modern LCD displays align their red, green, and blue subpixel elements in a regular pattern. Because of this, a renderer can attempt to create an image that uses this known layout to increase the perceived resolution of the rendered glyph. This subject itself is somewhat complicated, so I'll simply refer to other existing excellent documents on the subject.

Configuration tools

Ubuntu's font configuration system, unfortuately, has many moving parts and complementary configuration tools. The most visible one is the Appearance Preferences control panel, which can be found under the System menu on the desktop. The "Fonts" tab has the various settings related to font rendering.

Aside from this control panel, the font configuration in the Gnome environment is also affected by the fontconfig system. The fontconfig system is built on top of freetype, and allows applications to query the system for fonts based on all kinds of parameters and have the system return available fonts.

This fontconfig is controlled using a configuration file, and this configuration file allows the modification of all types of font rendering properties. Per-user fontconfig configuration information can be written into the .fonts.conf file in a user's home directory.

Overview of Approaches

Next, I'll enumerate what I think are the distinct worth approaches in LInux font rendering:

  • Bytecode Hinted, using subpixel filtering
  • Bytecode Hinted, using grayscale anti-aliasing
  • Unhinted, using subpixel filtering
  • Slightly autohinted, using subpixel filtering

Bytecode Hinted, using subpixel filtering

This approach most closely approximates how the Microsoft Windows "ClearType" system renders fonts. Truetype hinting information is interpreted to the extent supported by the freetype library, and subpixel filtering techniques are applied.

Configuration

In Ubuntu Gutsy, configuring this approach is most easily configured by choosing the "Subpixel Rendering" option in the Appearances Preferences control panel.

Advantages and Disadvantages

While this method in theory applies all the enhancement technologies that are available on the Ubuntu desktop system, the results can be somewhat unsatisfying. There are many potential reasons for this, though for each particular font the reasons may differ:

  • Ubuntu does not yet support the Vista fonts' cleartype specific hinting system. So Vista's new fonts will appear different on an Ubuntu system.
  • Freetype has a different anti-aliasing algorithm from Cleartype. This leads to different rendering.
  • Freetype bytecode hinting is not perfect. The bytecode interpreter in freetype tries to interpret all the bytecodes the best it can, but there are occasionally still bugs that show up as mis-rendered shapes, or slightly different shapes.
  • Linux font rendering is not gamma corrected, which can cause color fringes to appear more often, and certain intermediate colors to appear darker than they are meant to be, causing harsh edges. This again, depends on the font.

Bytecode Hinted, using grayscale rendering

This approach is essentially similar the previous one, except that subpixel filtering is not used. This results in slightly lower horizontal resolution, but eliminates the possibility of color fringing that can be introduced when using subpixel rendering.

Configuration

This approach can be configured using the Advanced section of the Fonts tab of the Appearance Preferences. In the Font Rendering Details window, choose Grayscale under Smoothing, and Full under Hinting.

Advantages and Disadvantages

The pros and cons of this method are similar to the subpixel filtered method. This method trades off subpixel rendering for a more consistent, color-fringing-less result. Depending on your monitor and font, this might produce a more pleasing result.


Unhinted, using Subpixel filtering

This approach forgoes any hinting at all. This means that glyph outlines are not adjusted for the pixel grid, and only subpixel filtering is used to smooth edges. This technique produces a less "sharp" output, but one that is more faithful to the original design of each font as the shapes are not distorted. Eariler version of Apple's OS X used this approach.

Configuration

This approach is configured, again, using the standard Appearance Preferences control panel. Under the Advanced settings of the Fonts tab, choose Subpixel under Smoothing, and None under Hinting.

Advantages and Disadvantages

This method gets correct glyph shapes while trading off sharpness. You will notice that most fonts look significantly more blurry under these settings. Even blurrier than the post 10.3 versions of OS X (see this post for an explanation).

On the plus side, core microsoft fonts will look just as good as "native" linux fonts, and fonts lacking hinting information will also be rendered relatively well.


Slightly autohinted, using Subpixel filtering

This method combines the relative outlines faithfulness of the Unhinted approach, but uses the freetype library's autohinter in a limited way to improve results.

Configuration

The standard Gnome fonts control panel does not allow one to configure the use of the auothinter. This must be configured using the command line:

% sudo dpkg-reconfigure fontconfig-config

Executing this command will result in some dialog questions. In the first question, be sure to choose the "autohinter" option over "native". The remaining two questions can be answered with their default selections.

Finally, use the Gnome Appearance Preferences to set the remaining settings. Under Smoothing, choose Subpixel and under Hinting choose Slight.

Advantages and Disadvantages

This configuration is recommended by David Turner, a large contributor to the freetype library. It combines a relative faithfulness to the shape of the outlines with an added sharpness from the autohinter.

They key to the effect is the combination of the autohinter and subpixel rendering. Subpixel rendering, increases the horizontal resolution of the pixel grid by in theory by 3x (perceived increase is somewhat less, but still significant). Because of this, it was suggested that hinting only need be applied in the vertical direction, where we have less resolution. The "slight" hinting setting when used with the autohinter does exactly this. Glyph outlines are only automatically adjusted in the vertical direction.

The autohinter can still have bugs, unfortunately, and some fonts still look suboptimal. Also, the use of subpixel rendering can still cause color fringing on certain fonts. Without proper gamma correct rendering, this will always be the case. Also some fonts, such as Arial, can still look a tad off even under these settings, usually due to the heuristic algorithm that the autohinter uses.

Comments

A really helpful article!

A really helpful article! Thanks.

sword.f1sh@yahoo.com