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.
The X Logical Font Description ("XLFD") is the full name for a font. It consists of the following fields:
fndry
- font foundry, the company or individual which
made
the fontfmly
- font family, the popular nickname of the fontwght
- font weight (bold, medium, etc.)slant
- font slant (italics, oblique, roman (normal),
etc.)sWdth
- font width (normal, condensed, extended, etc.)adstyl
- additional style (sans serif, serif, etc.)pxlsz
- pixel size, the number of pixels vertically in a
characterptSz
- approximate point size of the text (similar to
pxlsz)resx
- horizontal resolution, in dpiresy
- vertical resolution, in dpispc
- spacing, only useful, apparently, in the
Schumacher fontsavgWidth
- average character width of the fontrgstry
- the recognized registry that lists the fontencdng
- nationality encodingIn 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 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.
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.
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 SunSite 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:
<colorspace-name>:<value>/.../<value>
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.