Configuring Roboto font in Linux

Roboto font comes from Android and Google designed it really well. It looks awesome on desktops and laptops. But getting it working as a default system font in Linux is quite a task because the font package of Roboto available has multiple font forms declaring same type of text style.

The standard Roboto package consists of following fonts:

  • Roboto-BlackItalic
  • Roboto-Black
  • Roboto-BoldCondensedItalic
  • Roboto-BoldCondensed
  • Roboto-BoldItalic
  • Roboto-Bold
  • Roboto-CondensedItalic
  • Roboto-Condensed
  • Roboto-Italic
  • Roboto-LightItalic
  • Roboto-Light
  • Roboto-MediumItalic
  • Roboto-Medium
  • Roboto-Regular
  • Roboto-ThinItalic
  • Roboto-Thin

Now the problem is, Roboto Black, Roboto Regular and Roboto Medium, are selected as candidates for the standard font. See the output below:

Read the style field of each font in the above output, you’ll see “Regular” in the field for Roboto-Regular.ttf and Roboto-Medium.ttf. But note another parameter, the weight of font. Robot-Black and Regular declare it as 80 while Medium declares it as 100.

Font selection happens in the alphabetical order first matching weight and then style. The weight for “Regular” size is 80. So the first font selected would be Roboto-Black, since it declares weight as 80 and appears before Roboto-Regular and Roboto-Medium in alphabetical order.
If you delete Roboto-Black, it will match Roboto-Medium which declares a weight of 100, but has “Regular” in the style specification.

The problem is, both these fonts Black and Medium are just too bold for daily use. You just can’t distinguish between bold and normal text and this causes ridiculous amount of confusion in applications like Thunderbird which use bold text to mark unread message and normal text otherwise.

To deal with this, a slight modification is needed in your font configuration file as follows –

If you add the above configuration to your fontconfig, it will blacklist Roboto Lt font with weight 100 (which is Medium) and Roboto Bk font which is Roboto Black. See the earlier fc-query output if you’re interested in how I got these values.

And here’s my /etc/fonts/local.conf:

Just ensure that this configuration is not overridden in any file /etc/fonts/conf.d. A simple way would be to clean up /etc/fonts/conf.d and keep the bare minimum you need.

Some screenshots for Roboto font as requested by Zachary Potter:

Process Monitor

roboto_thunderbird

roboto_dolphin

11 thoughts on “Configuring Roboto font in Linux

  1. Doesn’t work. It seems in version 1.2 of font, bold and medium variants has only one family name, not Roboto LT and Roboto Bk, so fontconfig rule cannot block them.

      • I usually don’t blacklist fonts.
        With version 1.2 now I got this problem in my system: Thin looks like Light, and Regular looks like Black too.
        Looking for fonts properties, now every non-condensed fonts has:

        family: “Roboto”

        while each fonts specific fields are (in order of boldness):

        style: “Thin”
        fullname: “Roboto Thin”
        weight: 50

        style: “Light”
        fullname: “Roboto Light”
        weight: 50

        style: “Regular”
        fullname: “Roboto Regular”
        weight: 80

        style: “Medium”
        fullname: “Roboto Medium”
        weight: 100

        style: “Bold”
        fullname: “Roboto Bold”
        weight: 200

        style: “Black”
        fullname: “Roboto Black”
        weight: 80

        The weights in fontconfig http://cgit.freedesktop.org/fontconfig/tree/fontconfig/fontconfig.h#n129 are defined this way:

        thin=0
        extralight=ultralight=40
        light=50
        book=75
        regular=normal=80
        medium=100
        demibold=semibold=180
        bold=200
        extrabold=ultrabold=205
        black=heavy=210
        extrablack=ultrablack=215

        (intermediate values can be used).

        Adjusting the wrong values via fontconfig could fix my problem:

        ———————————————

        Roboto Thin

        0

        Roboto Thin Italic

        0

        Roboto Black

        210

        Roboto Black Italic

        210

        ———————————————

        Other problem: Qt apps (like VLC) supports only five weights
        https://qt.gitorious.org/qt/qt/source/ece0bd590a06d8d8f4f922395a8e68f7b0e678e6:src/gui/text/qfont.h#L103
        that are translated from fontconfig this way:

        light = 0 ~ 75
        normal = 76 ~ 140
        demibold = 141 ~ 190
        bold = 191 ~ 205
        black = 206 ~ 215+

        This can cause fonts weights overlap. Example: Medium (100) is used instead of Regular (80) because both fall in the Qt ‘normal’ weight (76~140).
        In this case to use all the Roboto weights without blacklisting, a possible solution could be to separate them in two groups:
        Thin, Regular and Bold in the family “Roboto” (the default family name, no changes);
        Light, Medium and Black in the family “Roboto Thick” (or whatever name, as we’ll use fontconfig).
        The resulting config, including the previous weights corrections is:

        ———————————————

        Roboto Thin

        0

        Roboto Thin Italic

        0

        Roboto Light

        Roboto Thick

        Roboto Light Italic

        Roboto Thick

        Roboto Medium

        Roboto Thick

        Roboto Medium Italic

        Roboto Thick

        Roboto Black

        Roboto Thick

        210

        Roboto Black Italic

        Roboto Thick

        210

        ———————————————

        This config could be added in already existing configuration files, like /etc/fonts/local.conf or saved as /etc/fonts/conf.d/81-roboto.conf (adding the header and tags).

        Note: in Android platform source code (and I think in all Android devices too), Medium and Black aren’t included, nor used. They’re present only in the separate .zip download.

  2. The fonts seem to just declare their weights incorrectly internally, which is what messes Fontconfig up. I’ve tried to report it a few places, with little luck. Maybe it’s only the “OS/2″ older-style data that’s wrong, but that’s what Fontconfig seems to use.

  3. No wonder Roboto was so bold! Seriously, the fontconfig developers should include these hacks in their software instead of making people write massive fonts.conf file to fix their issues (disabling hinting for Microsoft fonts at low sizes, for example)

Leave a Reply