I Can See Clearly Now, the Fonts Are Smooth
January 20th, 2004 by Jeffery D. Sauer in
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.
Special Magazine Offer -- Free Gift with Subscription
Receive a free digital copy of Linux Journal's System Administration Special Edition as well as instant online access to current and past issues. CLICK HERE for offer
Linux Journal: delivering readers the advice and inspiration they need to get the most out of their Linux systems since 1994.
Subscribe now!
The Latest
Newsletter
Tech Tip Videos
- Nov-19-09
- Nov-04-09
Recently Popular
From the Magazine
December 2009, #188
If last month's Infrastrucuture issue was too "big" for you then try on this month's Embedded issue. Find out how to use Player for programming mobile robots, build a humidity controller for your root cellar, find out how to reduce the boot time of your embedded system, and if you're new to embedded systems find out the basics that go into one. You can also read about the Beagle Board, the Mesh Potato and a spate of other interestingly named items. And along with our regular columns don't miss our new monthly column: Economy Size Geek.
Delicious
Digg
StumbleUpon
Reddit
Facebook








Re: I Can See Clearly Now, the Fonts Are Smooth
On February 1st, 2004 Anonymous says:
What about monitor gamma issue ? There is no hardware XRender accelerators that perform pow(V0, gamma) after fetching values from frame buffer, do linear space composing ( V0 * A) + V1 * ( 1 - A) or similar, and return to precorrected gamma space pow(V, 1.0/gamma) before store result to frame buffer. I have seen Xft patches somewhere that do it correct way but it make rendering very slow. Seems that poison all modern project such as freedesktop.org X server that trying to make fast hardware accelerated transparent windows. I think that we must wait until true 16 bit or more per component video cards be common desktop devices.
Re: I Can See Clearly Now, the Fonts Are Smooth
On February 1st, 2004 Anonymous says:
tyhtgtwg
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 29th, 2004 Anonymous says:
Coding for the lowest common denominator is great but most
people who download the latest mozilla/firebird are going to
be using a modern distro and are going to have decent
hardware.
A 2400Mhz machine with 128mb graphics card and 512ram
is as cheap as chips these days.
I'd say there is a performance penalty of 0.1 % on a machine
like that.
Firebird/Moz should ship with it turned on by default.
If you use Gentoo or something wierd or just like to show
off you should be the one to go through dependancy hell
and recompile the mofo.
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
Why scare people away from Linux by posting such comlicated installation proceedures? Most dists already provide the packages with good antialiased fonts.
Tom
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 22nd, 2004 Anonymous says:
When you can type XFT and the app installs there will be no need for complicated instructions. Default fonts in Mozilla on RH9 are still lousy.
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
Linking Mozilla to gtk (the old one) and XFT will make pretty web pages, but the font rendering of the UI will be almost unreadable. If your building your own Mozilla, you need to explicitely link it to gtk2 library. For instructions on how to do this, as well as XFT enable other parts of Linux, see the more comprehensive howto at:
http://bglug.ca/articles/freetype_mozilla_openoffice_ttf_hinting.html
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
Speaking of fonts, what are these strange, bit 7ish characters that we're supposed to enter into .mozconfig?
ac_add_options --enable-optimize=
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
My guess would be they're supposed to be double-quote characters...
ac_add_options --enable-optimize="-O2 -march=i686"
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
I wonder why applications are not compiled with xft enabled as standard.
Does it impact heavily on performance if the app is used on low spec machines?
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
Adding xft support adds an extra library dependency. The distributed binaries from mozilla.org are supposed to run on almost any linux distribution, including those that don't have an X server with xft2 support.
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 29th, 2004 Anonymous says:
Coding for the lowest common denominator is great but most
people who download the latest mozilla/firebird are going to
be using a modern distro and are going to have decent
hardware.
A 2400Mhz machine with 128mb graphics card and 512ram
is as cheap as chips these days.
I'd say there is a performance penalty of 0.1 % on a machine
like that.
Firebird/Moz should ship with it turned on by default.
If you use Gentoo or something wierd or just like to show
off you should be the one to go through dependancy hell
and recompile the mofo.
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
The version of netscape that ships with RH-9 has xft enabled by default. Admittedly it is an older version, but, the fonts are nice.
It is easy to get a newer version with xft enabled as well. Just head on over to the fedora linux and grab their mozilla SRPM and recompile it. It built just fine on my RH-9 system. Now I have mozilla-1.6 with xft running happily on RH9, without much fuss at all.
(Probably, the precompiled binary would work as well. If it complains about library versions, then you're better off to recompile it so it matches the libs on RH9.)
Re: I Can See Clearly Now, the Fonts Are Smooth
On January 21st, 2004 Anonymous says:
It does appear to make the programs more resource intensive; of the various Mozilla/Firebird builds I have tried on low end Linux and Solaris workstations, the non-Xft-enabled builds use less memory and run faster than the Xft-enabled ones.
Post new comment