TL;DR: Understanding fontconfig requires understanding why it was created and what problems it is trying to solve. That require a lot of understanding of Xorg.
Font configuration on UNIX machines went through different phases and fontconfig is simply one of the possibilities you can use to use fonts through Xorg. Reading the source of fontconfig without a good understanding of the source of Xorg is probably very difficult. But, I believe that an understanding of the concepts behind the evolution of fonts may prove a decent starting point.
Disclaimer: I deal a lot with fonts on Linux, but I never really needed to change Xorg code relating to fonts.
The Arch Linux wiki has a lot of info on this too
A bit of history
Original UNIX fonts were simply bitmap fonts. Today these can be found in
/usr/share/fonts/misc, the PCF (portable compiled format) is used for pretty much all of them today. It is a binary format. There have been other formats of binary fonts but I need to admit that I never needed to use any other format than PCF for binary fonts. Using
xfontsel you can configure a Xorg string to define the points, spacing, pixel size, terminal weight (bold, slant), encoding, among others of the font.
The bitmap fonts have different files for different pixel sizes of the font. The bitmap fonts already introduce the concept of font family.
Postscript (and TeX to some extent) created Type 1 fonts which are vector based fonts. These are in
/usr/share/fonts/Type1. Vector fonts are configured with several configuration values, e.g. antialias, embolden, dpi, or size (not necessarily point based this time).
Vector based fonts are scaled and do not require several files.
Xorg used both bitmap and Type1 fonts. And it created the XFT (well X FreeType is an interface to FreeType which is a GPL/BSD library that mimics and extends Type1). XFT not only allows the usage of Type1 and FreeType fonts but it also other formats: OTF by Adobe and Microsoft, TTF by Apple. Moreover XFT allows scaling of the old bitmap fonts to look like Type1 fonts.
Several other attributes, like hinting or hintstyle, were added to define attributes of these fonts.
All that can be found in subfolders of
/usr/share/fonts. And XFT parameters can be configured in your
fontconfig needs to deal with all the discrepancies of the above. In other words fontconfig is an attempt of configuring all the font types above in a manner that can exploit the attributes that the distinct fonts have with a common syntax.
The bitmap fonts have their problems:
- several different files for a single font
- limited sizes by points and pixel sizes.
But so does the vector based fonts:
- scaling takes time, especially if several parameters are used
- not all font attributes affect different font types in the same way
And both have the problem that there are many font formats, and that a user may wish to install fonts of his own in his home. Fontconfig tries to solve these problems.
fc-query tells you what fontconfig understand about the font file. Notably what attributes the file is for (for bitmap fonts for example) and what attributes can be used (for vector fonts).
fc-list is a way of telling you what fonts can be found in the directories fontconfig is looking at, and therefore con be used by applications. Finally
fc-cache performs an indexing of these fonts to find them easier and to scale them (among other things) for application use.
The fontocnfig shared library on the other hand is the most interesting part. It uses the configuration files (
~/.config/fontconfig) and the font cache to give preprepared fonts directly to applications that are linked against it. Since most applications used XFT (and therefore FreeType) and the FreeType library is using calls from the fontconfig library, the use of these fonts become ubiquitous.
But note that you can compile a program that will ask Xorg for a bitmap font in the old style (e.g.
-*-terminus-medium-r-normal-*-*-200-*-*-c-*-*-u) and the call will not go through the fontconfig shared lib.