#5 Kerning support

open
nobody
None
5
2009-09-03
2009-09-03
H. von Bargen
No

We now have kerning support for TrueType fonts.
It should be quite easy (I think) to add kerning for Type1 (AFM) fonts as well.
I estimate this could be done within 1 or 2 days.
However, there's a little difference in comparison with TTF:
For TTF fonts, the kerning info is already present when RL has loaded the font.
For AFM, RL extracts only the information it needs, not the kerning info (KP, KPX). So it seems necessary to monkey patch RL to avoid parsing the file a second time.
Here the relevant excerpt from the Adobe's AFM specification (see Adobe website http://www.adobe.com\):
"""
Kerning Data ... (Optional.) ... The section is delimited by the lines StartKernData and
EndKernData. Kerning data is supplied in two forms: track kerning and pairwise
kerning. They are treated as subsections within the kerning data section
and both sections need not be present.
...
Pairs-Wise Kerning
The pair-wise kerning data is surrounded by the keywords:
StartKernPairs integer
EndKernPairs
StartKernPairs0 integer
EndKernPairs
StartKernPairs1 integer
EndKernPairs
(Required if pair-wise kerning data are present.) integer indicates the number
of pairs to expect. StartKernPairs and StartKernPairs0 denote writing
direction 0; StartKernPairs1 denotes writing direction 1. An AFM file can
contain pair-wise kerning data for more than one writing direction, each
delimited by the StartKernPairs0 or StartKernPairs1 ... EndKernPairs.
There is one kerning pair per line. Each line begins with a keyword of the
form KP, KPH, KPX, or KPY.
KP name1 name2 numberx numbery
Name of the first character in the kerning pair followed by the name of the
second character followed by the kerning vector specified as an (x, y) pair.
The kerning vector is the amount by which to move the second character
relative to the first character to position it properly. The kerning vector is
specified in the standard character coordinate system. As with all metrics, in
order to use this vector it is necessary to scale it by (current point size)/1000.
KPH <hex1> <hex2> numberx numbery
Same as KP, but the byte strings needed to generate the characters are given,
rather than the names. hex1 and hex2 are hexadecimal values, enclosed in
angle brackets.
KPX name1 name2 numberx
Name of the first character in the kerning pair followed by the name of the
second character followed by the kerning amount in the x direction (y is
zero). The kerning amount is specified in the units of the character coordinate
system.
KPY name1 name2 numbery
Same as KPX, but in the y direction (x is zero).
"""
I think it should be enough to interpret KP and KPX.

Discussion