Fontconfig

The fontconfig library (media-libs/fontconfig) is intended to provide uniform font selection and configuration amongst all GUI applications. Although it is common for a desktop environment to provide its own font overrides and configuration utilities, fontconfig is still the underlying library.

Configuration

NoteChanges to fontconfig files will reflect only in applications started after the change!

Generic

fontconfig uses XML files in the /etc/fonts/ directory to generate its internal configuration. By default it parses /etc/fonts/fonts.conf (users should not edit this file!) which sets some sane defaults and usually contains code to also parse /etc/fonts/conf.d/ content. In addition there is the /etc/fonts/conf.avail/ directory that contains various possible configuration files that each cover some aspect of fontconfig. It's customary to symlink necessary files to /etc/fonts/conf.d/. These files are executed in order they are named; for this reason their names start with a two digit number with the first digit (tens) indicating what the file affects (called the class).

Gentoo specific

Gentoo ships an eselect module (eselect fontconfig) that does exactly what was described in generic way - it manages symlinks of files in /etc/fonts/conf.avail/ by adding or removing them from the /etc/fonts/conf.d/ directory. For obvious reasons changing system wide configuration requires appropriate permissions.

The following subsections explain how to deal with the fontconfig eselect module.

Listing available files

The list command shows the available fontconfig files, and marks the enabled ones with an asterisk (*).

To be clear, this says that when it comes to sans-serif fonts, we prefer using Ubuntu, TakaoPGothic, and Droid Sans fonts (in that order) over DejaVu Sans (which can be used as a default choice only when necessary). Obviously, different choices can be made here.

Per-user configuration

To create per-user fontconfig files, enable 50-user.conf (which might be enabled by default), and have the end users use the ~/.config/fontconfig/fonts.conf file. This file has the same XML format as local.conf.

NoteThis is one way how a desktop environment might try to affect font rendering. It might be prudent to disable this to be sure that what's being shown is actually system wide configuration when customizing it. Disabling it also makes font rendering more uniform across user accounts.

NoteThe previously used ~/.fonts.conf is now deprecated in favor of the $XDG_CONFIG_HOME based location. This variable by defaults points to ~/.config.

Checking configuration

Check the default font replacement, for example for Arial, by typing:

user $fc-match Arial

Anti-aliasing, hinting, and sub-pixel rendering

Rendering aspects can be tuned as well. In the following sections the Anti-aliasing, Hinting and Sub-pixel rendering features are tuned.

Feature

Description

Anti-aliasing

is enabled by default and makes fonts less blocky.

Hinting

is an attempt to cope with the low pixel count per unit of area of current displays. Correct hinting makes characters more crisp but since font metrics aren't changed (and arguably should not change) affects how overall the rendered text looks like.

Sub-pixel rendering

uses the fact that LCD matrix has three primaries to effectively triple the resolution of text but can make characters appear not entirely black. To combat that lcdfilter is to be used with sub-pixel rendering (available for newer fontconfig) but it can blur the characters too much. In the end this entirely depends on person how they like their text.

Forcing hinting

The default fontconfig behavior regarding hinting is rather undocumented, but it can be made deterministically sub-optimal by making a system wide default.

NoteMost fonts look best with full hinting but others need slight or more rarely some other other hinting option. Some fonts for one reason or another will always be ugly.

Using sub-pixel rendering

It's important to determine the sub-pixel layout of the LCD matrix. It's usually RGB (10-sub-pixel-rgb.conf) but the only way to be sure is to either consult display specification or use this sub-pixel layout test to determine it.

It's strongly advised that lcdfilter, if available, is used with sub-pixel rendering. It comes in different varieties but the default (11-lcdfilter-default.conf) should be appropriate for all common fonts.

root #eselect fontconfig enable 11-lcdfilter-default.conf

WarningThe bindist USE flag in media-libs/freetype disables sub-pixel rendering altogether due to potential patenting issues. In order to use sub-pixel rendering, the USE flag must be disabled (i.e., -bindist) for this package.

Regarding autohinter

Autohinter attempts to do automatic hinting disregarding any existing hinting information. Until recently it was the default because TrueType2 was covered by patents but now that they have expired there's very little reason to use it. From technical point of view it does better than broken or no hinting information but it will be strongly sub-optimal for fonts with good hinting information. Generally system fonts are of the second kind so autohinter should not be used.

WarningAutohinter is not compatible with sub-pixel rendering, do not use the two together!

Infinality

Infinality is a (somewhat controversial) set of patches for FreeType and accompanying fontconfig files. The goal of Infinality is to provide higher quality font rendering including emulation of other OS font rendering styles.

NoteAs usual with software still in development it is prudent to always use only the latest version available unless there are known problems with it.

Enabling Infinality

Enable the 'infinality' USE flag by editing make.conf either manually or by using the euse tool.

Configuring Infinality

Infinality can be configured in various ways including custom configurations, but easiest is to use pre-made profiles shipped in media-libs/fontconfig-infinality that along with eselect modules should have been installed as dependencies of the infinality USE flag.

Quick and reasonable config

root #eselect infinality set infinality

root #eselect lcdfilter set infinality

NoteAs always, fontconfig changes affect only applications started after changes have been made.

It's also recommended to disable all fontconfig settings except for 52-infinality.conf as they interfere with the rendering of infinality styles:

root #eselect fontconfig disable <number>

Certain fontconfig settings do not interfere with how the fonts are rendered, but rather determine the default fonts for font-types (such as Monospace, sans-serif, etc.). Such settings (for example the 62-croscore-*.conf configurations) can be left enabled.

Explanation

Infinality provides FreeType environment variables that can be used to configure features introduced with its patches as well as fontconfig files to be used with these changes. fontconfig file sets are administrated on Gentoo via eselect infinality while the FreeType behaviour is set using eselect lcdfilter.

These eselect modules function as usual:

Listing available fontconfig file sets.

root #eselect infinality list

Listing available FreeType variable sets.

root #eselect lcdfilter list

Both sets should match of course except when there are multiple matches possible such as shown below.

root #eselect infinality set win7

root #eselect lcdfilter set windows-7-light

Picking fonts

Choosing the right font can be trickier than deciding on the right hinting type. For one reason or another, some fonts will never be perfect — but it's certainly possible to make them look better than, say, the Windows 7 default font configuration.

Red Hat's fonts, which are metric-compatible with MS TrueType corefonts, have a decent, modern look. This is the Gentoo Fonts team recommendation for default Latin fonts. Covers about 2,600 code points.

Latin, Greek, Cyrillic, and Hebrew only. A few glyphs may have hinting trouble.

Very similar to Liberation, covering about 2,700 code points. Linux Libertine itself is proportional serif only, but the package contains less extensive sans and mono fonts, as well. Can be used as a fallback for some glyphs not in Liberation.

Google's font family that aims to support all the world's languages (so, well over 60,000 code points). It goes well with Liberation or Droid. Adobe's Source Han Sans fonts are included for CJK. Recommended as a fallback for many glyphs not covered by Liberation.

MS does not distribute them nowadays, so the available fonts are from many years ago and do not reflect their current state (not to mention the state of the art). Obviously, lacks fonts introduced more recently. Require full hinting.