Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

Using Sharp Fonts On A GNOME Desktop


You might have noticed that fonts are quite fuzzy on Linux desktops which can make your eyes ache if you have to sit in front of your computer all day long. Font rendering is still a little bit awkward and one of the last weaknesses of Linux desktops. This tutorial shows how you can make GNOME and all GNOME applications (such as Evolution, the file browser Nautilus, etc.) use sharp fonts. In fact, we will use the Microsoft Windows standard font, Tahoma, as the standard font in GNOME, too, which will make the desktop look quite familiar if you are used to working with a Windows desktop.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I have tested this on Ubuntu 6.10 (Edgy Eft) and 7.04 (Feisty Fawn), but this should work for any GNOME desktop (except for the part where I install packages – installing packages is distribution-specific, and I don’t cover the differences between the various distributions here).

It should be noted that these changes affect only GNOME and GNOME applications – unfortunately other applications such as Mozilla Firefox or OpenOffice will not benefit from them. (If you know how to change that with a simple configuration change, please tell me. But I’m not interested in changing the fonts configuration for every single application.)

I’m going to install the package msttcorefonts in this tutorial which contains most Windows fonts, but not all. Especially the Tahoma font is not included in this package; therefore you need a Windows system (and of course a valid Windows license) to copy Tahoma over to your GNOME desktop.

I’ve put this tutorial together from various sources I’ve found on the internet, especially:

  • http://ubuntuforums.org/showthread.php?t=20976
  • http://textsnippets.com/tag/gnome
  • http://fontconfig.org/fontconfig-user.html
  • http://wiki.archlinux.org/index.php/XOrg_Font_Configuration

I’d like to thank the authors of the above documents for their work! It’s highly appreciated.

 

2 Comparison Before – After

To give you an impression of what you will get, I’m going to show you the differences with the help of some screenshots in their original size (I haven’t resized them as that would distort your impression).

This is how the fonts in the menu look like now:

6

And this is how they will look after your changes. As you see, the fonts are much sharper which is better for your eyes. And as an additional benefit, if you’ve switched from a Windows desktop, you will feel right at home with the new font as it is the Windows font Tahoma:

12

Nautilus (File Browser) – Before

7

Nautilus (File Browser) – After

13

Tooltips – Before

8

Tooltips – After

14

Evolution – Before

9

Evolution – After

15

3 Configure X And GNOME

First we must configure X to use 96 dpi by modifying /etc/X11/xorg.conf. Open a terminal and run

sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
sudo gedit /etc/X11/xorg.conf

Search for the monitor section (Section “Monitor”). Put the following lines at the end of that section:

#    DisplaySize    270    203    # 1024×768 96dpi
#    DisplaySize    338    254    # 1280×960 96dpi
#    DisplaySize    338    270    # 1280×1024 96dpi
#    DisplaySize    370    277    # 1400×1050 96dpi
#    DisplaySize    423    370    # 1600×1400 96dpi

If you have another screen resolution than the ones listed above, please add a line for your resolution. You can calculate the DisplaySize like this:

displaysize = (<pixelsize>/96)*25.4

Then uncomment the line that suits your screen resolution. If you have a resolution of 1024×768 pixels, the monitor section should look like this in the end:

[...]
Section "Monitor"
        Identifier        "Generic Monitor"
        Option                "DPMS"
        HorizSync        28-51
        VertRefresh        43-60
        DisplaySize    270    203    # 1024x768 96dpi
#       DisplaySize    338    254    # 1280x960 96dpi
#       DisplaySize    338    270    # 1280x1024 96dpi
#       DisplaySize    370    277    # 1400x1050 96dpi
#       DisplaySize    423    370    # 1600x1400 96dpi
EndSection
[...]

Then reboot the system:

sudo shutdown -r now

After the system has come up again, open a terminal again and run the following commands:

xdpyinfo | grep dimensions

The output should display the correct screen resolution, like this:

falko@falko-desktop:~$ xdpyinfo | grep dimensions
dimensions:    1024×768 pixels (271×203 millimeters)

xdpyinfo | grep resolution

This should show that X is now using 96 dpi:

falko@falko-desktop:~$ xdpyinfo | grep resolution
resolution:    96×96 dots per inch

Now we must tell GNOME to use 96 dpi. Go to System > Preferences > Font:

9b

Click on the Details button. The following window comes up where you must select 96 dpi as resolution (usually this is already the default value):

9c

