Introduction
An Adobe Font Metrics file, .afm, is a plain text file that says how wide each
character of a PostScript font is, how much room it takes, which characters join into ligatures
and how much space to take out between pairs of characters that sit badly together (kerning).
Layout programs read it instead of the font itself: they can set a line of text without loading
the outlines. Adobe published the format as Technical Note #5004, “Adobe Font Metrics File Format
Specification”; the last version, 4.1, is dated 7 October 1998.
On Windows the same information travels in a binary PFM file.
An AFM file goes with a Type 1 font (its .pfb,
.pfa or .t1 file) and carries the same character names as the font. The viewer draws a sample
line with the font’s outlines when the font is dropped together with the metrics file, once
with the file’s kerning and once without.
The note describes three files. The AFM file (StartFontMetrics to
EndFontMetrics) holds the metrics of a base font, or of a composite or CID-keyed
font in one writing direction. The ACFM file (StartCompFontMetrics)
describes the structure of a composite font: its descendent fonts. The AMFM
file (StartMasterFontMetrics) describes a multiple master font: its axes, masters and
primary fonts, while the metrics of each master design are in an AFM file of their own
(Composite, multiple master and CID fonts).
Structure
The file is line oriented: each line starts with a key, followed by its values separated by
spaces or tabs (Syntax and keys). The first line is
StartFontMetrics with the version of the format, the last non-empty line is
EndFontMetrics. In between come, in this order: the control and global information
(FontName, FontBBox, CapHeight and the others), the writing
direction sections, the individual
character metrics, the
kerning data (track kerning and pair kerning) and the
composite characters. Every key is optional
except FontName and FontBBox, and
every character metrics line has the same shape: keys and values separated by semicolons.
StartFontMetrics 3.0
FontName Times-Roman
FontBBox -170 -223 1024 896
StartCharMetrics 228
C 32 ; WX 250 ; N space ; B 0 0 0 0 ;
C 102 ; WX 333 ; N f ; B 20 0 383 682 ; L i fi ; L l fl ;
EndCharMetrics
StartKernData
StartKernPairs 113
KPX A y -92
EndKernPairs
EndKernData
StartComposites 58
CC Aacute 2 ; PCC A 0 0 ; PCC acute 195 214 ;
EndComposites
EndFontMetrics
All measurements are in units of 1/1000 of the font’s point size; a width of 500 in a 12 point font is 6 points.
The viewer
The viewer reads every key of Technical Note #5004 and checks the file against it: the types of the
values, the required keys, the counts that follow each Start key, the ordering rules, the
conflicts the note forbids (IsFixedPitch against CharWidth, IsFixedV against
VVector), the closing keys, and the rules for AMFM and ACFM files (masters, axes, the weight
vector, the descendent ranges). What the note says must be so and is not shows as a problem with its line, and a click
opens the file as text at that line. What the note states and real files often depart from (the order
of the characters, a character box outside FontBBox) shows as a note. The characters, the
kerning pairs, the composites and the keys are listed in tables that open at any length, and the tree covers
every byte.
Not described
Known, not yet covered
- Reference: the mapping schemes of composite fonts (
MappingScheme2, 3 and the others) are defined in section 5.9 of the PostScript Language Reference Manual, second edition, which Technical Note #5004 refers to and these pages did not read; the families page gives only the two examples the note gives. - Reference: Technical Note #5074 (the Adobe Type Manager API for multiple master fonts) and #5088 (font naming), which the note cites for the weight vector and for primary font labels, were not read.
- Viewer: the sample line is drawn for a base font only, in writing direction 0, from
KPXpairs and (by an option) one track kerning degree. It does not apply ligatures (L),KP,KPHorKPYpairs, vertical metrics, or the metrics of a composite or CID-keyed font, and it does not interpolate the metrics of a multiple master instance from the master AFM files (section 3.3 of the note, described on the families page). - Viewer: the character set and encoding names (
CharacterSet,EncodingScheme) are shown, not checked against the characters the file lists, and the character names are not checked against Adobe’s glyph list.
Links
Software
- FontForge – free font editor that reads and writes AFM metrics for Type 1 fonts (Windows, macOS, Linux)
- Ghostscript – PostScript interpreter that uses Type 1 fonts (Windows, macOS, Linux)
- TeX Live – TeX distribution whose tools convert AFM files to TeX font metrics (Windows, macOS, Linux)
Developers
- FreeType – font library that reads an attached AFM file for the metrics of a Type 1 font (C)
- fontTools – font library with an AFM reader (Python)
- Apache PDFBox – PDF library whose FontBox module parses AFM files (Java)
Reference
- Adobe Font Metrics File Format Specification – Adobe Technical Note #5004, version 4.1, 7 October 1998 (PDF)
- PostScript Type 1 font – the outline font an AFM file describes
- Printer Font Metrics – the binary metrics file of the same fonts on Windows