The DejaVu font family is a very popular font collection for Linux and BSD systems. The font package of DejaVu includes a condensed variant; a variation of the same basic font theme that sports narrower characters.
The difference between the two font variants is very easy to spot when they are displayed side by side. The following image shows a small part of a Firefox window, displaying news articles as part of a Google Reader session:
The window snapshot on the left of this image shows the normal variant of the DejaVu Sans font family. The right-hand snapshot shows the condensed variant of the font family.
I usually to prefer the condensed variant for the display of text on a computer monitor. The narrower characters, with a height that is slightly larger than the width of each glyph, are more æsthetically pleasing for my eyes. Naturally, this is only a matter of personal preference; the normal variant may look and feel more pleasing to some other person. If your own preference leans towards the normal variant of the font, this article may not be very interesting to you, so it is probably ok if you stop reading now.
If you are one of those people who like the condensed variant of the DejaVu font family more than the normal variant though, by all means, keep reading. The “hack” I am going to describe uses a configuration tweak of the fontconfig package to forcibly replace all instances of the DejaVu Sans and the DejaVu Serif fonts with their condensed version.
The Main Problem with Firefox and Condensed Fonts
An interaction between fontconfig and the way some programs select font variants means that Firefox, OpenOffice and a few other programs cannot display the condensed variant in their GTK+ font selection dialog. Firefox, for example, shows only “DejaVu Sans”:
As a result, it is impossible to use the font selection dialog of Firefox to configure the condensed font variant as the default font for web content. This kept annoying me for a while, but not enough to actually do something about it. I always thought it would be much better if we could select either font variant, but kept saying to myself that “this may eventually be fixed”. Since this is a long standing bug that has not been fixed in Firefox or the other programs that exhibit the same misbehavior, I decided this morning to forcefully substitute all instances of DejaVu Sans with DejaVu Sans Condensed and all instances of DejaVu Serif with DejaVu Serif Condensed in my FreeBSD/Gnome desktop.
What Could Work but is Not a Good Idea
One way to do this is, of course, by manually replacing the TrueType font files of the non-condensed font variants with their condensed counterparts (e.g. by logging in as the system administrator and overwriting the non-condensed font files). I didn’t want to go that way. Manually modifying the installed versions of files registered into the package database is a bad idea and very ugly hack, because it will stop working the next time the same package is installed. So I chose to read a bit more about
fontconfig and see if I could do the same without all the smelly hackery of overwriting font files.
Using Fontconfig Might be a Better Idea
Fontconfig is a library that enables system-wide and per-user configuration, customization and application access to font files. The personal
fontconfig configuration of each user is stored in a file called
.fonts.conf, in the home directory of each user. The format of this file is defined by a relatively “simple” XML schema. Some of the options supported by the fontconfig schema are described in the fontconfig manual. The quotes around “simple” are there because once you see a few examples of
fontconfig tweaks, it is not very hard to come up with similar configuration tweaks, but the precise format and syntax of all the options supported by the syntax is, alas, not very intuitive.
.fonts.conf exists in your home directory it has the following general format:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> ... </fontconfig>
Font options that apply to your personal
fontconfig setup go inside the
<fontconfig>...</fontconfig> element. There are many sorts of options that can be placed inside this XML element, but it is not the intent of this article to describe all of them. For a full list of the options, you should read the fontconfig manual.
There are only three
fontconfig options that we are interested in to install the condensed font tweak:
<edit>. Using these three, we can forcefully replace all uses of the DejaVu fonts with their condensed versions, by adding the following XML snippet to
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <match target="pattern"> <test name="family" qual="any"> <string>DejaVu Sans</string> </test> <edit mode="assign" name="family"> <string>DejaVu Sans Condensed</string> </edit> </match> <match target="pattern"> <test name="family" qual="any"> <string>DejaVu Serif</string> </test> <edit mode="assign" name="family"> <string>DejaVu Serif Condensed</string> </edit> </match> </fontconfig>
XML is a very verbose and chatty format, but what these two small snippers of XML configuration do should be easy to understand:
- When an application asks for a font whose family matches “DejaVu Sans”, return a font from the “DejaVu Sans Condensed” variant.
- When an application asks for a font whose family matches “DejaVu Serif”, return a font from the “DejaVu Serif Condensed” variant.
That’s it. Now every time an application asks for a font of the DejaVu family,
fontconfig will always return a condensed variant of the font. The font-variant replacement is done transparently by fontconfig, so you don’t have to configure each application separately, or to install application-specific hacks that will work for one application but fail or be invisible to all other programs running on your desktop.
The downside of this forceful font-variant replacement is that it is now impossible to select the non-condensed variants of the DejaVu fonts. The good thing is that, at least in my case, this is “ok” and I can certainly live with it, because I always prefer the condensed variant for this particular font family.