Using the Condensed DejaVu Font-Family Variant by Default

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:

DejaVu Font Family Variants

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”:

Firefox Font Selection Dialog

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.

When the .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: <match>, <test> and <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 ~/.fonts.conf:

<?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.

15 thoughts on “Using the Condensed DejaVu Font-Family Variant by Default

  1. mperedim

    XML is a very verbose and chatty format

    That’s a nice and polite way to put it ;)

  2. Pingback: Astuce : Configuration de polices de caractère at FreeBSD-fr: Les nouvelles du géant en français

  3. Pingback: Messylaneous for 2009/11/07 · DragonFly BSD Digest

  4. Pingback: Messylaneous for 2009/11/07 « The Daily BSD

  5. Pingback: Using the Condensed DejaVu Font-Family Variant by Default | FreeBSD - the unknown Giant

  6. Philip Paeps

    You need to be sure to have the FreeType “autohinter” enabled for the condensed fonts to look readable. For some reason, it is disabled by default on a number of Linux distributions.

      <match target="font">
        <edit mode="assign" name="hinting">
          <bool>true</bool>
        </edit>
      </match>
    
  7. keramida Post author

    Thanks Philip. I think I fixed it, by copying the “hinting” section from my current ~/.fonts.conf. WordPress comment-syntax keeps amazing me too; not always in a nice way.

  8. Philip Paeps

    I’ve been using these fonts for a couple of days now and I have to say: much friendlier on the eyes than the “default” DejaVu fonts. I’m still absolutely not convinced about “truetype” fonts for code (I still use terminus for all my fixed-width needs), but this tip made “the web” slightly less unpleasant for me again.

    Thanks. :-)

  9. keramida Post author

    I know the feeling. I still use my own hacked version of lucida-sans-typewriter-12 for terminals. TrueType fonts look less pleasing to my eyes for code and terminal windows.

    I’m glad you liked the condensed variants, Philip :-)

  10. Taro

    Hi there. I tried this tip on Debian Lenny, but unfortunately I still cannot seem to use the concensed version of DejaVu. (I’m banging my head trying to correct all texts in my old ooimpress presentations which were all in DejaVu Sans Condensed….)

    Just editing ~/.fonts.conf the way described in the article should do it, correct?

    Anyways, thank you very must for posting this tip. Hopefully I can eventually figure this one…

    1. keramida

      I’m not sure if OpenOffice uses plain fontconfig to handle fonts. ISTR seeing guides about “Installing fonts for OOo” on the net, e.g. http://wiki.services.openoffice.org/wiki/Font-FAQ

      If OOo handles fonts in a special way it may need OOo-specific customizations to switch to the condensed variant of DejaVu. Since I don’t use OOo at all, it’s probably a good idea to ask around in one of their mailing lists too.

  11. Felix Miata

    If you only need DejaVu Sans Condensed to be the default in web browsers, then going through fontconfig and preventing DejaVu Sans from ever being used is the overkill. Instead, put in a user stylesheet (usually /*.slt/chrome/userContent.css in Firefox, SeaMonkey or older Epiphany versions; create if file does not already exist):

    * {font-family: ‘dejavu sans condensed’ !important}

    and then restart the browser. That’s all it takes. It overrides whatever default family is set in your browser prefs, the same way web pages do it.

    1. Giorgos Keramidas

      Fair point, but this way is also a bit heavy handed. It forces “DejaVu Sans Condensed” even on sites whose designers chose “Georgia” or “Garamond”.

      I still use the fontconfig-based method, even though 1.5+ years have passed. It affects “only” the DejaVu fonts, only at the web places where the author has not chosen an alternate font, and it also works for the dejavu variants I use on desktop applications (e.g. desktop font, default application font, etc. in Gnome).

  12. Felix Miata

    The rule as I wrote is has low specificity. As designers have a proclivity to overspecify, most of the time the user stylesheet will not apply anyway. You could make it even less applicable by replacing “*” with “body” or even “html” to simply overrule a broken browser’s idea of what’s an allowable default.

    As to designers specifying serif fonts, whose (personal) computer are you using? Wouldn’t you rather see more of your favorite font family and less of theirs? As it is it’s rather uncommon that user defaults ever get seen except when they happen to match the designer preference. Note too that IE and Safari don’t have separate prefs for serif and sans-serif, so whichever type has been chosen will always be the fallback in the rather rare case when the designer has somehow failed to specify anything at all.

    FWIW, when DejaVu Sans Condensed first appeared, I made it my default. I’ve since switched my preference to Droid. You could install an early version and then Gecko would be able to offer it as a default. Installing might be as simple as dumping an old copy into ~/.fonts, instead of going through the traditional font installation/uninstallation process. I’ve not played with DejaVu Sans Condensed or tweaking via ~/.fonts in quite some time.

Comments are closed.