The kerning data (section 9 of Adobe Technical Note #5004) appears in the AFM file only and is optional. It is enclosed by StartKernData and
EndKernData, which are required if track or pair kerning are present. The data comes in two forms, which are subsections that can each be present or absent: track kerning, which
applies to all characters uniformly, and pair kerning, which applies to specific pairs. They can be used independently or together: track kerning applied to a line of text,
then pair kerning after it.
Track kerning
Track kerning may be given for the writing directions MetricsSets names. The lines are enclosed by StartTrackKern count and
EndTrackKern, where the count is the number of sets of track kerning data. Normally track kerning comes in different degrees of tightness; within a track the amount to
decrease (or possibly increase) the space between characters grows (or shrinks) with the point size. For tight kerning the decrease at 6 point might be 0.1 points
and at 72 point 3.78 points. The distances are measured along the width of the characters: parallel to the x axis for horizontal writing directions, to the y axis for vertical ones.
TrackKern degree min-ptsize min-kern max-ptsize max-kern
The degree is an integer: increasingly negative degrees are tighter track kerning, increasingly positive degrees looser. The other four are numbers. The track kerning function is linear. With the point size p and the four values p0, k0, p1, k1, the amount k(p) in points is:
- k(p) = k0 for p < p0;
- k(p) = k0 + (k1 − k0) ÷ (p1 − p0) × (p − p0) for p0 ≤ p ≤ p1;
- k(p) = k1 for p > p1.
So below the minimum and above the maximum point size the amount stays constant. The note’s Times-Roman example:
StartTrackKern 3
Comment Light kerning
TrackKern -1 14 0 72 -1.89
Comment Medium kerning
TrackKern -2 8 0 72 -3.2
Comment Tight kerning
TrackKern -3 6 -.1 72 -3.78
EndTrackKern
At 12 points the tight track (degree -3) comes to -0.1 + (−3.78 + 0.1) ÷ 66 × 6 = −0.4345 points added after every character. The viewer lists each track with its amount at 6, 12, 24 and 72 points, and its sample line applies one degree when you choose it in the options.
Pair kerning
The pair data is enclosed by StartKernPairs count (or StartKernPairs0, StartKernPairs1) and
EndKernPairs. StartKernPairs and StartKernPairs0 denote writing direction 0, StartKernPairs1 direction 1; a file can have
pair kerning for more than one direction, each in its own section. The count is the number of pairs to expect. There is one pair on each line, beginning with one of four keys:
| Key | Values | Meaning |
|---|---|---|
KP | name1 name2 x y | The names of the first and second character of the pair, then the kerning vector: the amount by which to move the second character relative to the first, in the standard character coordinate system. Scale it by the point size ÷ 1000. |
KPH | <hex1> <hex2> x y | The same, with the byte strings that generate the characters in angle brackets instead of the names. |
KPX | name1 name2 x | The names, then the kerning amount in the x direction (y is zero), in the units of the character coordinate system. |
KPY | name1 name2 y | The same in the y direction (x is zero). |
KPX V A -129
Set in 100 point type, the pair V A is moved 12.9 points closer together (figure 3 of the note).
Applying the data
The note defines what the numbers mean, not an algorithm for a layout program. The viewer’s sample line (when the Type 1 font is dropped with the AFM file) takes the
advance of each character from its WX, adds the KPX amount of the pair of the two names before drawing the second one, and, when a track degree is chosen, adds k(p) × 1000 ÷ p after every
character, with one point drawn as one pixel. It draws the same text twice, with and without the kerning, so the difference shows.
What the viewer checks: the count after each StartKernPairs and StartTrackKern, the values of every line, that the pair names a character the file has (a note), that
a pair is not given twice (a note), and that the maximum point size of a track is not below its minimum.