New Font Tools For
New font to ols for T X
E
Werner Lemb erg
Kleine Beurhausstr. 1
D-44137 Dortmund
Germany
Abstract
The following font to ols will b e describ ed in this pap er:
VFlib, the Vector Font Library, which has b een written by Kakugawa Hi-
rotsugu Ì ¯ < ê. This library together with an included suite of demo
applications is aimed to provide a uniform interface for accessing fonts in
many di erent formats. With the help of con guration les it is p ossible to
access fonts with other enco dings, to de ne new virtual fonts, and others.
Using VFlib as a basis for dvi drivers, it will b e no longer necessary to have
pk les for any font format except for Metafont.
FreeTyp e, develop ed byDavid Turner, Rob ert Wilhelm, and the author
of this pap er. This is a platform-indep endent library to render bitmaps
from TrueTyp e fonts. What makes it di erent from other freely available
TrueTyp e to ols is a TrueTyp e interpreter to pro cess hints.
ttf2pk and hbf2gf, maintained resp. written by the author. Both programs
are part of the CJK package and are used to convert CJK TrueTyp e and HBF
fonts into T X fonts.
E
Intro duction Today,wehave many font les and many dif-
ferent font le formats. When we need soft-
None of the to ols are really new, but until now they
ware to display or printcharacters whichdoes
either have not b een presented to the English T X
E
not dep end on a windowing system and/or
communityorhave b een hidden in other packages.
an op erating system, wemust write interface
Most of them are work in progress, and there is a
routines for accessing font les in each appli-
good chance that this pap er is already out of date
cation software again and again. To do this,
when it is printed.
programmers must have knowledge of font le
1
All of them have a CJK background more or
formats; it will b e a hard task for program-
less; Kakugawa originally wanted easy Japanese
mers if the number of font formats that an
font supp ort for dvi drivers, mytwo programs are
application software supp orts b ecomes large.
still only useful for CJK fonts, and FreeTyp e was
also so on extended to manage CJK TrueTyp e fonts.
VFlib is a font library written in C pro-
Nevertheless, work is going on to internationalize the
viding several functions to obtain bitmaps of
to ols, making them useful for a broader audience.
characters. VFlib hides the font format of font
In the bibliographyyou can nd the lo cations
les and provides a uni ed API for all sup-
from whichtodownload the packages.
p orted font formats. Thus, programmers for
application software need not have knowledge
VFlib
on font le formats. Instead, any software us-
Until recently do cumentation was only available in
ing VFlib can supp ort various font le formats
Japanese see [2] | the main reason why this great
immediately.
to ol is virtually unknown outside of Japan. Nowa
translation into English has b een made; this quote
[...]
2
from basic.txt tells what VFlib is:
Currently, VFlib supp orts the following font
1
Chinese/Japanese/Korean
2
le formats: PCF, BDF, HBF, TrueTyp e,
In general, I'm following the do cumentation les very
closely, omitting not so imp ortantortootechnical details. GF, PK, TFM, ShotaiKurabu b K û Õ ,
206 TUGb oat,Volume 18 1997, No. 3 | Pro ceedings of the 1997 Annual Meeting
New font to ols for T X
E
3
a vector font format for Japanese Kanji, device. In addition to these font metrics are de ned
and JG another vector font format for Japa- for each glyph.
nese Kanji. Esp ecially, VFlib can b e used as Some font le formats do not have such con-
a font mo dule for drivers/previewers of dvi cepts; in this case, missing information either is
A
les T X/L T X; part of this package is a given in a vf libcap le or the sp eci c font driver pro-
E E
sample dvi previewer for X Windows writ- vides default values. For instance, a TrueTyp e font
ten with only 400 lines of C co de. is a vector font and is not restricted to a certain
p oint size and resolution of the target device since
VFlib stands for Vector Font library | earlier
vector fonts can b e scaled to any size. Another ex-
versions of the library have supp orted Japanese vec-
ample is the ShotaiKurabu font format whichdoes
tor fonts only, hence the name.
not have font metric information at all: a font driver
Basic concepts. The VFlib mo dule consists of two
for this font format generates virtual font metrics
parts: the library itself whichmust b e linked to the
using the data given in a vf libcap le.
application program, and a font database le called
Here a small excerpt of a vf libcap le suitable
`vf libcap' since the le format resembles the format
for Japanese T X JT X; omissions are indicated
E E
of a termcap database; see b elow for an example.
with three dots.
Font classes and font drivers. VFlib can handle
VFlib-Defaults:\
multiple font le formats. Reading a font le is done
:implicit-font-classes=ascii- jtex- kanj i,\
byaninternal mo dule in VFlib corresp onding to the
gf/pk:\
font le format. This internal mo dule is called a
:extension-hints=pk=ascii-jte x-kan ji,\
`font driver'. Service units provided by font drivers
gf=ascii-jtex-kanji,\
are called `font classes'. From an end-user's p ointof
pk=gf/pk,\
view, font formats are distinguished by the names
gf=gf/pk,\
of font classes. Font drivers themself are not visible
.ttf=ttf:\
for end-users.
:variables-default-values=\
$TeX_KPATHSEA_PROGRAM=\
Some font drivers may not read font les on
/usr/local/teTeX/bin/xldvi:
disk; they may generate glyphs and outlines by in-
ternal computation only. In addition, some font
TeX-Defaults:\
drivers may return glyphs which are obtained as
:kpathsea-mode=ljfour:\
glyphs by another font class.
:dpi=600:\
Font names and searching. In VFlib, a font is
:kpathsea-program-name=\
sp eci ed by a `font name' on op ening. First, VFlib
$TeX_KPATHSEA_PROGRAM:
checks if the font name is given in vf libcap or not. If
the font name is found, VFlib reads the description
TrueType-Defaults:\
for the font in vf libcap, invokes a font driver corre-
:extension=.ttf:\
sp onding to the font class name and op ens the font
:aspect=1:\
:dpi=600:\
le.
:font-directories=\
If the font name is not given in a vf libcap le, a
/dos/texmf/fonts/truetype/j apane se:\
font searching mechanism is invoked. Since there are
:platform=microsoft:
so many font les for X Window and T X, this fea-
E
ture has b een intro duced to avoid writing an entry
for each font le. Various font drivers will b e called
mincho-jtex:\
to see whether the font can b e op ened; a list of font
:font-class=ttf:\
drivers for font searching is given in the vf libcap le.
:font-file=uwjmg3.ttf:\
Fonts describ ed in a vf libcap le are called `ex-
:magnification=0.92:\
plicit fonts' and fonts that are searched by the font
:writing-direction=h:\
search feature are called `implicit fonts'.
:character-set=jisx0208_1983: \
:encoding-force=sjis:
For T X fonts, the kpathsea library will b e used
E
for searching.
mincho-5pt:\
The vf libcap database. Each virtual font as
:point-size=5:\
provided by VFlib has its inherent information on
:inheritance=mincho-jtex:
p oint size, pixel size, and resolution of the target
3
...
Other transcription forms are SyotaiKurabu or Syotai-
Club.
TUGb oat,Volume 18 1997, No. 3 | Pro ceedings of the 1997 Annual Meeting 207
Werner Lemb erg
All other entries are used to de ne a Japa- mincho-10pt:\
:point-size=10:\
nese TrueTyp e font as a font for JT X. The nal
E
:inheritance=mincho-jtex:
JT X font is built from various layers, starting with
E
the entry `mincho-jtex' which de nes the TrueTyp e
font name, the writing direction, the character set,
min:\
etc. `mincho-5pt' is an example of how to inherit
:font-class=ascii-jtex-kanj i:\
font capabilities: only a p oint size declaration has
:kanji-adjustment-file=\
b een added. Then the `min' base font class is sp eci-
/usr/local/VFlib/ascii-jtex/t tf.ad j:
ed, calling the `ascii-jtex-kanji' font driver and us-
ing an adjustment le ttf.adj for all fonts of this
min5:\
4
class. Note that in `min' no fonts are de ned |
:kanji-font=mincho-5pt:\
:inheritance=min: the concept is similar to ob ject oriented languages
where some base classes are de ned on which vir-
...
tual classes are built. With `min5' or `min10' the
top level is reached, using all previously constructed
min10:\
font classes.
:kanji-font=mincho-10pt:\
NFSS would not require size quantization of the
:inheritance=min:
font; it's easy to add a prop er entry like this:
min-nfss:\
The format of a capability le is somewhat
:kanji-font=mincho-jtex:\
strange: each entry must be formally on one line
:inheritance=min:
which can b e split with a trailing backslash. The
A font de ned in this way can then b e used at any
name of a capabilityentry is the rst name starting
size; VFlib would scale the font appropriately.
a line; all capability descriptions then follow in the
The VFlib API. The numb er of functions is small
format
due to the identical interface for all font formats.
:hentry 1 i:hentry 2 i:...:
Before op ening any font you have to call VF_Init
to initialize the library with a vf libcap le. Op en-
A single colon `:'is equivalent to the construction
ing and closing of a font are handled with the func-
`:hwhitespace i:', making it convenient to break a
tions VF_OpenFont and VF_CloseFont resp ectively.
line after the colon. Capability descriptions have
A glyph bitmap can b e accessed in twoways. Either
the format
you sp ecify bitmap sizes in pixels VF_GetBitmap2,
hcap description i=hcap value i
or you pass the resolution in dpi together with the
p oint size as parameters VF_GetBitmap1. Simi-
The rst equal sign separates the description from
lar commands exist for getting outline vector data
the value which can b e e.g. a list containing equal
VF_GetOutline and for obtaining information on
signs to o.
metrics VF_GetMetric1, VF_GetMetric2. All the
The capability entry `VFlib-Defaults' de nes
functions take the character co de as a mandatory
global default values for VFlib. `implicit-font-classes'
parameter.
sp eci es a list of font classes for implicit font search;
Auxiliary functions are provided to free bitmap
the font class drivers are invoked in the order of that
or metrics ob jects, to copy or scale bitmaps, and
list for searching. `extension-hints' gives an ordered
to `dump' the glyph using ASCI I characters to get
list of pairs indicating which extension of an implicit
similar output as gftype.
font needs which driver to handle. In the ab ove ex-
Finally,you can write your own font driver to
ample there are e.g. twoentries for les ending with
be installed with VF_InstallFontDriver. Font
pk: one for Japanese T X and one for standard T X.
E E
drivers must provide a small set of glyph manipulat-
If the rst driver fails, the second will be called.
5
ing functions, and p ointers to those functions are
Finally, `variables-default-values' gives a list of de-
then passed to the VFlib engine. Using the function
fault values which can b e overridden at run-time if
VF_GetProp it's easy to extract font-class-sp eci c
supplied as an argument string to the initialization
4
function of VFlib.
This le comp ensates the mono-width of Japanese
glyphs with small o sets for certain character classes like
`TeX-Defaults' primarily gives initialization val-
CJK punctuation characters to improvetyp ographical out-
ues for kpathsea. Users of web2c and teT X should
E
put. Character classes are a sp ecial feature of JT X.
E
5
b e quite familiar with the description names and its
With `glyph' an emptybox can b e meant also e.g. for
meanings. writing a tfm driver.
208 TUGb oat,Volume 18 1997, No. 3 | Pro ceedings of the 1997 Annual Meeting
New font to ols for T X
E
entries from the vf libcap le to control the new font with hinting instructions whichmove the p oints de-
driver. termining the glyph contours to device resolution
dep endent lo cations b efore rasterization.
Limitations and planned features. Many parts
Wenow assume that all p ointmoving has b een
of the VFlib package are still undo cumented, or do c-
done, and that the x and y co ordinates of the p oints
umentation is only available in Japanese. For in-
are stored in a list together with a ag to indicate
stance, VFlib contains a complete library for inter-
whether the p ointison or o the curve. See Fig-
preting dvi les with sp ecials which further sim-
8
ure 1.
pli es the writing of dvi drivers. A suite of dvi
A scanline is a pixel line in the target bitmap.
previewers and dvi drivers is also included.
An outline, also called contour, is a closed line that
Currently, VFlib is limited to UNIX-like op erat-
delimits an inner and an outer region of the glyph.
ing systems, but it should not b e dicult to p ort it
The b est way to ll a shap e is to decomp ose it into
to other platforms b ecause no real dep endencies on
simple horizontal segments, called spans. Spans are
UNIX features are built in.
computed for each scanline. This is usually done
Another useful to ol yet to b e written is a mo d-
from the top to the b ottom of the shap e, in a move-
ule or program for creating tfm les from the bitmap
ment called sweep see Figure 2. It's easy to see
and vector fonts.
that there is typically more than one span p er scan-
Planned for the near future are mo dules for pro-
line. For each scanline during the sweep op eration
cessing PostScript fonts and T X virtual fonts; sup-
E
we need the horizontal x co ordinates of the start
p ort for metrics les is already implemented, but
and end p oints of all spans. These are computed
without a vf mo dule its use is rather academic.
b efore the sweep, in a phase called `decomp osition'
which converts the glyph contours into pro les.
FreeTyp e
Pro les are sections of the contours which are
The rep ort on FreeTyp e see [6] will cover only the
either only ascending or only descending, i.e. mono-
basics without going to o muchinto detail | the -
tonic in the vertical direction we will also say y-
nal end-user API has not b een de ned yet. It is not
monotonic. It can easily b e deduced from Figure 3
really linked to T X, and if you are not interested
E
that it is p ossible to resolveany contour into vertical
in how a rasterizer works, you should skip this sec-
pro les and horizontal lines which are not part of
tion. Nevertheless, it is linked to typ ography, and
a pro le.
the text presents some general principles of how out-
Each pro le inherits the direction of the par-
line glyphs will b e handled to yield bitmaps.
ent contour this is necessary to decide whether a
FreeTyp e is develop ed in a rather unusual way.
p oint is inside or outside of a contour, see b elow.
The package provides the complete library co de and
Figure 4 shows that a contour can havemultiple pro-
some to ols which demonstrate the use of the library
les. Pro les are also called `edges' or `edgelists' in
in two programming languages, namely in C and in
other graphics libraries.
Pascal. We try to keep the library small ab out
The rasterizer stores a pro le as an array of
60 kByte if compiled for maximal sp eed with gcc;
x co ordinates of the intersection p oints of the pro-
nevertheless it is highly p ortable since the C part
le and the a ected scanlines. To allo cate a pro le
is written in ANSI C, having only a few architec-
array without wasting memory we must know the
ture dep endencies which can b e adjusted with a few
height of that pro le; with other words, wehaveto
global macro de nitions.
compute the vertical extrema minimum and max-
imum. This can be done very easily for straight
The rasterizer. A rasterizer converts the vector
lines, but it is not trivial for B ezier arcs b ecause
data of a glyph into a pixel representation. In
this short overview all complications drop-out con-
8
trol, wrong contour direction, sub-banding of pro-
A second-order B ezier curve also called quadratic
6
spline is fully sp eci ed with the starting p oint of the curve,
les etc. are omitted. This part of the FreeTyp e
a control p oint usually o the line, and the end p oint of the
engine is quite generic and could b e adapted to, say,
curve. It is p ossible to have two consecutive o -p oints in
PostScript fonts to o.
the p oints list; in this case a virtual on-p oint between the
Glyphs as stored in a TrueTyp e font see [5] for
two o -p oints will b e constructed. The parametric form of a
quadratic spline is
a reference consist of vectorial information straight
7
lines and B ezier curves of second order together
2 2
pt=1 t p +2t1 tp + t p ;
1 2 3
6
The original do cument is raster.doc of the FreeTyp e
package, written byDavid Turner.
t denotes a real numberinthe range [0; 1], p is the start
1
7
p oint, p the control p oint, and p the end p oint. PostScript fonts use third-order B ezier curves.
2 3
TUGb oat,Volume 18 1997, No. 3 | Pro ceedings of the 1997 Annual Meeting 209
Werner Lemb erg
p
2
p
3
p
1
Two `on' p oints with two `o ' p oints b etween.
Two `on' p oints Two `on' p oints and one `o ' p oint
The b ox indicates a virtual p oint not in the list.
Figure 1: Possible `on' and `o ' p oint combinations in a FreeTyp e font
Figure 2: Filling a shap e with spans. The arrow indicates the sweeping direction.
9
they are not monotonic in the general case. Nev-
ertheless, a B ezier arc can b e split into two subarcs
with very little computation. Both subarcs are again
B ezier arcs, and one of them is guaranteed to b e y-
monotonic. Lo ok at Figure 5: p denote the p oints
i
b elonging to the original curve, q and r then de ne
i i
the subarcs i b eing 1, 2, or 3. The following for-
mul give the relationship between an arc and its
subarcs:
q = p ; q =p + p =2
1 1 2 1 2
r = p ; r =p + p =2
3 3 2 2 3
q = r =q + r =2
3 1 2 2
We stop if either all subarcs are monotonic or the
Figure 3: Decomp osition of a contour into pro les
subarcs b ecome to o small; in b oth cases we've found
an extremum. This pro cess is called attening.
The next step is to compute all intersection
p oints of pro les and scanlines. In the case of lines
this is straightforward, but it is a little more compli-
cated for splines. Fortunately we can use arc split-
ting again. Consider Figure 6. The horizontal lines
represent scanlines, and a short segment of a pro le
is shown. If we continue splitting until each subarc
Figure 4: A contour with multiple pro les
9
A quadratic spline is y-monotonic if and only if the y co-
ordinates of the p oints p , p , and p are monotonic, i.e.
1 2 3
p p p or p p p . If p = p = p ,
1 2 3 1 2 3 1 2 3
y y y y y y y y y
the arc degenerates into a horizontal line.
210 TUGb oat,Volume 18 1997, No. 3 | Pro ceedings of the 1997 Annual Meeting
New font to ols for T X
E p 2