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:

$ fc-query /usr/share/fonts/roboto/Roboto-{Black,Regular,Medium}.ttf
Pattern has 20 elts (size 32)
        family: "Roboto"(s) "Roboto Bk"(s)
        familylang: "en"(s) "en"(s)
        style: "Black"(s) "Bold"(s)
        stylelang: "en"(s) "en"(s)
        fullname: "Roboto Black"(s)
        fullnamelang: "en"(s)
        slant: 0(i)(s)
        weight: 80(i)(s)
        width: 100(i)(s)
        foundry: "unknown"(s)
        file: "/usr/share/fonts/roboto/Roboto-Black.ttf"(s)
        index: 0(i)(s)
        outline: FcTrue(s)
        scalable: FcTrue(s)
        charset: 
        0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffffffff ffffffff ffffffff
        0001: ffffffff ffffffff ffffffff ffffffff 00040000 00018003 00000000 fc010000
        0002: 03000000 00800000 00000000 00000000 00000000 10000000 3f0002c0 00080000
        0003: 0000820b 00000008 00000000 00000000 ffffd7f0 fffffffb 00467fff 00000000
        0004: ffffffff ffffffff ffffffff ffffffff ffffff7f ffffffff ffffffff ffffffff
        0005: 000fffff 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        001e: 00000003 c0000000 00000000 00000000 0000003f ffffffff ffffffff 03ffffff
        001f: 00000000 00000000 00002000 00000000 00000000 00000000 00000000 00000000
        0020: 7fb80fff 160d0067 00000010 80100000 00000000 00001898 00000000 00000000
        0021: 00480020 00004044 78000000 00000000 00000000 00000000 00000000 00000000
        0022: 44068044 00000800 00000100 00000031 00000000 00000000 00000000 00000000
        0025: 00000000 00000000 00000000 00000000 00000000 00000000 00000400 00000000
        00f6: 00000000 00000000 00000000 00000000 00000000 00000000 00000008 00000000
        00fb: 0000001e 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        00fe: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 80000000
        00ff: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 30000000
(s)
        lang: aa|ab|af|av|ay|ba|be|bg|bi|bin|br|bs|bua|ca|ce|ch|chm|co|cs|cu|cv|cy|da|de|el|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gn|gv|ho|hr|hu|ia|ig|id|ie|ik|io|is|it|kaa|ki|kk|kl|kum|kv|ky|la|lb|lez|lt|lv|mg|mh|mk|mt|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ru|sah|se|sel|sh|sk|sl|sma|smj|smn|so|sq|sr|ss|st|sv|sw|tg|tk|tl|tn|tr|ts|tt|tyv|uk|uz|vo|vot|wa|wen|wo|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|lg|li|mn-mn|ms|na|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|ty|za(s)
        fontversion: 65536(i)(s)
        capability: "otlayout:DFLT"(s)
        fontformat: "TrueType"(s)
        decorative: FcFalse(s)

Pattern has 20 elts (size 32)
        family: "Roboto"(s)
        familylang: "en"(s)
        style: "Regular"(s)
        stylelang: "en"(s)
        fullname: "Roboto Regular"(s)
        fullnamelang: "en"(s)
        slant: 0(i)(s)
        weight: 80(i)(s)
        width: 100(i)(s)
        foundry: "unknown"(s)
        file: "/usr/share/fonts/roboto/Roboto-Regular.ttf"(s)
        index: 0(i)(s)
        outline: FcTrue(s)
        scalable: FcTrue(s)
        charset: 
        0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffffffff ffffffff ffffffff
        0001: ffffffff ffffffff ffffffff ffffffff 00040000 00018003 00000000 fc010000
        0002: 03000000 00800000 00000000 00000000 00000000 10000000 3f0002c0 00080000
        0003: 0000820b 00000008 00000000 00000000 ffffd7f0 fffffffb 00467fff 00000000
        0004: ffffffff ffffffff ffffffff ffffffff ffffff7f ffffffff ffffffff ffffffff
        0005: 000fffff 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        001e: 00000003 c0000000 00000000 00000000 0000003f ffffffff ffffffff 03ffffff
        001f: 00000000 00000000 00002000 00000000 00000000 00000000 00000000 00000000
        0020: 7fb80fff 160d0067 00000010 80100000 00000000 00001898 00000000 00000000
        0021: 00480020 00004044 78000000 00000000 00000000 00000000 00000000 00000000
        0022: 44068044 00000800 00000100 00000031 00000000 00000000 00000000 00000000
        0025: 00000000 00000000 00000000 00000000 00000000 00000000 00000400 00000000
        00f6: 00000000 00000000 00000000 00000000 00000000 00000000 00000008 00000000
        00fb: 0000001e 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        00fe: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 80000000
        00ff: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 30000000
(s)
        lang: aa|ab|af|av|ay|ba|be|bg|bi|bin|br|bs|bua|ca|ce|ch|chm|co|cs|cu|cv|cy|da|de|el|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gn|gv|ho|hr|hu|ia|ig|id|ie|ik|io|is|it|kaa|ki|kk|kl|kum|kv|ky|la|lb|lez|lt|lv|mg|mh|mk|mt|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ru|sah|se|sel|sh|sk|sl|sma|smj|smn|so|sq|sr|ss|st|sv|sw|tg|tk|tl|tn|tr|ts|tt|tyv|uk|uz|vo|vot|wa|wen|wo|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|lg|li|mn-mn|ms|na|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|ty|za(s)
        fontversion: 65536(i)(s)
        capability: "otlayout:DFLT"(s)
        fontformat: "TrueType"(s)
        decorative: FcFalse(s)

