Making ubuntu fonts not suck

This describes the steps I took to make fonts on Ubuntu 5.10 (Breezy something) look nicer. Results are here.

Note: I don't fully understand the details of how or why this works. Be warned.

  1. Configure X to run at 96 DPI:
    sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
    sudo gedit /etc/X11/xorg.conf
    Add these lines at the end of the Section "Monitor":
    #	DisplaySize	211	158	# 800x600 96dpi
    #	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

    Uncomment the line that corresponds to your monitor resolution. If your resolution is not listed here, you can use the following formula to calculate the numbers to use with DisplaySize: DisplaySize = pixelsize/96*25.4. E.g. 270=1024/96*25.4

    Restart X (usually CTRL+ALT+Backspace) or reboot, then check that DPI is set to 96. (You really need to do this.)

    xdpyinfo | grep resolution

    If resolution is not 96x96, adjust the values for DisplaySize and restart X. Repeat.

  2. Configure Gnome to run at 96 DPI in System > Preferences > Font > Details
  3. Install Microsoft fonts. You'll need to tweak /etc/apt/sources.list to allow installation from multiverse.
    sudo apt-get install msttcorefonts

    Install Tahoma by copying tahoma*.ttf from %WINDIR%\Fonts to ~/.fonts. Yes, you need Windows for that.

    I also installed Lucida console

  4. Reconfigure fontconfig:
    sudo dpkg-reconfigure fontconfig

    I used default answers (Native, Always, No).

  5. Configure Gnome and other apps. I used these settings:

    System > Preferences > Fonts:
    Application font and Desktop font: Tahoma 10, Window title font: Verdana Bold 10, Terminal font: Bitstream Vera Sans Mono Roman 10, Font Rendering: Subpixel smoothing

    Firefox: Edit > Preferences > Content > Fonts & Colors > Advanced:
    Proportional: Serif 16, Serif: Verdana, Sans-serif: Arial, Monospace: Courier New 12

    Make gedit use Lucida Console.

  6. Put the following in ~/.fonts.conf. Pay attention to the name: dot fonts dot conf. There's a man document cleverly named "fonts-conf". Despite this, the file you need is ~/.fonts.conf.
    <?xml version="1.0"?>
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
    <fontconfig>
      <!-- First turn on Hinting and Anti-aliasinng for everything -->
      <match target="font" >
        <edit mode="assign" name="hinting" ><bool>true</bool></edit>
      </match>
      <match target="font" >
        <edit mode="assign" name="hintstyle" ><const>hintfull</const></edit>
      </match>
      <match target="font" >
        <edit mode="assign" name="antialias" ><bool>true</bool></edit>
      </match>
      
      <!-- Turn AA off for font size range but leave on for BOLD -->
      <match target="font" >
        <test compare="more_eq" name="pixelsize" qual="any" ><double>9</double></test>
        <test compare="less_eq" name="pixelsize" qual="any" ><double>17</double></test>
        <test name="weight" compare="less"><int>200</int></test>
        <edit mode="assign" name="antialias"><bool>false</bool></edit>
      </match>
      
      <!-- Commented these out, because they make bold fonts look blurry for me -->
      <!-- Turn BCI Hinting off for Bold Type -->
      <!--match target="font"><test name="weight" compare="more_eq"><int>200</int></test>
        <edit name="hinting" mode="assign"><bool>false</bool></edit>
      </match-->
      <!-- Turn Native Auto-hinting on for Bold Type -->
      <!--match target="font"><test name="weight" compare="more_eq"><int>200</int></test>
        <edit name="autohint" mode="assign"><bool>true</bool></edit>
      </match-->
      
      <!-- Turn BCI Hinting off for small font sizes -->
      <match target="font">
        <test compare="less_eq" name="pixelsize" qual="any"><double>8</double></test>
        <edit mode="assign" name="hinting"><bool>false</bool></edit>
      </match>
      
      <!-- Turn Anti-aliasing on for all Courier font sizes -->
      <match target="font">
        <test name="family" qual="any" compare="eq"><string>Courier</string></test>
        <edit mode="assign" name="antialias"><bool>true</bool></edit>
      </match>
      <!-- Same for Bitstream Mono which I use for the terminal -->
      <match target="font">
        <test name="family" qual="any" compare="eq"><string>Bitstream Vera Sans Mono</string></test>
        <edit mode="assign" name="antialias"><bool>true</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>

    The file could be tweaked further, but the above rules are good enough for me. The only thing is that bold fonts look a bit different from Windows, but it does not hurt my eyes anymore.

Credit goes to Google, ubuntuforums.org, and linuxquestions.org.