Next Previous Contents

7. Fonts and Colors

There are a lot of tricks to the fonts and colors used in X. They are not quite as simple as in some other systems, for instance, the font is not just a one-word name. You specify these resources quite explicitly, and it seems rather complex at first, but with a little explanation you'll be a whiz in no time.

7.1 Fonts Demystified

The X Logical Font Description (``XLFD'') is the full name for a font. It consists of the following fields:

In light of this chaos, the program xfontsel (the default X Window font selection program) will come in enormously useful to you. Try launching it right now. You will see a strange nothing helpful in the main window, but try holding the left button down on the fndry button. If all your fonts are in order, you will see a menu of selections such as adobe and b&h and bitstream and so forth. Select one such as b&h and you will notice that the font in the lower window changes to something intelligible. This is generally the way you will select fonts with this program, starting from the left, which is the most general selection, and moving toward the right, to the more specific options. Selecting an option toward the rightmost end will not make much sense before the foundry, for instance, is selected, because the options are generally ordered by their dependence on each other.

When you go to select from the fmly selection, you will see most of the options greyed out, and only three remaining. That means that these three are the only families of font made by this foundry. Some families appear under more than one foundry, for instance, both Adobe and Bitstream make a variation of the Courier font. Now you can select the wght, and so forth. After you get far enough you will have narrowed it down to the font that you want. You don't necessarily have to fill in all the options to choose a single font, there's not that many fonts on your system! The options that you do not select will be represented by a * indicating that any option will do in that spot.

