<!doctype LINUXDOC PUBLIC "-//XFree86//DTD linuxdoc//EN" [
<!ENTITY % defs SYSTEM "defs.ent"> %defs;
]>

<article>

<title>Fonts in XFree86
<author>Juliusz Chroboczek, <email/jch@xfree86.org/
<date>26 November 2001</date>

<ident>
$XFree86: xc/programs/Xserver/hw/xfree86/doc/sgml/fonts.sgml,v 1.15 2001/12/17 19:25:36 dawes Exp $
</ident>

<toc>

<sect>Introduction

<!-- I hate SGML.  What's wrong with texinfo? -->

<p>This document describes the support for fonts in XFree86.  Section
<ref id="sec:installing" name="Installing fonts"> is aimed at the
casual user wishing to install fonts in the X server; the rest of the
document describes the font support in more detail.

We only describe font support within the core X protocol.  Issues
relating to fonts within the RENDER extension, the GLX (OpenGL)
extension or the PEX extension are outside the scope of this document.

We assume some familiarity with digital fonts.  If anything is not
clear to you, please consult Appendix <ref id="sec:background"
name="Background"> at the end of this document for background
information.

<sect>Installing fonts <label id="sec:installing">

<p>Installing fonts in XFree86 is a two step process.  First, you need
to create a <it/font directory/ that contains all the relevant font
files as well as some index files.  You then need to inform the X
server of the existence of this new directory by including it in the
<it/font path/.

<sect1>Installing bitmap fonts

<p>The XFree86 server can use bitmap fonts in both the cross-platform
BDF format and the somewhat more efficient binary PCF format.
(XFree86 also supports the obsolete SNF format.)

Bitmap fonts are normally distributed in the BDF format.  Before
installing such fonts, it is desirable (but not absolutely necessary)
to convert the font files to the PCF format.  This is done by using the
command `<tt/bdftopcf/', <it/e.g./ 
<tscreen><verb>
$ bdftopcf courier12.bdf
</verb></tscreen>
You may then want to compress the resulting PCF font files:
<tscreen><verb>
$ gzip courier12.pcf
</verb></tscreen>

After the fonts have been converted, you should copy all the font
files that you wish to make available into a arbitrary directory, say
`<tt>/usr/local/share/fonts/bitmap/</tt>'.  You should then create the
index file `<tt/fonts.dir/' by running the command `<tt/mkfontdir/'
(please see the <tt/mkfontdir/(1) manual page for more information):
<tscreen><verb>
$ mkdir /usr/local/share/fonts/bitmap 
$ cp *.pcf.gz /usr/local/share/fonts/bitmap
$ cd /usr/local/share/fonts/bitmap 
$ mkfontdir 
</verb></tscreen>

All that remains is to tell the X server about the existence of the
new font directory; see Section <ref id="sec:set-font-path"
name="Setting the server font path">.

<sect1>Installing scalable fonts

<p>The XFree86 server supports scalable fonts in four formats:
Type&nbsp;1, Speedo, TrueType and CIDFont.  This section only applies
to the former three; for information on CIDFonts, please see Section
<ref id="sec:cid-fonts" name="Installing CIDFonts"> later in this
document.

Installing scalable fonts is very similar to installing bitmap fonts:
you create a directory with the font files, and run `<tt/mkfontdir/'
to create an index file called `<tt/fonts.dir/'.

There is, however, a big difference: `<tt/mkfontdir/' cannot
automatically recognise scalable font files.  For that reason, you
must first index all the font files in a file called
`<tt/fonts.scale/'.  This file has the same format as a
`<tt/fonts.dir/' file, and typically looks as follows: 
<tscreen><verb>
4
cour.pfa -adobe-courier-medium-r-normal-0-0-0-0-p-0-iso8859-1
cour.pfa -adobe-courier-medium-r-normal-0-0-0-0-p-0-iso8859-2
couri.pfa -adobe-courier-medium-i-normal-0-0-0-0-p-0-iso8859-1
couri.pfa -adobe-courier-medium-i-normal-0-0-0-0-p-0-iso8859-2 
</verb></tscreen>
The first line indicates the number of entries in the file.
Each line after the first consists of two fields separated by a space;
the first field is the name of the font file, and the second one is
the name under which the font will appear to the server.  This name
should obey the X Logical Font Description conventions (see Section
<ref id="sec:xlfd" name="The X Logical Font Description">).  The
format of this file is fully described in the <tt/mkfontdir/(1) manual
page.

Note that multiple lines may point at the same font file.  This is
most commonly done in order to make a single font available under
multiple encodings; please see Section 
<ref id="sec:internationalisation" name="Fonts and internationalisation">.

While it is possible to create the `<tt/fonts.scale/' file by hand, it
is simpler and more convenient to have it generated automatically.
Utilities to perform this task are available, but are not currently
included with XFree86. For Type&nbsp;1 fonts, you may use a utility
called `<tt/type1inst/' which is available from
<url url="http://www.ibiblio.org/pub/Linux/X11/xutils/" name="standard
Free Software repositories"> throughout the world.

For TrueType fonts, you may use `<tt/ttmkfdir/', available from
<url name="Joerg Pommnitz's xfsft page"
     url="http://www.joerg-pommnitz.de/TrueType/xfsft.html">.

After the `<tt/fonts.scale/' is created, you may run `<tt/mkfontdir/' as
above; this time, however, you need to create an index of encoding
files called `<tt>encodings.dir</tt>' in addition to the
`<tt>fonts.dir</tt>' file.  This is done by using `<tt/mkfontdir/' with
the `<tt/-e/' flag:
<tscreen><verb>
$ cd /usr/local/share/fonts/Type1
$ mkfontdir -e /usr/X11R6/lib/font/encodings
</verb></tscreen>
For more information, please see the <tt/mkfontdir/(1) manual page and
Section <ref id="sec:internationalisation" name="Fonts and
internationalisation"> later in this document.

<sect1>Installing CID-keyed fonts <label id="sec:cid-fonts">

<p>The CID-keyed font format was designed by Adobe Systems for fonts
with large character sets.  A CID-keyed font, or CIDFont for short,
contains a collection of glyphs indexed by <it/character ID/ (CID).

Adobe make some sample CIDFonts and a complete set of CMaps
available from 
<url name="O'Reilly's FTP site"
     url="ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/">.

In order to map such glyphs to meaningful indices, Adobe provide a set
of <it/CMap/ files.  The PostScript name of a font generated from a
CIDFont consists of the name of the CIDFont and the name of the CMap
separated by two dashes.  For example, the font generated from the
CIDFont `<tt/Munhwa-Regular/' using the CMap `<tt/UniKS-UCS2-H/' is
called
<tscreen><verb>
Munhwa-Regular--UniKS-UCS2-H
</verb></tscreen>

