Anti-aliasing everything in XFree86 4.0.2+

  • Adrian Chung <adrian@enfusion-group.com>
  • One of my pet peeves about Linux on the desktop has always been its absolutely terrible font support. No anti-aliased fonts, combined with terrible fonts means that lots of applications, including web browsers look terrible.

    One of the nice things about upgrading to RedHat 7.2, or Debian is that there's support for anti-aliased fonts in QT out of the box.

    This means that if you run KDE, which is based on the QT widget set, your entire desktop, and apps, will inherit anti-aliased fonts, and font settings.

    I browse using Opera, mainly because it's fast, good, and uses QT, so I automatically inherit QT's anti-aliased fonts:

    No anti-aliasing:

    (click for larger image)
    Anti-aliased:

    (click for larger image)

    Here's a shot of my entire desktop:

    Desktop:

    (click for larger image)

    You can see Opera, Konqueror, and an xterm, all using anti-aliased fonts.

    Enabling anti-aliasing in XFree86 4.0.2+

    Anti-aliasing requires both support in QT, and hardware support. To my knowledge, all recent Matrox and nvidia cards support the RENDER extension. To check, while running XFree86 > 4.0.2, and run:

        $ xdpyinfo 
        name of display:    :0.0
        version number:    11.0
        vendor string:    The XFree86 Project, Inc
        vendor release number:    40100000
        XFree86 version: 4.1.0
        maximum request size:  4194300 bytes
        motion buffer size:  256
        bitmap unit, bit order, padding:    32, LSBFirst, 32
        image byte order:    LSBFirst
        number of supported pixmap formats:    7
        supported pixmap formats:
            depth 1, bits_per_pixel 1, scanline_pad 32
            depth 4, bits_per_pixel 8, scanline_pad 32
            depth 8, bits_per_pixel 8, scanline_pad 32
            depth 15, bits_per_pixel 16, scanline_pad 32
            depth 16, bits_per_pixel 16, scanline_pad 32
            depth 24, bits_per_pixel 32, scanline_pad 32
            depth 32, bits_per_pixel 32, scanline_pad 32
        keycode range:    minimum 8, maximum 255
        focus:  window 0x1a14af2, revert to Parent
        number of extensions:    26
            BIG-REQUESTS
            DOUBLE-BUFFER
            DPMS
            Extended-Visual-Information
            FontCache
            GLX
            LBX
            MIT-SCREEN-SAVER
            MIT-SHM
            MIT-SUNDRY-NONSTANDARD
            RENDER
            SECURITY
            SGI-GLX
            SHAPE
            SYNC
            TOG-CUP
            XC-APPGROUP
            XC-MISC
            XFree86-Bigfont
            XFree86-DGA
            XFree86-Misc
            XFree86-VidModeExtension
            XInputExtension
            XKEYBOARD
            XTEST
            XVideo
            [... lots of other output...]

    After that, make sure that your XF86Config file (/etc/X11/XF86Config-4 on RedHat and Debian systems) has both "freetype" and "type1" Load lines:

        [...]
        # Module loading section
        
        Section "Module"
        	Load  "dbe"		# Double-buffering
        	Load  "GLcore"		# OpenGL support
        	Load  "dri"		# Direct rendering infrastructure
        	Load  "glx"		# OpenGL X protocol interface
        	Load  "extmod"		# Misc. required extensions
        	Load  "v4l"		# Video4Linux
        	# Load  "pex5"		# PHIGS for X 3D environment (obsolete)
        	# Load  "record"	# X event recorder
        	# Load  "xie"		# X Image Extension (obsolete)
        	# You only need the following two modules if you do not use xfs.
        	Load  "freetype"	# TrueType font handler
        	Load  "type1"		# Adobe Type 1 font handler
        EndSection
        [...]

    This ensures that the XFree86 modules needed to support anti-aliasing are loaded.

    Now that XFree86 is configured and supports anti-aliasing, we'll need to actually to find some TrueType fonts, so that we can use them. Under RedHat, I copied TrueType fonts into /usr/share/fonts/default/TrueType/. If you have a Windows box you can simply copy TrueType fonts from the \Windows\Fonts folder. If not, Microsoft has a few free TrueType fonts for download here.

    Since RedHat 7.2 uses xfs as a font-server to serve fonts to X applications, I consulted /etc/X11/fs/config to see where it was configured to look for TrueType fonts:

        [...]
        # where to look for fonts
        #
        catalogue = /usr/X11R6/lib/X11/fonts/misc:unscaled,
    	/usr/X11R6/lib/X11/fonts/75dpi:unscaled,
    	/usr/X11R6/lib/X11/fonts/100dpi:unscaled,
    	/usr/X11R6/lib/X11/fonts/misc,
    	/usr/X11R6/lib/X11/fonts/Type1,
    	/usr/X11R6/lib/X11/fonts/Speedo,
    	/usr/X11R6/lib/X11/fonts/CID,
    	/usr/X11R6/lib/X11/fonts/75dpi,
    	/usr/X11R6/lib/X11/fonts/100dpi,
    	/usr/share/fonts/default/TrueType,
    	/usr/share/fonts/default/Type1,
    	/usr/share/fonts/ja/TrueType,
    	/usr/share/AbiSuite/fonts
        [...]

    I also made sure that my /etc/X11/XftConfig file referenced the directory I copied my fonts into:

        $ more /etc/X11/XftConfig
        # This file was automatically generated by gdkxft.
        # It should contain a reasonable Xft configuration given your
        # X server and fontserver setup.
    
        includeif	"~/.xftconfig"
    
        match any family == "fixed"		edit family =+ "LuciduxMono";
        match any family == "serif"		edit family += "LuciduxSerif";
        match any family == "sans"		edit family += "LuciduxSans";
        match any family == "mono"		edit family += "LuciduxMono";
    
        dir "/usr/lib/X11/fonts/Type1"
    
        dir "/usr/share/fonts/default/TrueType"
        [...]
    
        $ xftcache

    After copying my fonts to the proper location, I ran the following commands:

        $ cd /usr/share/fonts/default/TrueType
        $ ttmkfdir -o fonts.dir
        $ /etc/rc.d/init.d/xfs restart

    After restarting X, you should now be able to select TrueType fonts from within various applications. Under KDE, I had to set 'export QT_XFT=1' to make QT applications use the new Render extension, and allow me to select TrueType fonts, so I've simply added that to my ~/.bash_profile. I also ran 'kcontrol' and checked the 'Use Anti-Aliasing for fonts and icons' box.


    Last updated: Wednesday, April 18th, 2007