ZF-1993: Font Width for 14 standard fonts


When looking through the Zend_Pdf library, I noticed that the font width's for glyphs used synthetic numbers and not the actual widths. I recently looked up the numbers on Adobe's site: http://www.adobe.com/devnet/font/ (In particular I used the UNIX specs), and changed the values accordingly. This aids in doing things such as centering and positioning text.

Attached is the corresponding patch.

This patch is against Zend Framework Release 1.0.1 (build 5906).

Thanks, Logan Buesching


Corresponding patch which updates the glyph width values.

Attached file

The glyph widths themselves are not synthetic -- they are taken directly from the same Adobe core 14 AFM (Adobe Font Metrics) files you were looking at.

What is synthesized are the glyph numbers. If you look a bit farther down in these classes, you'll see an array called {{$cmapData}}, which is the character code-to-glyph mapping array. This array translates Unicode code points (characters) to the appropriate glyph numbers for the font.

For custom fonts (currently only OpenType, though Type 1 support is on the roadmap), the glyph widths and character-to-glyph map are read from the font itself. These metrics data are then included in the generated PDF document.

Since every PDF viewer is required to support the standard 14 PDF fonts (Helvetica, Times, Courier, Symbol, and Zapf Dingbats), none of the metrics data needs to be written to the PDF, so the glyph numbers that are used by the framework are for internal-use only and so the specific numbers used are not important.

Look at the {{$cmapData}} values: you will see that character code U+0020 SPACE ({{0x20}}) is mapped to glyph number {{0x01}}, which has a width is {{0x0116}}. Character code U+003F QUESTION MARK {{0x3f}} is mapped to glpyh number {{0x20}}, with a width of {{0x0263}}.

You were probably getting incorrect width calculations because you were asking for the wrong widths. In your patch, you have confused character codes with glyph numbers. Characters and glyphs are related, but totally distinct concepts. A good primer can be found here: http://developer.apple.com/documentation/Cocoa/…

Calculating the width of a string requires two steps. You must first convert the abstract characters to concrete glyphs (the typesetting phase), then calculate the widths of those glyphs. There is a function in ZF-313 which shows you how to do this.

Please evaluate and categorize as necessary.