The CIDFont support in XFree86 requires a very rigid directory
structure.  The main directory must be called `<tt/CID/' (its location
defaults to `<tt>/usr/X11R6/lib/X11/fonts/CID</tt>' but it may be
located anywhere), and it should contain a subdirectory for every CID
collection.  Every subdirectory <it/must/ contain subdirectories
called <tt/CIDFont/ (containing the actual CIDFont files), <tt/CMap/
(containing all the needed CMaps), <tt/AFM/ (containing the font
metric files) and <tt/CFM/ (initially empty).  For example, in the
case of the font <tt/Munhwa-Regular/ that uses the CID collection
<tt/Adobe-Korea1-0/, the directory structure should be as follows:
<tscreen><verb>
CID/Adobe-Korea1/CIDFont/Munhwa-Regular
CID/Adobe-Korea1/CMap/UniKS-UCS2-H
CID/Adobe-Korea1/AFM/Munhwa-Regular.afm
CID/Adobe-Korea1/CFM/
CID/fonts.dir
CID/fonts.scale
</verb></tscreen>

After creating this directory structure and copying the relevant
files, you should create a <`tt/fonts.scale/' file.  This file has the
same format as in the case of (non-CID) scalable fonts, except that
its first column contains PostScript font names with the extension
`<tt/.cid/' appended rather than actual filenames:
<tscreen><verb>
1
Adobe-Korea1/Munhwa-Regular--UniKS-UCS2-H.cid \
  -adobe-munhwa-medium-r-normal--0-0-0-0-p-0-iso10646-1
</verb></tscreen>
(both names on the same line).  As above, running `<tt/mkfontdir/'
creates the `<tt/fonts.dir/' file:
<tscreen><verb>
$ cd /usr/local/share/fonts/CID
$ mkfontdir
</verb></tscreen>

Finally, you should create the font metrics summary files in the
directory `<tt/CFM/' by running the command `<tt/mkcfm/':
<tscreen><verb>
$ mkcfm /usr/local/share/fonts/CID
</verb></tscreen>
If no CFM files are available, the server will still be able to use
the CID fonts but querying them will take a long time.  You should run
`<tt/mkcfm/' again whenever a change is made to any of the CID-keyed
fonts, or when the CID-keyed fonts are copied to a machine with a
different architecture.

<sect1>Setting the server's font path <label id="sec:set-font-path">

<p>The list of directories where the server looks for fonts is known
as the <it/font path/.  Informing the server of the existence of a new
font directory consists in putting it on the font path.

The font path is an ordered list; if a client's request matches
multiple fonts, the first one in the font path is the one that gets
used.  When matching fonts, the server makes two passes over the font
path: during the first pass, it searches for an exact match; during
the second, it searches for fonts suitable for scaling.

For best results, scalable fonts should appear in the font path before
the bitmap fonts; this way, the server will prefer bitmap fonts to
scalable fonts when an exact match is possible, but will avoid scaling
bitmap fonts when a scalable font can be used.  (The `<tt/:unscaled/'
hack, while still supported, should no longer be necessary in XFree86
4.0 and later.)

You may check the font path of the running server by typing the command
<tscreen><verb>
$ xset q
</verb></tscreen>

<sect2>Temporary modification of the font path

<p>The `<tt/xset/' utility may be used to modify the font path for the
current session.  The font path is set with the command <tt/xset fp/;
a new element is added to the front with <tt/xset +fp/, and added to
the end with <tt/xset fp+/.  For example,
<tscreen><verb>
$ xset +fp /usr/local/fonts/Type1
$ xset fp+ /usr/local/fonts/bitmap
</verb></tscreen>

Conversely, an element may be removed from the front of the font path
with `<tt/xset -fp/', and removed from the end with `<tt/xset fp-/'.

For more information, please consult the <tt/xset/(1) manual page.

<sect2>Permanent modification of the font path

<p>The default font path (the one used just after server startup) is
specified in the X server's `<tt/XF86Config/' file.  It is computed by
appending all the directories mentioned in the `<tt/FontPath/' entries
of the `<tt/Files/' section in the order in which they appear.
<tscreen><verb>
FontPath "/usr/local/fonts/Type1"
...
FontPath "/usr/local/fonts/bitmap"
</verb></tscreen>

For more information, please consult the `<tt/XF86Config/'(5) manual
page.

<sect1>Troubleshooting <label id="sec:troubleshooting">

<p>If you seem to be unable to use some of the fonts you have
installed, the first thing to check is that the `<tt/fonts.dir/' files
are correct and that they are readable by the server.  If this doesn't
help, it is quite possible that you are trying to use a font in a
format that is not supported by your server.

XFree86 supports the BDF, PCF, SNF, Type 1, Speedo, TrueType and
CIDFont font formats.  However, not all XFree86 servers come with all
the font backends configured in.