4 Install Microsoft Fonts

To install Microsoft fonts on your system, please make sure that the Ubuntu universe and multiverse repositories are enabled in /etc/apt/sources.list:

sudo gedit /etc/apt/sources.list

For Ubuntu Edgy Eft, you should have the following lines in that file (please use a repository that is close to you):

[...]
deb http://de.archive.ubuntu.com/ubuntu/ edgy universe
deb-src http://de.archive.ubuntu.com/ubuntu/ edgy universe

deb http://de.archive.ubuntu.com/ubuntu/ edgy multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ edgy multiverse
[...]

And for Ubuntu Feisty Fawn, the lines should look like this:

[...]
deb http://de.archive.ubuntu.com/ubuntu/ feisty universe
deb-src http://de.archive.ubuntu.com/ubuntu/ feisty universe

deb http://de.archive.ubuntu.com/ubuntu/ feisty multiverse
deb-src http://de.archive.ubuntu.com/ubuntu/ feisty multiverse
[...]

If you had to modify /etc/apt/sources.list, please run this command to update the packages database:

sudo apt-get update

Then install the Microsoft fonts:

sudo apt-get install msttcorefonts

In the next step we must copy the Tahoma fonts (which aren’t included in the msttcorefonts package) from our Windows system to our Linux system and register the new Tahoma fonts.

First we create a new directory for the Tahoma fonts:

sudo mkdir /usr/share/fonts/truetype/custom

Then copy the files tahoma.ttf and tahomabd.ttf from the C:\WINDOWS\Fonts directory on your Windows system to /usr/share/fonts/truetype/custom/ (e.g. with a USB stick).

Next create the file /etc/defoma/hints/custom.hints:

sudo gedit /etc/defoma/hints/custom.hints

category truetype
begin /usr/share/fonts/truetype/custom/tahoma.ttf
  Family = Tahoma
  FontName = Tahoma-Regular
  Encoding = Unicode
  Location = Magyar Dutch Spanish Czech Russian English Catalan Slovak Italian Turkish Danish Slovenian Basque Portuguese German Polish Swedish Norwegian French Finnish Greek
  Charset = ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 ISO8859-7 ISO8859-9 ISO8859-10 ISO8859-13 ISO8859-14 ISO8859-15 KOI8-R KOI8-U CP1251 VISCII1.1-1 TCVN-5712 ISO10646-1
  UniCharset = ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 ISO8859-7 ISO8859-9 ISO8859-10 ISO8859-13 ISO8859-14 ISO8859-15 KOI8-R KOI8-U CP1251 VISCII1.1-1 TCVN-5712
  GeneralFamily = SansSerif
  Weight = Medium
  Width = Variable
  Shape = NoSerif Upright
  Foundry = Microsoft
  Priority = 20
end
begin /usr/share/fonts/truetype/custom/tahomabd.ttf
  Family = Tahoma
  FontName = Tahoma-Bold
  Encoding = Unicode
  Location = Magyar Dutch Spanish Czech Russian English Catalan Slovak Italian Turkish Danish Slovenian Basque Portuguese German Polish Swedish Norwegian French Finnish Greek
  Charset = ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 ISO8859-7 ISO8859-9 ISO8859-10 ISO8859-13 ISO8859-14 ISO8859-15 KOI8-R KOI8-U CP1251 VISCII1.1-1 TCVN-5712 ISO10646-1
  UniCharset = ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 ISO8859-7 ISO8859-9 ISO8859-10 ISO8859-13 ISO8859-14 ISO8859-15 KOI8-R KOI8-U CP1251 VISCII1.1-1 TCVN-5712
  GeneralFamily = SansSerif
  Weight = Bold
  Width = Variable
  Shape = NoSerif Upright
  Foundry = Microsoft
  Priority = 20
end

Afterwards, we register our new fonts:

sudo /usr/bin/defoma-font -v register-all /etc/defoma/hints/custom.hints
sudo dpkg-reconfigure fontconfig

5 Configure GNOME Font Preferences

Now we have to tell GNOME which fonts it should use for applications, on the desktop, in window titles, etc. Go to System > Preferences > Font:

10

Select Tahoma (8 pt.) for Application font, Document font, Desktop font, and Window title font, and Monospace (10 pt.) for Fixed width font. Also make sure that Subpixel smoothing (LCDs) is enabled:

11

6 Create A .fonts.conf File In Your Home Directory

