mf2pt1: Scott Pakin
mf2pt1: Scott Pakin
Copyright
c 2014 Scott Pakin
This program may be distributed and/or modified under the conditions of the LATEX Project
Public License, either version 1.3c of this license or (at your option) any later version.
http://www.latex-project.org/lppl.txt
and version 1.3c or later is part of all distributions of LATEX version 2006/05/20 or later.
Table of Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1 Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Specifying font information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Additional command-line options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Custom font encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 Restoring mfplain defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter 1: Introduction 1
1 Introduction
METAFONT is a high-level, mathematically oriented language for producing fonts. The
METAFONT interpreter produces device-dependent bitmaps, which render well at the target
resolution on the target device, but poorly at other resolutions or on other devices. Adobe’s
PostScript Type 1 font format is the de facto font standard for printers these days. It is a
vector format, which implies that it scales better than bitmaps, and it delegates the device-
and resolution-dependent tweaking from the font source to the target device’s PostScript
renderer. However, Type 1 fonts are extremely difficult to code by hand. Usually, one uses
a WYSIWYG program to design a Type 1 font. METAFONT, with its font-specific program-
ming language, is an elegant alternative. A font designer can write reusable subroutines
for repeated features, such as serifs and accents. He can define a font in terms of arbitrary
parameters, such as “boldness” or “italicness”, making it trivial to produce entire families
of fonts from a single source (hence the “meta” in the name “METAFONT”). Ideally, we
would like to design a font using the METAFONT language, but produce PostScript Type 1
output instead of bitmaps.
mf2pt1 helps bridge the gap between METAFONT and Type 1 fonts. mf2pt1 facilitates
producing PostScript Type 1 fonts from a METAFONT source file. It is not, as the name
may imply, an automatic converter of arbitrary METAFONT fonts to Type 1 format. mf2pt1
imposes a number of restrictions on the METAFONT input. If these restrictions are met,
mf2pt1 will produce valid Type 1 output.
1.1 Requirements
Before using mf2pt1, you will need to install the following programs:
Perl mf2pt1 is written in Perl. You will need a Perl interpreter to run it.
MetaPost mf2pt1 actually uses MetaPost, not METAFONT, to produce PostScript output.
Specifically, you will need the mpost executable and the mfplain.mp base file.
Type 1 Utilities
Producing properly encoded Type 1 fonts is tricky. mf2pt1 delegates the effort
to the Type 1 Utilities, specifically, to the t1asm program within that suite.
FontForge (optional)
FontForge is a WYSIWYG, but scriptable, Type 1 font-editing program. Al-
though FontForge is not strictly required for mf2pt1 to produce a Type 1 font,
mf2pt1 uses FontForge when available to autohint the generated Type 1 font,
thereby making it look better especially at lower resolutions.
Perl is available from the Comprehensive Perl Archive Network; MetaPost and the
Type 1 utilities are available from the Comprehensive TEX Archive Network; and, Font-
Forge is available from http://fontforge.sourceforge.net/. In addition, MetaPost’s
home page is http://cm.bell-labs.com/who/hobby/MetaPost.html, and the Type 1
utilities’ home page is http://www.lcdf.org/type/.
Besides being useful for autohinting fonts, FontForge enables a font designer to hint fonts
manually for additional fine-tuning and to convert among a variety of font formats, such
as PostScript, TrueType, and X Window fonts. FontForge is strongly recommended as a
complement to mf2pt1.
Chapter 2: Usage 2
1.2 Installation
To install mf2pt1, move the mf2pt1 executable someplace where your operating system can
find it. If you’re running Microsoft Windows, you should rename the program to mf2pt1.pl,
so that Windows knows it’s a Perl script. (Alternatively, if you have pl2bat, use that to
produce a mf2pt1.bat file, which you can run as simply mf2pt1.)
The next step is to produce a mf2pt1.mem file from the supplied mf2pt1.mp. The com-
mand to do this differs from system to system but is usually something like the following:
mpost -progname=mpost -ini mf2pt1 \\dump
Move the resulting mf2pt1.mem file someplace where MetaPost can find it.
The mf2pt1 documentation (what you’re reading now) is written in Texinfo and can
therefore easily be converted to a variety of formats:
PDF (mf2pt1.pdf)
texi2pdf mf2pt1.texi
PostScript (mf2pt1.ps)
texi2dvi mf2pt1.texi
dvips mf2pt1.dvi -o mf2pt1.ps
HTML (mf2pt1.html)
makeinfo --html mf2pt1.texi
Info (mf2pt1.info)
makeinfo mf2pt1.texi
N.B. The install-info command is a convenient way to install mf2pt1.info on your
system.
On Unix, you may also want to generate an mf2pt1 man page. The man page is embed-
ded within the mf2pt1 Perl script and can be extracted with pod2man:
pod2man --center="User Commands" --date="30 April 2014" \
--release="v2.5a" mf2pt1 > mf2pt1.1
You can then move mf2pt1.1 into /usr/man/man1 or any other man page directory. Note
that the mf2pt1 man page is fairly rudimentary. It is primarily a list of the command-line
options (see Section 2.2 [Font information], page 4) and a pointer to the document that
you’re reading now.
2 Usage
mf2pt1 is fairly straightforward to use. To process a METAFONT source file, merely specify
the filename:
mf2pt1 myfont.mf
That simple command automatically performs all of the following operations:
1. Read myfont.mf.
Chapter 2: Usage 3
2. Use mpost to convert each character to a separate Encapsulated PostScript (EPS) file
named myfont.num.
3. Process and merge the EPS files into a single “disassembled” Type 1 font called
myfont.pt1.
4. Run t1asm from the Type 1 Utilities to convert the disassembled font into a true,
binary Type 1 font called myfont.pfb.
5. Invoke fontforge to apply rendering hints to myfont.pfb and to attempt to remove
overlapping paths.
2.1 Restrictions
If mf2pt1 sounds too good to be true, it is—somewhat. mf2pt1 is not a general-purpose
METAFONT-to-Type 1 converter. Rather, it can convert only certain METAFONT constructs.
This is not a showstopper for new fonts designed with mf2pt1 in mind, but it is unlikely
that mf2pt1 will work on an arbitrary METAFONT source file.
mf2pt1’s biggest restriction is that each glyph must be drawn entirely from closed paths,
using METAFONT’s fill and unfill commands. (mf2pt1 has limited support for draw and
undraw, but their use is currently discouraged. filldraw and unfilldraw issue a warning
message and invoke draw and undraw, respectively.) The Type 1 format requires that
these paths be nonoverlapping. The following are some of the alternatives for removing
path overlaps:
1. Install FontForge. As part of its final step in producing a Type 1 font, mf2pt1 instructs
FontForge to replace overlapping paths with nonoverlapping paths.
2. Remove overlaps using METAFONT code within the font program itself. A .zip file
attachment to a 6 January 2005 article by Boguslaw Jackowski on the MetaPost mailing
list (subject: “Re: all intersections between two paths”) includes a MetaPost library
which assists with that task. The library provides a find outlines command which can
be used to define a path as the union of two other paths. A number of MetaPost
example programs are also included in the .zip file.
3. Design your fonts from the beginning without using overlapping paths.
font name string (The value of font family, plus an underscore, plus
the value of font weight, with all spaces removed)
font size numeric (Must be specified or mf2pt1 will abort with an error
message)
As an example, the following METAFONT code shows the usage of all of the parameters
that mf2pt1 accepts:
if known ps output:
font coding scheme "ot1";
font comment "Copyright (C) 2014 Scott Pakin.";
Chapter 2: Usage 7
option specifies the filename of a FontForge script to use instead of the default script, which
is listed below:
Open($1);
SelectAll();
RemoveOverlap();
AddExtrema();
Simplify(0, 2);
CorrectDirection();
Simplify(0, 2);
RoundToInt();
AutoHint();
Generate($1);
Quit(0);
See the FontForge documentation for an explanation of each of those commands and a
description of other commands made available to FontForge scripts. mf2pt1 runs the script
with one argument ($1), which is the name of the generated .pfb file.
mf2pt1 also supports a --help option which summarizes all of the program’s command-
line options.
Chapter 2: Usage 9
All entries in the encoding vector are PostScript “names” and therefore must be pre-
fixed with a slash. Unnamed characters such as control characters are commonly named
‘_anumber’, where number is the decimal offset into the character table. Undefined char-
acters are indicated by ‘.notdef’. In the EBCDIC example, the character at position 0 in
the font will be named ‘a0’; the character at position 1 will be named ‘a1’; the character at
position 74 will be named ‘bracketleft’; the character at position 129 will be named ‘a’;
and so forth.
overrides the character position passed to beginchar (i.e., 123) with whatever character
position the current encoding has designated for the ‘ohungarumlaut’ glyph:
beginchar (123, cap height#-1/2pt#, cap height#, 0);
if known ps output:
glyph name "ohungarumlaut";
fi
...
endchar;
3 Future Work
One avenue for future work is to enable the font designer to specify Type 1 font hints
directly in the METAFONT font program. Hinting is a way for a font designer to specify
how a font should be rendered at low resolutions, for example, at typical monitor res-
olutions. In METAFONT, this is done by controlling the way that points are mapped to
pixel locations, using commands such as define corrected pixels, define blacker pixels, and
lowres fix. Type 1 fonts are hinted in a completely different manner. Type 1 hints dis-
tinguish key character features, such as stems and dots, from decorations which can be
discarded at low resolutions. The PostScript interpreter uses that information to determine
how to map points to pixels. Although mf2pt1 employs FontForge to autohint the fonts
it generates, the approach is mechanical and unlikely to hint as well as a human can do
manually. It would be convenient for mf2pt1 one day to provide METAFONT commands for
hstem, vstem, dotsection, and the other Type 1 hints. That way, hints will no longer need
to be re-added manually every time mf2pt1 regenerates a Type 1 font.
Another future addition to mf2pt1 is the addition of more font encodings. The following
are the encodings that mf2pt1 will most likely accept:
TeXMathItalicEncoding
Upper- and lowercase Greek and Latin letters, old-style digits, and a few sym-
bols and accents.
TeXMathSymbolEncoding
A variety of symbols, as well as calligraphic Latin majuscules.
Acknowledgments 11
TeXMathExtensionEncoding
Variable-sized symbols, such as braces, integrals, and radicals.
AdobeExpert
Small caps, currency symbols, old-style digits, and various superior and inferior
letters and digits.
Acknowledgments
Many thanks are owed to Werner Lemberg for writing the code underlying the --rounding
option; for introducing the glyph name command and asis encoding vector; for provid-
ing the default FontForge script listed in Section 2.3 [Additional command-line options],
page 7; for fixing some code-generation bugs in mf2pt1; for finding a more robust way to
dump mf2pt1.mem; for directing me to the overlap-removal code mentioned in Section 2.1
[Restrictions], page 3; for supplying the crossproduct, makeline, and is clockwise functions
used by mf2pt1.mp; for proposing the --bpppix command-line option; and, for suggesting
various features and improvements to mf2pt1. Thanks also go to Werner Lemberg and
Boguslaw Jackowski for updating the is clockwise function in mf2pt1.mp to work around a
bug in MetaPost which relates to the turningnumber command. Finally, thanks go to Ralf
Stubner for providing the T1 encoding vector and for pointing out a typo in the generated
font programs; to Michael Zedler for alerting me to problems with --encoding and sug-
gesting I modify that option to accept PostScript .enc files; and to Michael Ummels for
fixing a couple of bugs that made character widths in the generated fonts slightly too large.