7. Matching Names and Fonts

The intent of the matching algorithm in Fontconfig is to allow applications to provide as much information as possible and for the matching algorithm to pick the font closest to the requested values. That is why patterns contain more than one value for each name -- the values are used as alternatives in matching. Values earlier in the list are preferred, so a list of family names like Times, Arial, Verdana will match Times if that family is available, otherwise it will match Arial or Verdana.

Before the matching process begins, Fontconfig fills in some default values for patterns without them; a font without a preference for style will have default values assigned to weight and slant. The pixel size is computed from the point size, DPI and an additional scale factor that can be used to adjust the size of various families from the configuration. Finally, various FreeType rasterizer controls are set to their default values in the event that the pattern is used with FreeType.

By convention, the names serif, sans-serif and monospace are bound by the configuration to the user's preferred fonts in that style. This means that applications should always provide one of these generic names whenever opening a font so that a reasonable font is always used, even when the specific family is not available.

During matching, Fontconfig measures the distance from the given pattern to every available font, selecting the nearest one. This distance metric is based on how close the values are and which name is involved; fonts with identical family names but different styles are ``closer'' than fonts with identical styles but different family names.

The numeric values for the various weights and slants are designed so that applications requesting a missing style will get something reasonable instead; (e.g. oblique and italic are closer to each other than either is to roman). This is similar, but not precisely the same as the W3C Cascading Style Sheet specification for font matching with respect to slant and weight matching.

A fixed set of names in a fixed order are used to match fonts; in reality, most matching either finds the desired family name or falls back to either a generic name or one of a few fonts supporting an unusual language. The names include the foundry, Unicode coverage, language groups, family name and style.