To control the behaviour of our fonts (anti-aliasing, hinting, font sizes to be smoothed, etc.), we can create the file ~/.fonts.conf. This is an XML file. After lots of experiments I found that this one works the best for me:

gedit ~/.fonts.conf

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

<!-- Give all fonts light hinting and subpixel smoothing -->
<!--
<match target="font">
    <edit mode="assign" name="rgba">
        <const>rgb</const>
    </edit>
    <edit mode="assign" name="hinting">
        <bool>true</bool>
    </edit>
    <edit mode="assign" name="hintstyle">
        <const>hintslight</const>
    </edit>
    <edit mode="assign" name="antialias">
        <bool>true</bool>
    </edit>
</match>
-->

<!--
     <match target="font">
        <test qual="all" name="rgba"><const>unknown</const></test>
           <edit name="rgba" mode="assign"><const>rgb</const></edit>
     </match>
-->

<!--  Do not smooth Fixedsys  -->
<match target="font">
    <test name="family">
        <string>FixedsysTTF</string>
    </test>
    <edit name="antialias">
        <bool>false</bool>
    </edit>
</match>

<!--  Do not smooth Tahoma 8pt and under  -->
<match target="font">
    <test name="family">
        <string>Tahoma</string>
    </test>
    <test compare="less" name="size" qual="any">
        <double>9</double>
    </test>
    <edit name="antialias">
        <bool>false</bool>
    </edit>
</match>

<!--  Do not smooth Times New Roman or Courier New for 12pt and under  -->
<match target="font">
    <test name="family">
        <string>Times New Roman</string>
    </test>
    <test compare="less" name="size" qual="any">
        <double>13</double>
    </test>
    <edit name="antialias">
        <bool>false</bool>
    </edit>
</match>

<match target="font">
    <test name="family">
        <string>Courier</string>
        <string>Courier New</string>
        <string>Courier 10 Pitch</string>
    </test>
    <test compare="less" name="size" qual="any">
        <double>11</double>
    </test>
    <edit name="antialias">
        <bool>false</bool>
    </edit>
</match>

<!-- Do not autohint Courier New, Fixedsys, Tahoma, or Times New Roman -->
<match target="font">
    <test name="family">
        <string>Courier New</string>
        <string>Times New Roman</string>
        <string>Tahoma</string>
        <string>FixedsysTTF</string>
    </test>
    <edit mode="assign" name="hintstyle">
        <const>hintslight</const>
    </edit>
    <edit mode="assign" name="autohint">
        <bool>false</bool>
    </edit>
</match>

<match target="pattern">
            <test qual="any" name="family">
                    <string>Bitstream Vera Sans</string>
            </test>
            <edit name="family" mode="assign">
                    <string>Arial</string>
            </edit>
</match>
    <match target="pattern">
            <test qual="any" name="family">
                    <string>Helvetica</string>
            </test>
            <edit name="family" mode="assign">
                    <string>Arial</string>
            </edit>
</match>
<match target="pattern">
            <test qual="any" name="family">
                    <string>Palatino</string>
            </test>
            <edit name="family" mode="assign">
                    <string>Georgia</string>
            </edit>
</match>
</fontconfig>

(If you’d like to find out more about available configuration options, how to use that file, etc., please refer to these pages:

http://fontconfig.org/fontconfig-user.html
http://wiki.archlinux.org/index.php/XOrg_Font_Configuration

)

Each time you modify ~/.fonts.conf you must log out of GNOME and back in for the changes to take effect, so please log out now and back in.

After you’ve logged in again, you should now see that your fonts look exactly like on the After screenshots in chapter 2!

If you want GTK1 applications to use Tahoma, too, please create the file ~/.gtkrc.mine with the following contents:

gedit ~/.gtkrc.mine

style “user-font”
{
fontset=”-microsoft-tahoma-medium-r-normal-*-10-*-*-*-p-*-*”
}
widget_class “*” style “user-font”
7 Links

HOWTO: Hoary ClearType-like fonts: http://ubuntuforums.org/showthread.php?t=20976
.fonts.conf Sample: http://textsnippets.com/tag/gnome
fonts.conf Documentation: http://fontconfig.org/fontconfig-user.html
Fonts Configuration (Arch Linux Wiki): http://wiki.archlinux.org/index.php/XOrg_Font_Configuration
GNOME: http://www.gnome.org
Ubuntu: http://www.ubuntu.com

Comments

comments