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:
- The font size.
- All relevant values from the TTF file (Ascender, Descender, Line Gap, etc.)
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).