On most platforms, the XFree86 servers are <it/modular/: the font
backends are included in modules that are loaded at runtime.  The
modules to be loaded are specified in the `<tt/XF86Config/' file using
the `<tt/Load/' directive:
<tscreen><verb>
Load "type1"
</verb></tscreen>
If you have trouble installing fonts in a specific format, you may
want to check the server's log file in order to see whether the
relevant modules are properly loaded.  The list of font modules
distributed with XFree86 is as follows:
<itemize>
<item> <tt/"bitmap"/: bitmap fonts (`<tt/*.bdf/', `<tt/*.pcf/'
and `<tt/*.snf/');
<item> <tt/"type1"/: Type&nbsp;1 fonts (`<tt/*.pfa/' and
`<tt/*.pfb/') and CIDFonts;
<item> <tt/"speedo"/: Bitstream Speedo fonts (`<tt/*.spd/');
<item> <tt/"freetype"/: TrueType fonts (`<tt/*.ttf/' and `<tt/*.ttc/');
<item> <tt/"xtt"/: alternate TrueType backend (`<tt/*.ttf/' and
`<tt/*.ttc/').
</itemize>
Please note that the argument of the `<tt/Load/' directive is
case-sensitive.

<sect>Fonts included with XFree86

<sect1>Standard bitmap fonts

<p>The Sample Implementation of X11 comes with a large number of
bitmap fonts, including the `<tt/fixed/' family, and bitmap versions
of Courier, Times and Helvetica.  In the SI, these fonts are provided
in the ISO&nbsp;8859-1 encoding (ISO Latin Western-European).

In XFree86, a number of these fonts are provided in Unicode-encoded
font files instead.  At build time, these fonts are split into font
files encoded according to legacy encodings, a process which enables
us to provide the standard fonts in a number of regional encodings
with no duplication of work.

For example, the font file
<tscreen><verb>
/usr/X11R6/lib/X11/fonts/misc/6x13.bdf
</verb></tscreen>
with XLFD
<tscreen><verb>
-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1
</verb></tscreen>
is a Unicode-encoded version of the standard `<tt/fixed/' font with
added support for the Latin, Greek, Cyrillic, Georgian, Armenian, IPA
and other scripts plus numerous technical symbols. It contains over
2800 glyphs, covering all characters of ISO&nbsp;8859 parts 1-5,
7-10, 13-15, as well as all European IBM and Microsoft code pages,
KOI8, WGL4, and the repertoires of many other character sets.

This font is used at build time for generating the font files
<tscreen><verb>
6x13-ISO8859-1.bdf
6x13-ISO8859-2.bdf
6x13-ISO8859-3.bdf
6x13-ISO8859-4.bdf
6x13-ISO8859-5.bdf
6x13-ISO8859-7.bdf
6x13-ISO8859-8.bdf
6x13-ISO8859-9.bdf
6x13-ISO8859-10.bdf
6x13-ISO8859-13.bdf
6x13-ISO8859-15.bdf
6x13-KOI8-R.bdf
</verb></tscreen>
with respective XLFDs
<tscreen><verb>
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-1
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-2
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-3
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-4
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-5
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-7
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-8
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-9
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-10
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-13
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-15
-misc-fixed-medium-r-normal--13-120-75-75-c-60-koi8-r
</verb></tscreen>
The standard short name `<tt/fixed/' is normally an alias for
<tscreen><verb>
-misc-fixed-medium-r-normal--13-120-75-75-c-60-iso8859-1
</verb></tscreen>

(The conversion of the standard fonts to Unicode was mainly performed
by Markus Kuhn.  Markus is a man of taste, which makes his use of Perl
in the conversion process somewhat surprising.)

<sect1>The ClearlyU Unicode font family

<p>The ClearlyU family of fonts provides a set of 12&nbsp;pt,
100&nbsp;dpi proportional fonts with many of the glyphs needed for
Unicode text.  Together, the fonts contain approximately 7500 glyphs.

The main ClearlyU font has the XLFD
<tscreen><verb>
-mutt-clearlyu-medium-r-normal--17-120-100-100-p-101-iso10646-1 
</verb></tscreen>
and resides in the font file
<tscreen><verb>
/usr/X11R6/lib/X11/fonts/misc/cu12.pcf.gz 
</verb></tscreen>
Additional ClearlyU fonts include
<tscreen><verb>
-mutt-clearlyu alternate glyphs-medium-r-normal--17-120-100-100-p-91-iso10646-1 
-mutt-clearlyu pua-medium-r-normal--17-120-100-100-p-111-iso10646-1
-mutt-clearlyu arabic extra-medium-r-normal--17-120-100-100-p-103-fontspecific-0
-mutt-clearlyu ligature-medium-r-normal--17-120-100-100-p-141-fontspecific-0
</verb></tscreen>

The <it/Alternate Glyphs/ font contains additional glyph shapes that
are needed for certain languages.  A second alternate glyph font will
be provided later for cases where a character has more than one
commonly used alternate shape (<it/e.g./ the Urdu heh).

The <it/PUA/ font contains extra glyphs that are useful for certain
rendering purposes.

The <it/Arabic Extra/ font contains the glyphs necessary for
characters that don't have all of their possible shapes encoded in
ISO&nbsp;10646.  The glyphs are roughly ordered according to the order
of the characters in the ISO&nbsp;10646 standard.

The <it/Ligature/ font contains ligatures for various scripts that
may be useful for improved presentation of text.

(The ClearlyU family was designed by Mark Leisher.  Mark's usage of
the foundry name <it/mutt/ predates the mailer of the same name, but
he won't say more.)

<sect1>Standard scalable fonts

<p>XFree86 includes all the scalable fonts distributed with X11R6.

<sect2>Standard Type&nbsp;1 fonts

<p>The IBM Courier set of fonts cover ISO&nbsp;8859-1 and
ISO&nbsp;8859-2 as well as Adobe Standard Encoding.  These fonts have
XLFD
<tscreen><verb>
-adobe-courier-medium-*-*--0-0-0-0-m-0-*-*
</verb></tscreen>
and reside in the font files
<tscreen><verb>
/usr/X11R6/lib/X11/fonts/Type1/cour*.pfa
</verb></tscreen>

The Adobe Utopia set of fonts only cover ISO&nbsp;8859-1 as well as
Adobe Standard Encoding.  These fonts have XLFD
<tscreen><verb>
-adobe-utopia-*-*-normal--0-0-0-0-p-0-iso8859-1
</verb></tscreen>
and reside in the font files
<tscreen><verb>
/usr/X11R6/lib/X11/fonts/Type1/UT*.pfa
</verb></tscreen>

Finally, XFree86 also comes with Type&nbsp;1 versions of Bitstream
Courier and Charter.  These fonts have XLFD
<tscreen><verb>
-bitstream-courier-*-*-normal--0-0-0-0-m-0-iso8859-1
-bitstream-charter-*-*-normal--0-0-0-0-p-0-iso8859-1
</verb></tscreen>
and reside in the font files
<tscreen><verb>
/usr/X11R6/lib/X11/fonts/Type1/c*bt_.pfb
</verb></tscreen>

<sect2>Standard Speedo fonts

<p>XFree86 includes Speedo versions of the Bitstream Courier and
Charter fonts.  In order to use these fonts, you should ensure that
your X server is loading the `<tt/Speedo/' font backend; see Section
<ref id="sec:troubleshooting" name="Troubleshooting">.

These fonts cover all of ISO&nbsp;8859-1 and almost all of
ISO&nbsp;8859-2.  They have XLFD name
<tscreen><verb>
-bitstream-courier-*-*-normal--0-0-0-0-m-0-*-*
-bitstream-charter-*-*-normal--0-0-0-0-p-0-*-*
</verb></tscreen>
and reside in the font files
<tscreen><verb>
/usr/X11R6/lib/X11/fonts/Speedo/font*.spd
</verb></tscreen>

<sect1>The Bigelow &amp; Holmes Luxi family

<p>XFree86 includes the <it/Luxi/ family of scalable fonts, in both
TrueType and Type&nbsp;1 format.  This family consists of the fonts
<it/Luxi Serif/, with XLFD
<tscreen><verb>
-b&amp;h-luxi serif-medium-*-normal--*-*-*-*-p-*-*-*
</verb></tscreen>
<it/Luxi Sans/, with XLFD
<tscreen><verb>
-b&amp;h-luxi sans-medium-*-normal--*-*-*-*-p-*-*-*
</verb></tscreen>
and <it/Luxi Mono/, with XLFD
<tscreen><verb>
-b&amp;h-luxi mono-medium-*-normal--*-*-*-*-m-*-*-*
</verb></tscreen>
Each of these fonts comes Roman, oblique, bold and bold oblique variants
The TrueType version have glyphs covering the basic ASCII Unicode
range, the Latin&nbsp;1 range, as well as the <it/Extended Latin/
range and some additional punctuation characters.  In particular,
these fonts include all the glyphs needed for ISO&nbsp;8859 parts 1,
2, 3, 4, 9, 13 and 15, as well as all the glyphs in the Adobe Standard
encoding and the Windows 3.1  character set.

The glyph coverage of the Type&nbsp;1 versions is somewhat reduced,
and only covers ISO&nbsp;8859 parts 1, 2 and 15 as well as the Adobe
Standard encoding.

The Luxi fonts are original designs by Kris Holmes and Charles 
Bigelow. Luxi fonts include seriffed, sans serif, and monospaced 
styles, in roman and oblique, and normal and bold weights. The fonts 
share stem weight, x-height, capital height, ascent and descent, for 
graphical harmony.

The character width metrics of Luxi roman and bold fonts match those 
of core fonts bundled with popular operating and window systems.

The license terms for the Luxi fonts are included in the file
`<tt/COPYRIGHT.BH/', as well as in the <htmlurl
name="License document" url="LICENSE.html">.

Charles Bigelow and Kris Holmes from Bigelow and Holmes Inc. 
developed the Luxi typeface designs in Ikarus digital format.

URW++ Design and Development GmbH converted the Ikarus format fonts 
to TrueType and Type1 font programs and implemented the grid-fitting 
"hints" and kerning tables in the Luxi fonts.

For more information, please contact
<email>design@bigelowandholmes.com</email> or 
<email>info@urwpp.de</email>, or consult 
<url name="the URW++ web site" url="http://www.urwpp.de">.

An earlier version of the Luxi fonts was made available under the
name <em/Lucidux/.  This name should no longer be used due to trademark
uncertainties, and all traces of the <em/Lucidux/ name have been
removed from this version of XFree86.

<sect>Fonts and internationalisation <label id="sec:internationalisation">

<p>The scalable font backends (Type&nbsp;1, Speedo and TrueType) can
now automatically re-encode fonts to the encoding specified in the
XLFD in <tt/fonts.dir/.  For example, a <tt/fonts.dir/ file can
contain entries for the Type&nbsp;1 Courier font such as
<tscreen><verb>
cour.pfa -adobe-courier-medium-r-normal--0-0-0-0-m-0-iso8859-1 
cour.pfa -adobe-courier-medium-r-normal--0-0-0-0-m-0-iso8859-2
</verb></tscreen>
which will lead to the font being recoded to ISO&nbsp;8859-1 and
ISO&nbsp;8859-2 respectively.

<sect1>The <it/fontenc/ layer <label id="sec:fontenc">

<p>Three of the scalable backends (Type&nbsp;1, Speedo, and the
<it/FreeType/ TrueType backend) use a common <it/fontenc/ layer for
font re-encoding.  This allows these backends to share their encoding
data, and allows simple configuration of new locales independently of
font type.

<it/Please note:/ the X-TrueType (X-TT) backend does not use the
<it/fontenc/ layer, but instead uses its own method for font
reencoding.  If you are only interested in X-TT you may want to skip
to Section <ref id="sec:symbol-fonts" name="Using Symbol Fonts">, as
the intervening information does not apply to X-TT.  X-TT itself is
described in more detail in Section <ref id="sec:X-TT"
name="X-TrueType">.

In the <it/fontenc/ layer, an encoding is defined by a name (such as
<tt/iso8859-1/), possibly a number of aliases (alternate names), and
an ordered collection of mappings.  A mapping defines the way the
encoding can be mapped into one of the <it/target encodings/ known to
<it/fontenc/; currently, these consist of Unicode, Adobe glyph names,
and arbitrary TrueType ``cmap''s.

A number of encodings are hardwired into <it/fontenc/, and are
therefore always available; the hardcoded encodings cannot easily be
redefined.  These include:
<itemize>
<item> <tt/iso10646-1/: Unicode;
<item> <tt/iso8859-1/: ISO&nbsp;Latin-1 (Western Europe);
<item> <tt/iso8859-2/: ISO&nbsp;Latin-2 (Eastern Europe);
<item> <tt/iso8859-3/: ISO&nbsp;Latin-3 (Southern Europe);
<item> <tt/iso8859-4/: ISO&nbsp;Latin-4 (Northern Europe);
<item> <tt/iso8859-5/: ISO&nbsp;Cyrillic;
<item> <tt/iso8859-6/: ISO&nbsp;Arabic;
<item> <tt/iso8859-7/: ISO&nbsp;Greek;
<item> <tt/iso8859-8/: ISO&nbsp;Hebrew;
<item> <tt/iso8859-9/: ISO&nbsp;Latin-5 (Turkish);
<item> <tt/iso8859-10/: ISO&nbsp;Latin-6 (Nordic);
<item> <tt/iso8859-15/: ISO&nbsp;Latin-9, or Latin-0 (Revised
  Western-European);
<item> <tt/koi8-r/: KOI8 Russian;
<item> <tt/koi8-u/: KOI8 Ukrainian (see RFC 2319);
<item> <tt/koi8-ru/: KOI8 Russian/Ukrainian
<item> <tt/koi8-uni/: KOI8 ``Unified'' (Russian, Ukrainian, and
  Byelorussian);
<item> <tt/koi8-e/: KOI8 ``European,'' ISO-IR-111, or ECMA-Cyrillic;
<item> <tt/microsoft-symbol/ and <tt/apple-roman/: these are only
  likely to be useful with TrueType symbol fonts.
</itemize>

Additional encodings can be added by defining <it/encoding files/.
When a font encoding is requested that the <it/fontenc/ layer doesn't
know about, the backend checks the directory in which the font file
resides (not necessarily the directory with <tt/fonts.dir/!) for a
file named `<tt/encodings.dir/'.  If found, this file is scanned for
the requested encoding, and the relevant encoding definition file is
read in.  The `<tt/mkfontdir/' utility, when invoked with the
`<tt/-e/' option followed by the name of a directory containing
encoding files, can be used to automatically build
`<tt/encodings.dir/' files.  See the <tt/mkfontdir/(1) manual page for
more details.

A number of encoding files for common encodings are included with
XFree86.  Information on writing new encoding files can be found in
Section <ref id="sec:format-encoding-directory-files" name="Format of
encodings directory files"> and <ref id="sec:format-encoding-files"
name="Format of encoding files"> later in this document.

<sect1>Backend-specific notes about fontenc

<sect2>Type&nbsp;1

<p>The Type&nbsp;1 backend first searches for a mapping with a target
of PostScript.  If one is found, it is used.  Otherwise, the
backend searches for a mapping with target Unicode, which is then
composed with a built-in table mapping codes to glyph names.  Note
that this table only covers part of the Unicode code points that have
been assigned names by Adobe.

If neither a PostScript or Unicode mapping is found, the backend
defaults to ISO&nbsp;8859-1.

Specifying an encoding value of <tt/adobe-fontspecific/ disables
the encoding mechanism.  This is useful with symbol and incorrectly
encoded fonts (see Section 
<ref id="sec:incorrect-encoding" name="Incorrectly encoded fonts">
below).

The Type&nbsp;1 backend currently limits all encodings to 8-bit codes.

<sect2>Speedo

<p>The Speedo backend searches for a mapping with a target of Unicode,
and uses it if found.  If none is found, the backend defaults to
ISO&nbsp;8859-1.

The Speedo backend limits all encodings to 8-bit codes.

<sect2>The <it/FreeType/ TrueType backend <label id="sec:fontenc-freetype"

<p>The TrueType backend scans the mappings in order.  Mappings with a
target of PostScript are ignored; mappings with a TrueType or Unicode
target are checked against all the cmaps in the file.  The first
applicable mapping is used.

If you are writing an encoding file to be used with the TrueType
backend, you should ensure that mappings are mentioned in decreasing
order of preference.

<sect1>Format of encoding directory files <label id="sec:format-encoding-directory-files">

<p>In order to use a font in an encoding that the font backend does
not know about, you need to have an `<tt/encodings.dir/' file in the
same directory as the font file used.  The `<tt/encodings.dir/' file
has a similar format to `<tt/fonts.dir/'.  Its first line specifies
the number of encodings, while every successive line has two columns,
the name of the encoding, and the name of the encoding file; this can
be relative to the current directory, or absolute.  Every encoding
name should agree with the encoding name defined in the encoding file.
For example,

<tscreen><verb>
3
mulearabic-0 /usr/X11R6/lib/X11/fonts/encodings/mulearabic-0.enc
mulearabic-1 /usr/X11R6/lib/X11/fonts/encodings/mulearabic-1.enc
mulearabic-2 /usr/X11R6/lib/X11/fonts/encodings/mulearabic-2.enc
</verb></tscreen>

The name of an encoding <it/must/ be specified in the encoding file's
`<tt/STARTENCODING/' or `<tt/ALIAS/' line.  It is not enough to create
an `<tt/encodings.dir/' entry.

If your platform supports it (it probably does), encoding files may be
compressed or gzipped.

The `<tt/encoding.dir/' files are best maintained by the
`<tt/mkfontdir/' utility.  Please see the <tt/mkfontdir/(1) manual
page for more information.

<sect1>Format of encoding files <label id="sec:format-encoding-files">

<p>The encoding files are ``free form,'' <it/i.e./ any string of
whitespace is equivalent to a single space.  Keywords are parsed in a
non-case-sensitive manner, meaning that `<tt/size/', `<tt/SIZE/', and
`<tt/SiZE/' all parse as the same keyword; on the other hand, case is
significant in glyph names.

Numbers can be written in decimal, as in `<tt/256/', in hexadecimal,
as in `<tt/0x100/', or in octal, as in `<tt/0400/'.

Comments are introduced by a hash sign `<tt/#/'.  A `<tt/#/' may
appear at any point in a line, and all characters following the
`<tt/#/' are ignored, up to the end of the line.

The encoding file starts with the definition of the name of the
encoding, and possibly its alternate names (aliases):
<tscreen><verb>
STARTENCODING mulearabic-0
ALIAS arabic-0
ALIAS something-else
</verb></tscreen>
The name of the encoding and its aliases should be suitable for use in
an XLFD font name, and therefore contain exactly one dash `<tt/-/'.

The encoding file may then optionally declare the size of the
encoding.  For a linear encoding (such as ISO&nbsp;8859-1), the SIZE
line specifies the maximum code plus one:
<tscreen><verb>
SIZE 0x2B
</verb></tscreen>
For a matrix encoding, it should specify two numbers.  The first is
the number of the last row plus one, the other, the highest column
number plus one.  In the case of `<tt/jisx0208.1990-0/'
(JIS&nbsp;X&nbsp;0208(1990), double-byte encoding, high bit clear), it
should be
<tscreen><verb>
SIZE 0x75 0x80
</verb></tscreen>
In the case of a matrix encoding, a `<tt/FIRSTINDEX/' line may be
included to specify the minimum glyph index in an encoding.  The
keyword `<tt/FIRSTINDEX/' is followed by two integers, the minimum row
number followed by the minimum column number:
<tscreen><verb>
FIRSTINDEX 0x20 0x20
</verb></tscreen>
In the case of a linear encoding, a `<tt/FIRSTINDEX/' line is not very
useful.  If for some reason however you chose to include on, it should
be followed by a single integer.

Note that in most font backends inclusion of a `<tt/FIRSTINDEX/' line
has the side effect of disabling default glyph generation, and this
keyword should therefore be avoided unless absolutely necessary.

Codes outside the region defined by the `<tt/SIZE/' and
`<tt/FIRSTINDEX/' lines are understood to be undefined.  Encodings
default to linear encoding with a size of 256 (0x100).  This means
that you must declare the size of all 16 bit encodings.

What follows is one or more mapping sections.  A mapping section
starts with a `<tt/STARTMAPPING/' line stating the target of the mapping.
The target may be one of:
<itemize>
<item>Unicode (ISO&nbsp;10646):
<tscreen><verb>
STARTMAPPING unicode
</verb></tscreen>
<item>a given TrueType ``cmap'':
<tscreen><verb>
STARTMAPPING cmap 3 1
</verb></tscreen>
<item>PostScript glyph names:
<tscreen><verb>
STARTMAPPING postscript
</verb></tscreen>
</itemize>
Every line in a mapping section maps one from the encoding being
defined to the target of the mapping.  In mappings with a Unicode or
TrueType mapping, codes are mapped to codes:
<tscreen><verb>
0x21 0x0660
0x22 0x0661
...
</verb></tscreen>
As an abbreviation, it is possible to map a contiguous range of codes
in a single line.  A line consisting of three integers
<tscreen><verb>
<it/start/ <it/end/ <it/target/
</verb></tscreen>
is an abbreviation for the range of lines
<tscreen>
<it/start/     <it/target/
</tscreen><tscreen>
<it/start/+1   <it/target/+1
</tscreen><tscreen>
...
</tscreen><tscreen>
<it/end/       <it/target/+<it/end/-<it/start/
</tscreen>
For example, the line
<tscreen><verb>
0x2121 0x215F 0x8140
</verb></tscreen>
is an abbreviation for
<tscreen><verb>
0x2121 0x8140
0x2122 0x8141
...
0x215F 0x817E
</verb></tscreen>
Codes not listed are assumed to map through the identity (<it/i.e./ to
the same numerical value).  In order to override this default mapping,
you may specify a range of codes to be undefined by using an
`<tt/UNDEFINE/' line:
<tscreen><verb>
UNDEFINE 0x00 0x2A
</verb></tscreen>
or, for a single code,
<tscreen><verb>
UNDEFINE 0x1234
</verb></tscreen>

PostScript mappings are different.  Every line in a PostScript mapping
maps a code to a glyph name
<tscreen><verb>
0x41 A
0x42 B
...
</verb></tscreen>
and codes not explicitly listed are undefined.

A mapping section ends with an <tt/ENDMAPPING/ line
<tscreen><verb>
ENDMAPPING
</verb></tscreen>
After all the mappings have been defined, the file ends with an
<tt/ENDENCODING/ line
<tscreen><verb>
ENDENCODING
</verb></tscreen>

In order to make future extensions to the format possible, lines
starting with an unknown keyword are silently ignored, as are mapping
sections with an unknown target.

<sect1>Using symbol fonts <label id="sec:symbol-fonts">

<p>Type&nbsp;1 symbol fonts should be installed using the
<tt/adobe-fontspecific/ encoding.

In an ideal world, all TrueType symbol fonts would be installed using
one of the <tt/microsoft-symbol/ and <tt/apple-roman/ encodings. A
number of symbol fonts, however, are not marked as such; such fonts
should be installed using <tt/microsoft-cp1252/, or, for older fonts,
<tt/microsoft-win3.1/.

In order to guarantee consistent results (especially between
Type&nbsp;1 and TrueType versions of the same font), it is possible to
define a special encoding for a given font. This has already been done
for the <tt/ZapfDingbats/ font; see the file
<tt>encodings/adobe-dingbats.enc</tt>.

<sect1>Hints about using badly encoded fonts <label id="sec:incorrect-encoding">

<p>A number of text fonts are incorrectly encoded. Incorrect encoding
is sometimes done by design, in order to make a font for an exotic
script appear like an ordinary Western text font.  It is often the
result of the font designer's laziness or incompetence; for some
reason, most people seem to find it easier to invent idiosyncratic
glyph names rather than follow the Adobe glyph list.

There are two ways of dealing with such fonts: using them with the
encoding they were designed for, and creating an <it/ad hoc/ encoding
file.

<sect2>Using fonts with the designer's encoding

<p>In the case of Type&nbsp;1 fonts, the font designer can specify a
default encoding; this encoding is requested by using the
`<tt/adobe-fontspecific/' encoding in the XLFD name. Sometimes, the
font designer omitted to specify a reasonable default encoding, in
which case you should experiment with `<tt/adobe-standard/',
`<tt/iso8859-1/', `<tt/microsoft-cp1252/', and
`<tt/microsoft-win3.1/'. (The encoding `<tt/microsoft-symbol/' doesn't
make sense for Type&nbsp;1 fonts).

TrueType fonts do not have a default encoding.  However, most TrueType
fonts are designed with either Microsoft or Apple platforms in mind,
so one of `<tt/microsoft-symbol/', `<tt/microsoft-cp1252/',
`<tt/microsoft-win3.1/', or `<tt/apple-roman/' should yield reasonable
results.

<sect2>Specifying an <it/ad hoc/ encoding file

<p>It is always possible to define an encoding file to put the glyphs
in a font in any desired order. Again, see the
`<tt>encodings/adobe-dingbats.enc</tt>' file to see how this is done.

<sect2>Specifying font aliases

<p>By following the directions above, you will find yourself with a
number of fonts with unusual names --- with encodings such as
`<tt/adobe-fontspecific/', `<tt/microsoft-win3.1/' <it/etc/.  In order
to use these fonts with standard applications, it may be useful to
remap them to their proper names.

This is done by writing a `<tt/fonts.alias/' file. The format of this file
is similar to the format of the `<tt/fonts.dir/' file, except that it maps
XLFD names to XLFD names. A `<tt/fonts.alias/' file might look as follows:
<tscreen><verb>
1
"-ogonki-alamakota-medium-r-normal--0-0-0-0-p-0-iso8859-2" \
  "-ogonki-alamakota-medium-r-normal--0-0-0-0-p-0-adobe-fontspecific"
</verb></tscreen>
(both XLFD names on a single line).  The syntax of the
`<tt/fonts.alias/' file is precisely described in the
<tt/mkfontdir/(1) manual page.

<sect>Additional notes about TrueType support

<p>This version of XFree86 comes with two TrueType backends,
<it/FreeType/ (module `<tt/freetype/', formerly known as <it/xfsft/) and
<it/X-TrueType/ (module `<tt/xtt/').  These two backends are <it/not/
compatible: only one of them can be used at any one time.

In order to use the <it/FreeType/ backend, please check that the
`<tt/Module/' section of your `<tt/XF86Config/' file contains a line
that reads
<tscreen><verb>
Load "freetype"
</verb></tscreen>

In order to use the <it/X-TrueType/ backend, replace the line in your
<tt/XF86Config/ file that loads the <tt/freetype/ module with a
line that reads
<tscreen><verb>
    Load "xtt"
</verb></tscreen>

Both TrueType backends delay glyph rasterisation up to the time at
which a glyph is first used.  For this reason, they only provide an
approximate value for the ``average width'' font property.

Both backends also support an optimisation for character-cell fonts
(fonts with all glyph metrics equal, or terminal fonts).  A font with
an XLFD specifying a character-cell spacing `<tt/c/', as in
<tscreen><verb>
-misc-mincho-medium-r-normal--0-0-0-0-c-0-jisx0208.1990-0
</verb></tscreen>
will not rasterise glyphs at metrics computation time, but instead
trust the font really to be a character-cell font.  You are
encouraged to make use of this optimisation when useful, but be warned
that not all monospaced fonts are character-cell fonts.

<sect1>The <it/FreeType/ TrueType backend

<p>The <it/FreeType/ backend (formerly <it/xfsft/) is a backend based on
the FreeType library (see <url url="http://www.freetype.org/"
name="the FreeType web site">) and has support for the ``fontenc''
style of internationalisation (see Section <ref id="sec:fontenc"
name="The fontenc layer">).  This backend supports TrueType Font files
(`<tt/*.ttf/') and TrueType Collections (`<tt/*.ttc/').

In order to access the faces in a TrueType Collection file, the face
number must be specified in the fonts.dir file before the filename
within colons.  For example,
<tscreen><verb>
:2:mincho.ttc -misc-mincho-medium-r-normal--0-0-0-0-c-0-jisx0208.1990-0
</verb></tscreen>
refers to face 2 in the `<tt/mincho.ttc/' TrueType Collection file.

The <it/FreeType/ backend uses the <it/fontenc/ layer in order to
support recoding of fonts; this was described in Section <ref
id="sec:fontenc" name="The fontenc layer"> and especially Section <ref
id="sec:fontenc-freetype" name="FreeType-specific notes about
fontenc"> earlier in this document.

<sect1>The <it/X-TrueType/ TrueType backend <label id="sec:X-TT">

<p>The `X-TrueType' backend is another backend based on the FreeType
library.  X-TrueType doesn't use the `fontenc' layer for managing font
encodings, but instead uses its own database of encodings.  However,
X-TrueType includes a large number of encodings, and any encoding you
need is likely to be present in X-TrueType.

X-TrueType extends the `<tt/fonts.dir/' syntax with a number of options,
known as `TTCap'.  A `TTCap' entry follows the general syntax
<tscreen><verb>
:option=value:
</verb></tscreen>
and should be specified before the filename.

The most useful TTCap option is used to specify the face number to use
with TTCs; this is the `<tt/fn/' TTCap option.  For example, face 2 of
font file `<tt/mincho.ttc/' is specified using:
<tscreen><verb>
:fn=2:mincho.ttc -misc-mincho-medium-r-normal--0-0-0-0-c-0-jisx0208.1990-0
</verb></tscreen>
More information on the TTCap syntax, and on X-TrueType in general,
may be found on <url url="http://x-tt.dsl.gr.jp/" name="the X-TrueType
home page">.

<sect>Appendix: background and terminology <label id="sec:background">
<sect1>Characters and glyphs

<p>A computer text-processing system inputs keystrokes and outputs
<it/glyphs/, small pictures that are assembled on paper or on a
computer screen.  Keystrokes and glyphs do not, in general, coincide:
for example, if the system does generate ligatures, then to the two
keystrokes &lt;<tt/f/&gt;&lt<tt/i/&gt; will typically correspond a
single glyph.  Similarly, if the system shapes Arabic glyphs in a
reasonable manner, then multiple different glyphs may correspond to
a single keystroke.

The complex transformation rules from keystrokes to glyphs are usually
factored into two simpler transformations, going through the
intermediary of <it/characters/.  You may want to think of characters
as the basic unit of data that is stored <it/e.g./ in the buffer of
your text editor.  While the definition of a character is intrinsically
application-specific, a number of standardised collections of
characters have been defined.

A <it/coded character set/ is a set of characters together with a
mapping from integer codes --- known as <it/codepoints/ --- to
characters.  Examples of coded character sets include US-ASCII,
ISO&nbsp;8859-1, KOI8-R, and JIS&nbsp;X&nbsp;0208(1990).

A coded character set need not use 8 bit integers to index
characters. Many early mainframes used 6 bit character sets, while
16 bit (or more) character sets are necessary for ideographic writing
systems.

<sect1>Font files, fonts, and XLFD <label id="sec:xlfd">

<p>Traditionally, typographers speak about <it/typefaces/ and
<it/founts/.  A typeface is a particular style or design, such as
Times Italic, while a fount is a molten-lead incarnation of a given
typeface at a given size.

Digital fonts come in <it/font files/.  A font file contains all the
information necessary for generating glyphs of a given typeface, and
applications using font files may access glyph information in an
arbitrary order.

Digital fonts may consist of bitmap data, in which case they are said
to be <it/bitmap fonts/.  They may also consist of a mathematical
description of glyph shapes, in which case they are said to be
<it/scalable fonts/.  Common formats for scalable font files are
<it/Type&nbsp;1/ (sometimes incorrectly called <it/ATM fonts/ or
<it/PostScript fonts/), <it/Speedo/ and <it/TrueType/.

The glyph data in a digital font needs to be indexed somehow.  How
this is done depends on the font file format.  In the case of
Type&nbsp;1 fonts, glyphs are identified by <it/glyph names/.  In the
case of TrueType fonts, glyphs are indexed by integers corresponding
to one of a number of indexing schemes (usually Unicode --- see below).

The X11 system uses the data in font file to generate <it/font
instances/, which are collections of glyphs at a given size indexed
according to a given encoding.

X11 font instances are usually specified using a notation known as the
<it/X Logical Font Description/ (XLFD).  An XLFD starts with a dash
`<tt/-/', and consists of fourteen fields separated by dashes, for
example
<tscreen><verb>
-adobe-courier-medium-r-normal--0-0-0-0-m-0-iso8859-1
</verb></tscreen>
Or particular interest are the last two fields `<tt/iso8859-1/', which
specify the font instance's encoding.

X11 font instances may also be specified by short name.  Unlike an
XLFD, a short name has no structure and is simply a conventional name
for a font instance.  Two short names are of particular interest, as
they are handled specially by the server, and the server will not
start if font instances with these names cannot be opened.  These are
`<tt/fixed/', which specifies the fallback font to use when the
requested font cannot be opened, and `<tt/cursor/', which specifies
the set of glyphs to be used by the mouse pointer.

Short names are usually implemented as aliases to XLFDs; the
`<tt/fixed/' and `<tt/cursor/' aliases are defined in
<tscreen><verb>
/usr/X11R6/lib/X11/font/misc/fonts.alias
</verb></tscreen>

<sect1>Unicode

<p>Unicode (<url url="http://www.unicode.org">) is a coded character
set with the goal of uniquely identifying all characters for all
scripts, current and historical.  While Unicode was explicitly not
designed as a glyph encoding scheme, it is often possible to use it as
such.

Unicode is an <it/open/ character set, meaning that codepoint
assignments may be added to Unicode at any time (once specified,
though, an assignment can never be changed).  For this reason, a
Unicode font will be <it/sparse/, and only define glyphs for a subset
of the character registry of Unicode.

The Unicode standard is defined in parallel with the international
standard ISO&nbsp;10646.  Assignments in the two standards are always
equivalent, and this document uses the terms <it/Unicode/ and
<it/ISO&nbsp;10646/ interchangeably.

When used in X11, Unicode-encoded fonts should have the last two
fields of their XLFD set to `<tt/iso10646-1/'.

<sect>References

<p>XFree86 comes with extensive documentation in the form of manual
pages and typeset documents.  Before installing fonts, you really
should read the <tt/mkfontdir/(1) manual page; other manual pages of
interest include <tt/X/(1), <tt/Xserver/(1), <tt/xset/(1),
<tt/xlsfonts/(1) and <tt/showfont/(1).  In addition, you may want to
read the X Logical Font Description document, by Jim Flowers, which is
provided in the file `<tt>xc/doc/xlfd.PS.Z</tt>'.

The <url name="comp.fonts FAQ"
url="http://www.netmeg.net/faq/computers/fonts/">, which is
unfortunately no longer being maintained, contains a wealth of
information about digital fonts.

The 
<url name="xfsft home page"
     url="http://www.dcs.ed.ac.uk/home/jec/programs/xfsft/">
has been superseded by this document, and is now obsolete; you may
however still find some of the information it contains useful.  <url
name="Joerg Pommnitz' xfsft page"
url="http://www.joerg-pommnitz.de/TrueType/xfsft.html"> is the
canonical source for the `<tt/ttmkfdir/' utility.

The documentation of <it/X-TrueType/ is available from
<url url="http://x-tt.dsl.gr.jp/" name="the X-TrueType home page">.

A number of East-Asian CIDFonts are available from 
<url name="O'Reilly's FTP site"
     url="ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/">. 

The <url url="http://www.unicode.org" name="Unicode consortium site">
may be of interest.  But you are more likely to find what you need on
Markus Kuhn's <url url="http://www.cl.cam.ac.uk/~mgk25/unicode.html"
name="UTF-8 and Unicode FAQ">.

The IANA RFC documents, available from a number of sites throughout
the world, often provide interesting information about character set
issues; my favourite is RFC&nbsp;373.

</article>
<!-- Who was it who wrote the Linuxdoc DTD, and was he drunk at the
     time ? -->
