The PDF specification defines a text operator called ' (apostrophe). The definition is that it writes out some text, and moves to the next line based on the current leading state. The current leading state can be set using the TL operator. This makes it very easy to write lines of text if you know how much they should be spaced apart vertically:
16 TL /F1 12 Tf (Line 1) ' (Line 2) ' (Line 3) ' (Line 4) '
I am not using any libraries for this, as it is a learning exercise. I have written some code to directly parse TTF files and extract character widths, and other items that are required for PDF FontDescriptor dictionaries.
I have been reading the TTF file format specification in order to try to figure out where the line height is located or how it can be calculated, but I have had no luck.
Assuming I have the following givens:
How do I calculate PDF leading from TTF?
edit
It appears that the Line Gap value from the TTF file is instrumental in calculating PDF leading, but some fonts do not provide a sensible value for it (Courier New on Windows, for example).
By no means am I the least bit knowledgeable about fonts, or have a definite answer, but I figured I'd post some links regarding some information I found regarding the topic.
The Microsoft OpenType Specification (see the Baseline To Baseline Distances section, toward the bottom) defines leading as being equal to the LineGap.
The Apple Text System Overview states that:
Space added during typesetting between lines of type is called leading, after the slugs of lead used for that purpose in traditional metal-type page layout. (Leading is sometimes also called linegap.)
So, according to these links, LineGap is not just used to calculate the leading, but actually is the leading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With