When you are happy with your font selection, you can hit the select button, and your selection will be placed in the X clipboard, ready to be pasted into your document or whatever you are working on. For instance, go to your xterm window and type in something like xterm -font followed by an opening quotation mark. Then point to that spot on your screen, and click your middle mouse button (or click both the left and right, if you're middle-button impaired). This will paste the selection from the clipboard, which should be the font you just selected. Then enter the closing quote, and hit Enter. For instance, a nice big xterm with a Courier font specified would look like this: xterm -font "-adobe-courier-medium-r-*-*-14-*-*-*-*-*-*-*" A fresh xterm should the pop up using the font that you selected.

The utility xfd is very helpful for examining a font. If you launch it with a command line such as xfd -fn fixed, it will show you the character set for the font, much like the keycaps utility on a Macintosh. Note that you can also limit the number of fonts that you want xfontsel to display with the command line option -pattern, followed by a quoted font specification, as discussed above.

7.2 Font Aliases and Configuration

Sometimes it gets tiresome to remember all of the long font names, and very impractical too. Luckily, it is not necessary to type in a hundred keystrokes or so just to get the font name you want, for X provides something called font aliases.

If you look in the directory /usr/X11R6/lib/fonts/misc/fonts.alias, you will find shortcut names for many of the fonts. For example, 8x16 is listed as a shortcut for -sony-fixed-medium-r-normal--16-120-100-100-c-80-iso8859-1, and anywhere you enter 8x16 as an X font resource or at a command line for a font name, the long version of the font will be substituted. The 75dpi and 100dpi directories have similar aliases to take advantage of, on most systems the Lucida Sans font has a nice shortcut.

If you add fonts or aliases to your system, you will have to issue a few commands (probably as root). If you add fonts, you will have to issue the following two commands (these are examples, you will have to put in the correct directory, or perhaps leave it off altogether, to have your fonts re-read correctly.

 mkfontdir /usr/lib/X11/fonts/misc
 xset fp rehash

If you change the alias file for a font, you may only have to issue the last command above, but it may be a good idea to issue them both, to be sure. With the xset command you can explicitly issue a font path you wish the server to use, you can delete a specific directory from your font path, see the man page for more information.

Another common problem is that some distributions (notably Red Hat 5.2, at the moment) come with the fonts configured in the wrong order. If you take a look at your /etc/XF86Config (it may be somewhere else in some distributions, unfortunately, and I'm not sure where it is in Red Hat at the moment, so maybe locate it...) Take a look at this file if your fonts are ugly in X (as in, very difficult to read even at large sizes). You will see a bunch of entries that look something like this:

 FontPath   "/usr/X11R6/lib/X11/fonts/misc/"
 FontPath   "/usr/X11R6/lib/X11/fonts/75dpi/:unscaled"
 FontPath   "/usr/X11R6/lib/X11/fonts/100dpi/:unscaled"
 FontPath   "/usr/X11R6/lib/X11/fonts/Type1/"
 FontPath   "/usr/X11R6/lib/X11/fonts/Speedo/"

The important thing to note here is that we have the unscaled bitmapped fonts (the directories misc, 75dpi, 100dpi) before the scaled fonts (such as Type1 and Speedo). Bitmapped fonts are preferred for the X Server, because scaled fonts don't look very pretty for common use, they're better for things like The Gimp or Netscape, perhaps. You should also do a sanity check to see that these directories all do, in fact exist, and if you have modified any lately, you might need to (as root) go in and issue an mkfontdir * command in the fonts directory.

Note that if you are running a more recent distribution, such as one based on Red Hat 6.0 or later, you won't have to worry about this, as the xttfs True Type font server is the default, and does not use the path system to find your fonts.

7.3 Using Type 1 Fonts in X

The font types X generally accepts are of limited use, considering that about the only place you'll find fonts of that kind used are in the X Window System itself, and unfortunately most media junkies and fontaholics work in operating systems that prefer other formats. Type 1 fonts, most commonly used in conjunction with PostScript document formats, can be found for free on the internet with considerable ease. Try for starters.

To make use of these fonts is not that difficult, and graphics programs like GIMP will take advantage of them tremendously, and best of all, the Linux X servers understand Type 1 fonts ``out of the box.'' To use them, first unpack the archive using the appropriate commands, and put the fonts with a .pfb extension in /usr/X11R6/lib/X11/fonts/type1/ on your system. Then, add mention of those fonts in the fonts.scale file in that directory, using the format for the other fonts, already there. Then save the file.

Now, you should be able to mkfontdir to tell the X server about the updates, and then run xset fp rehash to re-read the font path. If this doesn't work for you, you might have to restart X to see the changes.

If you find yourself using Type 1 fonts a lot, and for things other than just X (GhostScript, for instance, can handle this font format as well), you'll want to check out the type1inst utility by James Macnicol. This program can configure Type 1 fonts for GhostScript and X, and it can also generate sample sheets for your fonts, and does most of the work of configuration for you. This program can usually be found at

7.4 Using TrueType Fonts in X

If you have been using an operating system such as Windows or the MacOS, you may have lots of fonts sitting on your computer already that are TrueType fonts. TrueType fonts are considered best on smaller, low-resolution displays, such as your computer monitor, and attempt to provide nice features like shading and antialiasing, making your display look smoother. It is also really easy to find cheap TrueType fonts in bulk, and CD's featuring upwards of 500 fonts in the TrueType format are common in computer stores.

X does not understand TrueType fonts, and has no innate capability (at present) to do so, and so it needs a separate program to do the font rendering for it. There is a FreeType library to do this, but if you just want to use them on your computer, all you will need is a program called xfstt, the X font server for TrueType. This program should be available at

Installation is fairly straightforward. Extract the archive, and make the file, and then make install. You may get a few errors that don't make sense after the second command; ignore them. What you need to do next is create a writable directory called /usr/ttfonts and put some of your .ttf fonts there, just to make sure it's going to work. Then synchronize the font server with the command xfstt --sync.

If you got no errors there, run the font server in the background with the command xfstt & and tell your X11 server about the font service with the command xset fp+ unix/:7100. If you got no errors, you should be able to run Netscape, the GIMP, even xfontsel, and have those fonts available to you. Your biggest problem may be finding the font you want, but that's not really a bad thing.

It has been brought to my attention that more recent versions of xset require a slightly modified version of this command, because of changes in the code of xset. If you are running a distribution based on Red Hat 6.0 or later, or something equivalent, you will first want to try xset fp+ unix/:7101.

If everything seems to be working fine, at this point you will want to configure your system so that the fonts will be working when you start X. If you are just starting X from the command line, this is easy. All you have to do is add the two commands from the previous paragraph to your .xinitrc file, in that order. When you next start X, it should work just fine. If you are starting X via xdm, you will need to add /usr/X11R6/bin/xfstt & to /usr/X11R6/lib/X11/xdm/Xsetup_0. Got that? Then add xset fp+ unix/:7100 as well.

Bear in mind that the installation of a TrueType font server can be tricky business. Remember that the order that you issue the above commands is important. The font server must be started before X is started, otherwise you will run into problems. Be sure to read the FAQ file that came with the distribution, and the xfstt man page too. Many newer Linux versions come with this already working, so see if that's not already the case before worrying too much about it.

7.5 Colors

Let's go back to our terminal window and try some more things. Try opening an xterm with a command line like the following:

 xterm -fg darkslateblue -bg red3 &

While that window may not be pretty, and you may not do much of your best work in it, it demonstrates one interesting theme of X, the names of the colors. While not very precise, this is a nice way to remember the colors more easily than remembering a series of hexadecimal numbers. Note that color names are never case-sensitive.

If you're interested in the gory details, or want to see the samples, or even want to replace those silly color names with your own for some strange reason, you can find the file listing all the colors with their hexadecimal representation in /usr/X11R6/lib/X11/rgb.txt on your system. There are also some extremely useful utilities with names like xcolorsel and such. They can be found in the usual locations, on and elsewhere.

A more precise way of specifying colors is through the numerical definition. This consists of a color space name and a set of values in the following syntax:


An RGB Device, which you will most likely be using, is specified with the prefix "rgb:" and has the following syntax:

rgb:<red>/<green>/<blue> , where <color> is a 1 to 4 digit hexadecimal number.

As an example, you might represent the color red with rgb:ffff/0/0. For backward compatibility, you can also specify red with a syntax such as #ff0000 or #ffff00000000, and you will likely be seeing that (older) syntax a lot.

Next Previous Contents