Using truetype fonts with pdftex
From version 1.21a pdftex supports the naming convention `uniXXXX' in encoding files. This only makes sense with ttf fonts, of course. When
Hi,
the question how to use truetype fonts with pdftex keeps
popping up from time to time, so I wrote some (draft) notes
which would be added to the official pdftex manual.
Comments/suggestions welcome.
Regards,
Thanh
======================================================
\subsection{A closer look at TrueType fonts and pdftex}
The most common outline format for tex is t1. ttf fonts are slightly
different from t1 and hence requires some extra work to get it right.
An important issue when dealing with ttf is to understand the way how t1
and ttf handle encoding and glyph names (or more precisely, glyph
``identity'').
t1 is familiar with tex users, so let's start with it first: t1 refers to
glyphs by names, ie each glyph is identified by its name like
`/A', `/comma', etc. Given a glyph name, it's easy to tell if a t1 font
contains that glyph or not. Encoding with t1 is therefore simple: given a
number (between 0..255), an encoding tells us the name to get the relevant
glyph.
With ttf the situation is not that simple, since ttf doesn't use name to
refer to glyphs, but ``indices''. This means that each glyph
is identified by its index, not its name. The indices are numbers that
differ from font to font. ttf handle encodings by a mechanism called
``cmap'', which are roughly tables containing mapping from character code
to glyph index. A ttf font can contain one or more such tables (each
corresponds to an encoding).
Since glyph names are not strictly necessary for ttf, they are not always
available inside a ttf font. Given a ttf font, one of the following case
may happen:
\startitemize[a,packed]
\item the font contains correct names for all its glyphs. This is the ideal
situation and is often the case for high-quality latin fonts.
\item the font contains wrong name for all or most of its glyphs. This is
the worst situation that often happens with poor-quality fonts, or
fonts converted from other formats.
\item the font contains no glyph names at all. Newer version of Palatino
fonts by Linotype (v1.40, coming with Windows XP) is one example.
\item the font contains correct names for most glyphs, and no names or
wrong names for a few glyphs. This happens from time to time.
\stopitemize
One may wonder how things can be so complex with glyph names in ttf. The
reason is that t1 fonts rely on correct names to work properly. If a glyph
has wrong name, it get noticed immediately. ttf as mentioned before don't
use names for its encoding. So, if glyph names in a ttf font are wrong or
missing, it's usually not a big deal and often goes unnoticed.
The potential problem with using ttf in pdftex is that we are so used to
the t1 encoding convention which relies on correct glyph names. Most font
tools also rely on this convention; all encoding file (.enc files) use
glyph names, too. But as discussed above, glyph names in ttf is not
something very reliable. If we encounter a font that doesn't have correct
names for all glyphs, we need to do some more work.
If glyph names are not correct, we need a better way to refer to a glyph in
ttf fonts than using its name. The most reliable way seems to be via
Unicode: most ttf fonts provide correct mapping from unicode to glyph
index. This is something we can count on, since it is required for a ttf to
be usable.
pdftex sees for example `uni12AB', it will:
\startitemize[a,packed]
\item read the table <unicode> -> <glyph-index> from the font;
\item loop up the value '12AB' in the table; if found then pick the
relevant glyph index.
\stopitemize
ttf2afm also does the same lookup when it sees names like `uni12AB'.
Now let's review the minimal steps to get a ttf font working with pdftex:
\startitemize[a,packed]
\item generate an afm from ttf using ttf2afm. Example:
\starttyping
ttf2afm -e 8r.enc -o times.afm times.ttf
\stoptyping
\item convert afm to tfm using whatever tool suitable: afm2tfm, fontinst,
afm2pl, etc. Example:
\starttyping
afm2tfm times.afm -T 8r.enc
\stoptyping
\item create the needed map entry for the font. Example:
\starttyping
\pdfmapfile{+times TimesNewRomanPSMT <8r.enc
participants (1)
-
Thanh Han The