Fun With Fontconfig

Fontconfig <http://www.freedesktop.org/wiki/Software/fontconfig/> is a set of command-line utilities, as well as an API for programs to use. It allows matching of fonts by names and other characteristics, rather than having to hard-code paths to font file names, or having to embed fonts into every document. For example, you format some text in a LibreOffice document. In the GUI, you will see a popup menu of all the fonts available on your system. Having chosen a font to use and saved your document, you send a copy to a friend. But they don’t have the same font installed, so LibreOffice uses Fontconfig to find the next best available font. As another example, Web pages commonly specify fonts by names like “serif” or even “Arial” (actually the name of a Microsoft-created clone of the original “Helvetica” font). While those who really care about typography and layout will use CSS font specifications to get the exact font they want from some server, the rest of us will muddle through with the common names, and expect the Web browser to find a suitable match on the user’s local machine. The command-line utilities allow you to observe this process in action. Given a reasonably vague font name, the fc-match command will show you the exact font file that will be chosen; thus, on my system: ldo(a)theon:~> fc-match -f "%{file}\n" arial /usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf (You will likely get a different result, depending on what fonts you have installed.) Sometimes the file names are not so explanatory: ldo(a)theon:~> fc-match -f "%{file}\n" palatino /usr/share/fonts/type1/gsfonts/p052003l.pfb in which case, the fc-query command will give you more info about what exactly is in that font file: ldo(a)theon:~> fc-query -f "%{family}\n" /usr/share/fonts/type1/gsfonts/p052003l.pfb URW Palladio L Or, you could have combined both steps into one: ldo(a)theon:~> fc-match -f "%{family} %{file}\n" palatino URW Palladio L /usr/share/fonts/type1/gsfonts/p052003l.pfb The list of what information item names you can put in those “%{...}” format specifiers is not mentioned in any of the man pages, but you can look in /usr/include/fontconfig/fontconfig.h, which is part of the libfontconfig1-dev package. Be warned, though: not all the items listed there will work with all fonts.
participants (1)
-
Lawrence D'Oliveiro