I Can See Clearly Now, the Fonts Are Smooth

by Jeffery D. Sauer

Isn't technology wonderful? There has never been an easier time to run Linux. The progress we've seen over the past few years is nothing short of amazing. Today, from the comfort of your own keyboard, you can browse for your favorite distribution, download it, burn your own CD-Rs and install. In fact, I think it's safe to say that the biggest hurdle holding users back is fear of the unknown. But, Linux is an adventure and that's half the fun.

I've been running Linux off and on for several years now. When Red Hat 9.0 was released, I finally decided to take the plunge and dedicate a machine to running Linux full-time. The machine is pretty decent: a gigabyte of RAM, plenty of disk space, dual Athlon XP1600+ CPUs and two Nvidia graphics cards used to support the three 21" monitors it has attached (one graphic card has support for two monitor connectors). Overall, installation was a breeze, and Red Hat 9.0 recognized and configured all of the devices just fine. About the only thing I had to do was download and install the new graphics driver from Nvidia and make some minor configuration changes for the X server to recognize all three monitors I had attached.

So, here I am working on my newly configured machine. After playing around with all of the goodies included in the distribution, I decide to launch the browser and surf the Net for a while. To my horror, the rendered text in Mozilla looked terrible. The rods and cones in my eyes started going bonkers! As can be seen in Figure 1, the characters were difficult to read and full of jaggies. How could this be? Can't Linux do better then this?

6854f1.gif Figure 1. Before Xft

Well, it can, with Xft.

Xft is a client-side API that works with the X server to smooth out fonts and, if available, leverage the X Render extension to accelerate text drawing. If the X Render extension is not available, it uses the base X protocol to draw the client-side glyphs. This, however, can cause a severe performance penalty as it involves fetching pixel information, merging the glyphs with the pixels and then sending them back. Thankfully, most modern versions of Linux ship with X Render included so this isn't be a problem.

Xft is only a single part of the infrastructure used to anti-alias text on Linux. As mentioned above, X Render is used to accelerate the process. Another component, called Fontconfig, is used to select the fonts and protocols used for rendering them. Yet another component, called FreeType, is a font engine used by Xft to rasterize the fonts. By simply enabling anti-aliasing support in an application, we are setting in motion a rather complex chain of events and technologies used to accomplish the task. The results can be seen in Figure 2.

6854f2.gifFigure 2. After Xft

For applications to take advantage of Xft, they first need to be compiled with the proper options and then linked with the correct libraries. If you tend to download and use pre-compiled Linux binaries, chances are these are not Xft-enabled. To see if your current version of Mozilla (or any application) is Xft-enabled, simply check what libraries it loads dynamically upon execution by using the ldd command from a terminal window:


     cd /usr/lib/<your-mozilla-home-directory> 
     ldd mozilla-bin 

If you see libXft in the list, congratulations; your browser already is enabled. Unfortunately, this may not be the case for most users, who need either to find a pre-built version of Mozilla with Xft enabled or to build it themselves.

I decided to build it myself. If you've never built a large Linux application before, don't worry; it's not that difficult. Over the years, I've found that compiling software is a lot like cooking--the results tend to be as good as the recipe used to make it. As with cooking, you can change the recipe to your liking, but you still need to know what ingredients to change to get the desired results. With that said, here is my personal recipe for Xft-enabled Mozilla. All of these steps are done from a single terminal window.

Step 1. Make sure the following five packages are installed: XFree86-4.3, XFree86-100dpi-fonts-4.3, XFree86-75dpi-fonts-4.3, XFree86-libs-4.3 and XFree86-xfs-4.3. The best way to find out if they are installed is to issue an RPM query command:


     rpm -qa | grep XFree86

Step 2. You now are ready to download the source code for the Mozilla browser. I suggest making a local directory to hold everything:



     mkdir ~/mozilla-source 
     cd ~/mozilla-source 


Then download the latest stable Mozilla source:



     wget http://ftp25moz.newaol.com/pub/mozilla/
          releases/mozilla1.4a/src/
          mozilla-source-1.4a.tar.bz2 


Step 3. Unzip the tarball and create the .mozconfig file if it is not present already:



     tar xvjf ./mozilla-source-1.4a.tar.bz2
     touch .mozconfig 


Step 4. The .mozconfig file tells the build scripts how to configure the build, that is, what features to enable and disable. Edit the .mozconfig and make sure the following options are defined:



     ac_add_options --enable-crypto 
     ac_add_options --enable-optimize=Ó-O2 -march=i686Ó
     ac_add_options --enable-xft
     ac_add_options --disable-tests
     ac_add_options --disable-debug


Make sure you change march=i686 to something appropriate for your system; if in doubt, use i386. You also can choose to disable specific components-- Composer, Mail/News--by adding additional options:



     ac_add_options --disable-composer 


Step 5. Next, a few environment variables need to be defined before compiling:



     export MOZILLA_OFFICIAL=1
     export BUILD_OFFICIAL=1
     export MOZ_INTERNAL_LIBART_LGPL=1 


Step 6.Everything is ready now. First, run the configure command to prepare things, ./configure. Upon completion, begin the actual compilation process by typing make. The make command takes a while to complete--almost an hour for me on a Dual Athlon XP1600+ system. You still can use your system, however; simple push the terminal window into the background or minimize it to the taskbar. As when baking a cake, check in on it from time to time to make sure things are moving along. Assuming your development environment is set up properly, everything should go smoothly. If something goes wrong, search the Web for help on resolving the problem. A good place to find friendly advice and assistance are the forums at www.mozillazine.org.

Step 7. Assuming all went well, the final step is to install the newly built executable. First, let's get rid of all the excess junk generated during the build process with:

     cd xpinstall/packager 
     make 

These commands create a tarball in mozilla-source/mozilla/dist. Next, remove any previous versions of Mozilla and install the new Mozilla in /usr/local using:



     cd /usr/local 
     tar xzvf ~/mozilla-source/mozilla/dist/
         mozilla-i686-pc-linux-gnu.tar.gz 


You now can enjoy surfing the Net with great looking fonts--your eyes will be sure to thank you.

Jeff Sauer has been working with various technologies for over 17 years. After working for IBM, VeriSign and several successful startups, he now is providing corporate training and consulting services in the heart of Silicon Valley. He can be reached through his Web site, www.jouledata.com.

Load Disqus comments

Firstwave Cloud