Pattern has 20 elts (size 32)
        family: "Roboto"(s) "Roboto Lt"(s)
        familylang: "en"(s) "en"(s)
        style: "Medium"(s) "Regular"(s)
        stylelang: "en"(s) "en"(s)
        fullname: "Roboto Medium"(s)
        fullnamelang: "en"(s)
        slant: 0(i)(s)
        weight: 100(i)(s)
        width: 100(i)(s)
        foundry: "unknown"(s)
        file: "/usr/share/fonts/roboto/Roboto-Medium.ttf"(s)
        index: 0(i)(s)
        outline: FcTrue(s)
        scalable: FcTrue(s)
        charset: 
        0000: 00000000 ffffffff ffffffff 7fffffff 00000000 ffffffff ffffffff ffffffff
        0001: ffffffff ffffffff ffffffff ffffffff 00040000 00018003 00000000 fc010000
        0002: 03000000 00800000 00000000 00000000 00000000 10000000 3f0002c0 00080000
        0003: 0000820b 00000008 00000000 00000000 ffffd7f0 fffffffb 00467fff 00000000
        0004: ffffffff ffffffff ffffffff ffffffff ffffff7f ffffffff ffffffff ffffffff
        0005: 000fffff 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        001e: 00000003 c0000000 00000000 00000000 0000003f ffffffff ffffffff 03ffffff
        001f: 00000000 00000000 00002000 00000000 00000000 00000000 00000000 00000000
        0020: 7fb80fff 160d0067 00000010 80100000 00000000 00001898 00000000 00000000
        0021: 00480020 00004044 78000000 00000000 00000000 00000000 00000000 00000000
        0022: 44068044 00000800 00000100 00000031 00000000 00000000 00000000 00000000
        0025: 00000000 00000000 00000000 00000000 00000000 00000000 00000400 00000000
        00f6: 00000000 00000000 00000000 00000000 00000000 00000000 00000008 00000000
        00fb: 0000001e 00000000 00000000 00000000 00000000 00000000 00000000 00000000
        00fe: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 80000000
        00ff: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 30000000
(s)
        lang: aa|ab|af|av|ay|ba|be|bg|bi|bin|br|bs|bua|ca|ce|ch|chm|co|cs|cu|cv|cy|da|de|el|en|eo|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gn|gv|ho|hr|hu|ia|ig|id|ie|ik|io|is|it|kaa|ki|kk|kl|kum|kv|ky|la|lb|lez|lt|lv|mg|mh|mk|mt|nb|nds|nl|nn|no|nr|nso|ny|oc|om|os|pl|pt|rm|ru|sah|se|sel|sh|sk|sl|sma|smj|smn|so|sq|sr|ss|st|sv|sw|tg|tk|tl|tn|tr|ts|tt|tyv|uk|uz|vo|vot|wa|wen|wo|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|lg|li|mn-mn|ms|na|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|ty|za(s)
        fontversion: 65536(i)(s)
        capability: "otlayout:DFLT"(s)
        fontformat: "TrueType"(s)
        decorative: FcFalse(s)

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 –

<selectfont>
        <rejectfont>
                <pattern>
                        <patelt name="family"><string>Roboto Lt</string></patelt>
                        <patelt name="weight"><int>100</int></patelt>
                </pattern>
                <pattern>
                        <patelt name="family"><string>Roboto Bk</string></patelt>
                </pattern>
        </rejectfont>
</selectfont>

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:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
        <match target="font">
                <edit mode="assign" name="hinting">
                        <bool>true</bool>
                </edit>
        </match>
        <match target="font">
                <edit mode="assign" name="hintstyle">
                        <const>hintslight</const>
                </edit>
        </match>
        <match target="font">
                <edit mode="assign" name="antialias">
                        <bool>true</bool>
                </edit>
        </match>
        <!--match target="font">
                <test qual="any" name="size" compare="less">
                        <double>9.0</double>
                </test>
                <edit name="size" mode="assign">
                        <double>9.0</double>
                </edit>
        </match-->
        <match target="font">
                <test qual="any" name="size" compare="less">
                        <double>10.0</double>
                </test>
                <test qual="any" name="family">
                        <string>Monaco</string>
                </test>
                <edit name="size" mode="assign">
                        <double>10.0</double>
                </edit>
        </match>
        <alias>
                <family>serif</family>
                <default>
                        <family>Roboto</family>
                </default>
        </alias>
        <alias>
                <family>sans-serif</family>
                <default>
                        <family>Roboto</family>
                </default>
        </alias>
        <alias>
                <family>monospace</family>
                <default>
                        <family>Monaco</family>
                </default>
        </alias>
        <selectfont>
                <rejectfont>
                        <pattern>
                                <patelt name="family"><string>Roboto Lt</string></patelt>
                                <patelt name="weight"><int>100</int></patelt>
                        </pattern>
                        <pattern>
                                <patelt name="family"><string>Roboto Bk</string></patelt>
                        </pattern>
                </rejectfont>
        </selectfont>
</fontconfig>

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

13 Comments on “Configuring Roboto font in Linux”

  1. 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)

    Like

  2. Thank you very much! I still prefer Droid Sans on my Laptop, but Roboto looks a lot better now!

    Like

    • I tried Droid Sans, but didn’t like it and found not much difference between Liberation Sans and DejaVu Sans. Or may be I was mislead by some similar configuration bug :O

      Like

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

    Like

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

    Like

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

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: