old-www/HOWTO/XWindow-User-HOWTO/fontscolors.html

1010 lines
18 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Fonts and Colors</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="The X Window User HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="More X Configuration"
HREF="moreconfig.html"><LINK
REL="NEXT"
TITLE="Window Managers and Desktops"
HREF="windowman.html"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The X Window User HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="moreconfig.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="windowman.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="fontscolors"
></A
>5. Fonts and Colors</H1
><P
>&#13; Understanding fonts and colors can be more complex in
<SPAN
CLASS="application"
>X</SPAN
> than on other platforms.
</P
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN867"
></A
>5.1. Fonts Demystified</H2
><P
>&#13; <SPAN
CLASS="application"
>X</SPAN
> knows about various font types, including
bitmaps, Type 1, and as of v4.x, TrueType. The X server can either handle
fonts itself, or sometimes this duty is forked to a font server (of which
there are several). <B
CLASS="command"
>xfs</B
> (X Font Server) is the most common
font server in use on Linux.
</P
><P
>&#13; A font server is not required, as <SPAN
CLASS="application"
>X</SPAN
> can handle
most font rendering itself. Font servers are traditionally used for serving
fonts to multiple hosts on a network, but sometimes are also used to provide
enhanced functionality. Additionally, a font server may provide a modest
performance boost by off-loading font rendering to a separate process.
</P
><P
>&#13; <SPAN
CLASS="application"
>X</SPAN
> knows about fonts according to fonts that are in
the <SPAN
CLASS="QUOTE"
>"FontPath"</SPAN
>. This is set initially in
<TT
CLASS="filename"
>XF86Config</TT
>. If the X server is handling font duties
itself (i.e. no font server), this will be a list of directories that contain
font files, like:
</P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
FontPath "/usr/X11R6/lib/X11/fonts/misc:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/100dpi:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/75dpi:unscaled"
FontPath "/usr/X11R6/lib/X11/fonts/Type1"
FontPath "/usr/X11R6/lib/X11/fonts/misc"
FontPath "/usr/X11R6/lib/X11/fonts/100dpi"
FontPath "/usr/X11R6/lib/X11/fonts/75dpi"
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; If a font server is being used, the <SPAN
CLASS="QUOTE"
>"FontPath"</SPAN
> will point to the
socket where the font server is serving (this is just one possible example):
</P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
FontPath "unix/:7101"
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; In this latter case, the actual font directories that are available will be
configured with the font server (see local documentation), which will use a
similar directory type scheme as shown for <TT
CLASS="filename"
>XF86Config</TT
>.
</P
><P
>&#13; Once suitable fonts have been installed, they must be
<SPAN
CLASS="QUOTE"
>"prepared"</SPAN
>. For most fonts, this means running the
<B
CLASS="command"
>mkfontdir</B
> utility (see man page) in the directory where
the fonts are (as root). Type 1 and TrueType require additional steps (see
below). Your vendor has done this for any fonts that were included with your
distribution. So, this will only need to be done for fonts that you add. For
newly added fonts to become visible to <SPAN
CLASS="application"
>X</SPAN
>,
you will need to run the appropriate
<B
CLASS="command"
>xset</B
> commands to either modify the existing FontPath, or
re-read it (see man page). Or, re-initialize your font server.
</P
><P
>&#13; Example: Preparing fonts, and re-initializing font server after adding new
fonts:
</P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
su
&#60;password&#62;
mkfontdir /usr/X11R6/lib/X11/fonts/my_new_fonts/
/etc/init.d/xfs restart
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; The first command may not be necessary on newer distros (since it's done by
the init script in some cases). And the font server configuration would need
to be modified, if this is a new directory. Example: re-initializing with no
font server:
</P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
su
&#60;password&#62;
mkfontdir /usr/X11R6/lib/X11/fonts/my_new_fonts/
xset +fp /usr/X11R6/lib/X11/fonts/my_new_fonts/
xset fp rehash
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; The <SPAN
CLASS="QUOTE"
>"<B
CLASS="command"
>xset +fp</B
>"</SPAN
> would not be necessary if the
directory is already part of the FontPath.
</P
><P
>&#13; <B
CLASS="command"
>xlsfonts | less</B
> can be used to list what fonts are known,
and thus available, to <SPAN
CLASS="application"
>X</SPAN
> and its clients. Run
<B
CLASS="command"
>xlsfonts | less</B
>, and you also can get an idea of the font
definition as understood by <SPAN
CLASS="application"
>X</SPAN
>. Font resources are
specified quite explicitly, and it may seem complex at first. The <EM
>X
Logical Font Description</EM
> (<SPAN
CLASS="QUOTE"
>"XLFD"</SPAN
>) is the full
description for any given font. The XLFD looks like:
</P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
-adobe-helvetica-medium-r-normal-*-*-120-*-*-p-*-iso10646-1
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; Where each field, left to right is:
</P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>fndry</TT
> - font foundry, the company or individual
which made the font.
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>fmly</TT
> - font family, the popular nickname of the font
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>wght</TT
> - font weight (bold, medium, etc.)
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>slant</TT
> - font slant (italics, oblique, roman
(normal), etc.)
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>sWdth</TT
> - font width (normal, condensed, extended, etc.)
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>adstyl</TT
> - additional style (sans serif, serif, etc.)
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>pxlsz</TT
> - pixel size, the number of pixels
vertically in a character
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>ptSz</TT
> - approximate point size of the text
(similar to pxlsz)
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>resx</TT
> - horizontal resolution, in dpi
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>resy</TT
> - vertical resolution, in dpi
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>spc</TT
> - spacing, only useful, apparently, in the
Schumacher fonts
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>avgWidth</TT
> - average character width of the font
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>rgstry</TT
> - the recognized registry that lists
the font
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13; <TT
CLASS="literal"
>encdng</TT
> - nationality encoding
</TD
></TR
></TBODY
></TABLE
><P
></P
><P
>&#13; The <SPAN
CLASS="QUOTE"
>"*"</SPAN
> acts as a wild-card character. In fact, if not every
field is specified, the X server will take the first match it finds in
the FontPath. This is why it is best to order the FontPath with preferred
fonts coming first since some programs will deliberately specify fonts
<SPAN
CLASS="QUOTE"
>"loosely"</SPAN
> so that your system has some discretion.
</P
><P
>&#13; The program <B
CLASS="command"
>xfontsel</B
> (<SPAN
CLASS="application"
>X</SPAN
>
Font Selector) may be useful. Try launching it now. You will see
nothing helpful in the main window at first, but try holding the left button
down on the <TT
CLASS="literal"
>fndry</TT
> button. If all your fonts are
in order, you will see a menu of selections such as <TT
CLASS="literal"
>adobe</TT
> and <TT
CLASS="literal"
>b&#38;h</TT
> and
<TT
CLASS="literal"
>bitstream</TT
> and so forth. Select one such as
<TT
CLASS="literal"
>b&#38;h</TT
> and you will notice that the font in
the lower window changes to something intelligible. This is the way
fonts are selected 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.
</P
><P
>&#13; When you select from the <TT
CLASS="literal"
>fmly</TT
> selection,
you will see most of the options grayed 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
<EM
>Adobe</EM
> and <EM
>Bitstream</EM
> make a
variation of the Courier font. Now you can select the <TT
CLASS="literal"
>wght</TT
>, 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
<EM
>that</EM
> many fonts on your system! The options that you do
not select will be represented by a <TT
CLASS="literal"
>*</TT
>
indicating that any option will do in that spot, and gives X some leeway.
</P
><P
>&#13; When you are satisfied with your font selection, hit the select button,
and your selection will be placed in the <SPAN
CLASS="application"
>X</SPAN
>
clipboard, ready to be pasted into your document or whatever you are working
on. For example, open an <EM
>xterm</EM
> window and
type in something like <TT
CLASS="literal"
>xterm -font </TT
> 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 are
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 <TT
CLASS="literal"
>Enter</TT
>. For instance, a nice big <EM
>xterm</EM
> with a Courier font specified would look like
this: <TT
CLASS="literal"
>xterm -font
"-adobe-courier-medium-r-*-*-14-*-*-*-*-*-*-*"</TT
>.
</P
><P
>&#13; If you've found a font you prefer, this can permanently be used by placing the
font definition in the appropriate configuration file (see above).
</P
><P
>&#13; Note that you can also limit the number of fonts that you want
<B
CLASS="command"
>xfontsel</B
> to display with the command line option
<EM
>-pattern</EM
>, followed by a quoted font specification, as
discussed above.
</P
><P
>&#13; The <B
CLASS="command"
>xfd</B
> utility is also helpful for examining
individual fonts. If launched with a command line such as <B
CLASS="command"
>xfd
-fn fixed</B
>, it will show you the complete character set for that font.
</P
><P
>&#13; <SPAN
CLASS="application"
>KDE</SPAN
> and <SPAN
CLASS="application"
>GNOME</SPAN
> have
their own utilities that are not quite as obtuse ;-)
</P
><DIV
CLASS="sect3"
><H3
CLASS="sect3"
><A
NAME="AEN987"
></A
>5.1.1. Type 1 and TrueType Fonts</H3
><P
>&#13; The fonts provided with XFree86 are of limited use for many of us,
considering that about the only place you'll find fonts of that kind, are
used in the X Window System itself for the most part. Unfortunately many
media junkies, web designers and fontaholics work in operating systems that
rely on other formats. And then, there often does not seem to be much
emphasis by some distributions on making the best of the default fonts
either.
</P
><P
>&#13; Type 1 fonts, most commonly used in conjunction with PostScript document
formats, are the traditional standard in Unix and Linux environments. You
should have a reasonably good starter selection installed already. Or, more
can be found for free on the Internet with considerable ease, and Try <A
HREF="ftp://ftp.cdrom.com/pub/os2/fonts/"
TARGET="_top"
>ftp://ftp.cdrom.com/pub/os2/fonts/</A
>
for starters. Type 1 are scalable fonts, and have many of the same benefits
of the better known TrueType fonts. If you don't have a good selection of
TrueType fonts installed, then Type 1 is what you want for most GUI
applications. But again, this is not standard on other platforms, and can
present problems when viewing documents (e.g. web pages) that are designed
with <SPAN
CLASS="QUOTE"
>"other platforms"</SPAN
> in mind.
</P
><P
>&#13; TrueType fonts started with Apple, and later were licensed by Microsoft. So
people migrating from non-Unix platforms are already familiar with these high
quality fonts. Unfortunately, there are not many quality TrueType fonts under
a suitable license, and thus there are not many included with Linux
distributions. And the ones that are, often are not as high quality. Also
unfortunately, TrueType has become somewhat of a standard on the Web and in
other venues, and not having good TrueType fonts can be a detriment.
XFree86 also seems to render TrueType a little better than Type1.
</P
><P
>&#13; That is the bad news. The good news is that any TrueType font included with
any version of Windows, or any Windows applications, should work on Linux.
Though you will have to take some additional steps to integrate them. This
particularly helps web browsing where <SPAN
CLASS="application"
>X's</SPAN
>
bitmapped fonts just don't scale well.
</P
><P
>&#13;
We shall not go into detail on installing and configuring these fonts here,
as it is addressed in depth in other documents. See
<A
HREF="http://tldp.org/HOWTO/Font-HOWTO.html"
TARGET="_top"
>The Font HOWTO</A
>
for general font information, and Type 1 tips.
See <I
CLASS="citetitle"
>The Font De-Uglification
Mini HOWTO</I
>,
<A
HREF="http://tldp.org/HOWTO/FDU/index.html"
TARGET="_top"
>The Font De-Uglification
Mini HOWTO</A
>,
for various <SPAN
CLASS="application"
>X</SPAN
> related font tips, especially TrueType.
</P
></DIV
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="AEN1001"
></A
>5.2. Colors</H2
><P
>&#13; Let's go back to our terminal window and try something. Open an
<B
CLASS="command"
>xterm</B
> with a command line like the following:
</P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
xterm -fg DarkSteelBlue1 -bg red3 &#38;
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; Ouch! While that may not be pretty, and you may not do much of your best work
in it, it demonstrates one interesting aspect of <SPAN
CLASS="application"
>X</SPAN
>
configuration -- color names. While not particularly precise, this is a nice
way to remember a variety of colors. Note that color names are never
case-sensitive.
</P
><P
>&#13; The X server will actually deal with color values as a hexadecimal
Red-Green-Blue (RGB) color notation. This would look something like
<SPAN
CLASS="QUOTE"
>"#0aff0a"</SPAN
> in hex. Not so easy to remember. But
<SPAN
CLASS="application"
>X</SPAN
> gives a more mnemonic way of remembering valid
color definitions. These are stored in a text table, typically as
<TT
CLASS="filename"
>/usr/X11R6/lib/X11/rgb.txt</TT
>, and is defined in
<TT
CLASS="filename"
>XF86Config</TT
> in the <SPAN
CLASS="QUOTE"
>"Files"</SPAN
> section.
</P
><P
>&#13; If you are interested, have a look with a text editor. There are many, many
shades defined. I count eighty-three shades of blue in mine, for instance. Brief
snip:
</P
><P
>&#13; <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;
176 226 255 LightSkyBlue1
164 211 238 LightSkyBlue2
141 182 205 LightSkyBlue3
96 123 139 LightSkyBlue4
202 225 255 LightSteelBlue1
188 210 238 LightSteelBlue2
162 181 205 LightSteelBlue3
110 123 139 LightSteelBlue4
191 239 255 LightBlue1
178 223 238 LightBlue2
154 192 205 LightBlue3
104 131 139 LightBlue4
</PRE
></FONT
></TD
></TR
></TABLE
>
</P
><P
>&#13; This file can be customized should you desire, but this is rarely needed for
most of us. It is important to have though, since some applications depend on
it.
</P
><P
>&#13; Desktop Environments will have a GUI utility for selecting colors.
</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="moreconfig.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="windowman.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>More X Configuration</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Window Managers and Desktops</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>