views:

43

answers:

2

I (think) have every values for Text-Rendering in a PDF.

* Position (Text Matrix)
* FontDescriptor with Widths Array
* FontBBox
* StemV/StemH
* FontName
* Descent
* Ascent
* CapHeight
* XHeight
* ItalicAngle

My problem is I don't know what to do with these values. I went through the PDF Spec 1.7 a couple of times and cannot find a formular to calculate the real pixel sizes of every glyph in PDF. Can you give me a hint?

Thank you.

A: 

These values are designed to properly typeset type, not draw glyphs, so you can't get the exact pixel size of each glyph from these attributes. The only way to get the exact pixel dimensions of a glyph is to draw the glyph into an image and analyze that image.

The FontBBox (font bounding box) is the smallest box that will hold each glyph. The Widths Array holds information on how far apart each character should be drawn, not the actual glyph image size. Some fonts will draw some glyphs outsize that width.

When you highlight text in a typical text editor, the highlight will be the full height of the font, and the width of each individual character. This highlight is made by getting the FontBBox height, and each character's width from the Widths Array, and transforming those values to match the current font's attributes (size, etc.). This information is sufficient to make your app draw type like typical applications.

Mr. Berna
How do i transform FontBBox-values into Device Space values (real pixel values)?
asonico
FontBBox and Widths values are in glyph space as specified by the FontMatrix. Build a transformation matrix by concatenation of the font matrix and the text space, to map FontBBox values to device space.
Mr. Berna
do you have an excact formular for calculating FontBBox-Height + Width-Array to device space, that i can get the character sizes?
asonico
+2  A: 

What are you trying to do? Rendering PDF is a lot of work and you also need to factor in leading, Text raise, kerning, CTM and several other factors.

mark stephens
I am trying to highlight a text. I parsed the PDF sucessfully with the Quartz 2D methods. I think I have every information, now I have to do some Math to find out the "CGRects" of some text/words.
asonico