Fonts – Override Fonts Installed by ttf-mscorefonts-installer


I had to apt-get install ttf-mscorefonts-installer on Ubuntu 12.04/12.10. The short version is I need to pipe PDF files out of an application that requires these fonts for certain glyphs.

The problem, after running this command, is that the fonts in my web browser (and some java apps) are now "ugly." Obviously this is a subjective opinion but it is the one I hold.

I want the old fonts back for most cases (Liberation, DejaVu, Ubuntu, …). I'm not sure how best to describe this but here's an example:

Example CSS in Webbrowser

font-family: Verdana,Arial,sans-serif;

Without ttf-mscorefonts-installer (Case 1):

    $ fc-match Verdana
    LiberationSans-Regular.ttf: "Liberation Sans" "Regular"

    $ fc-match Arial
    LiberationSans-Regular.ttf: "Liberation Sans" "Regular"

    $ fc-match sans-serif
    LiberationSans-Regular.ttf: "Liberation Sans" "Regular"`

With ttf-mscorefonts-installer (Case 2):

    $ fc-match Verdana
    Verdana.ttf: "Verdana" "Normal"

    $ fc-match Arial
    Arial.ttf: "Arial" "Normal"

    $ fc-match sans-serif
    LiberationSans-Regular.ttf: "Liberation Sans" "Regular"`

I want (Case 1). Optionally, I want the fonts in (Case 2) not to look "ugly" IE. they are more jagged, less smooth than their free alternatives in my web browsers.

Is this possible?

Best Answer

fontconfig employs a complete set of font substitution systems. There are different levels of font definition: font name and font families. Given a specific font, fontconfig uses the font of the same name if available, then seeks otherwise the font family of the same name. If there is still no match, it uses the standard font family definition as substitution, i.e. Sans, Sans-serif and Mono.

Ubuntu has the font family 'Verdana' defined in `/etc/fonts/conf.d/45-latin.conf', where 'Verdana' is set default to 'Sans-serif', which means Sans-serif is employed for 'Verdana' by default. But 'Verdana.ttf' would be used instead if it's installed.

In your system, the preferred font in the Sans-serif family is 'Liberation Sans', so fontconfig uses the 'Liberation Sans' as substitution for 'Verdana' provided there is no font of the same name, whereas uses 'Verdana.ttf' if it's in the search path. This explains what you've posted.

So the solution to your problem is that, you have to remap the font 'Verdana' to a different font, or to a group of fonts which assigns to 'Liberation Sans' the highest priority. (The latter case is recommended)

Open or create the file ~/.config/fontconfig/fonts.conf, append following:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">

    <test name="family"><string>Verdana</string></test>
    <edit name="family" mode="prepend" binding="strong">
        <string>Liberation Sans</string>


Note that ~/.fonts.conf is deprecated now, and if you already have user-defined fonts.conf, remove the header and footer and only keep the 'match' section. And it would be too long-winded to demonstrate the same workaround on 'Arial'. I'm sure you can find it on your own.

Related Question