3. Configuring Fonts

The central feature of the library is the configuration mechanism. All of the other pieces derive from what information is relevant in configuring the fonts, and how the configuration data affects the internal operation of the library. While there are some internal implementation issues within the library, the code serves chiefly as a wrapper around the configuration information. Describe the content of that configuration and the operation and use of the library is transparent.

As mentioned above, font configuration files are in XML format. Because Fontconfig already has a manual describing the precise format of the files, this section will describe the semantic content of the configuration files and how applications and users are expected to use them.

3.1. Configuration Files

To ensure that every system using Fontconfig shares a common configuration, the Fontconfig library always uses the same configuration files by default. Font config searches for the fonts.conf configuration file along the directories specified in the FONTCONFIG_PATH environment variable, and also in /etc/fonts.

The fonts.conf file may reference other configuration files using the <include> element. <include> elements may use ~ to reference files relative to the current users home directory. The complete list of configuration files used is saved within the current configuration for applications to monitor those files and automatically update their internal configuration when they change.

<include> elements may be marked as optional in which case the failure to locate them is not remarked upon by the library. This is conventionally used when referring to the per-user ~/.fonts.conf file so that it need not exist for all users.

Applications modifying any of the font configuration files follow a locking protocol designed to ensure that only one application can edit the configuration at a time. The protocol is also designed so that applications using the font configuration need not use read locks; a consistent and complete font configuration will always be accessed through the configuration file name.

3.2. Font Directories

Fontconfig locates fontfiles through a list of directory names. The order of the directory names is not particularly significant. Just as with configuration files, font directory names may start with ~ to indicate a directory relative to the users home directory. Missing directories are silently ignored by Fontconfig so that the system may reference optional packages without affecting the font configuration.

Fontconfig also exposes the list of configured directory names to the application. This can either be used by applications uninterested in the remaining parts of font configuration to look for fonts through some private mechanism, or so for applications to monitor the font directories for changes and reload the configuration to update the set of available fonts.