views:

347

answers:

2

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).

A: 

I'm not entirely sure what it is you are trying to do, but it sounds like you want to embed true type fonts in a pdf document. If that is the case, why don't you just use latex?

http://www.radamir.com/tex/ttf-tex.htm

blackkettle
+2  A: 

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.

Tarsier
Fonts like Courier New on Windows have a 0 in Line Gap, have you dealt with those at all?
Martin
Nice research, but from what I understand, in PDF parlance, leading is actually defined as the distance from the previous baseline to the current baseline. In other words, you can use the baseline-to-baseline distance calculation in the OpenType specification directly.
WCWedin