I am generating pdf file of true type font in vb6. For true type font we have to mention an array named Widths in font dictionary. I am facing difficulty in getting values for widths array for all fonts. Can any one please help me...?
In a comment the OP explained
Actually I downloaded a project file from http://www.luigimicco.altervista.org/doku.php/vbpdf here. In this he is generating pdf of true type fonts. In clsPDFCreator class, he is calling a function named CreateFontTimes which will write the widths array value. In this function he has mentioned the array values for Time New Roman font. Like wise can I also mention array values for other fonts.
The method CreateFontTimes
(and similarly multiple other ones for a selection of other fonts) return an object which contains multiple properties of the respective font, among them a Widths
array which is initialized from a hard coded array like this for pdfFontStyle.pdfNormal
:
awTemp = New Int16() {0, 250, 333, 408, 500, 500, 833, 778, 180, 333, 333, 500, 564, 250, 333, 250, 278, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 278, 278, 564, 564, 564, 444, 921, 722, 667, 667, 722, 611, 556, 722, 722, 333, 389, 722, 611, 889, 722, 722, 556, 722, 667, 556, 611, 722, 722, 944, 722, 722, 611, 333, 278, 333, 469, 500, _
333, 444, 500, 444, 500, 444, 333, 500, 500, 278, 278, 500, 278, 778, 500, 500, 500, 500, 333, 389, 278, 500, 500, 722, 500, 500, 444, 480, 200, 480, 541, 778, 500, 778, 333, 500, 444, 1000, 500, 500, 333, 1000, 556, 333, 889, 778, 611, 778, 778, 333, 333, 444, 444, 350, 500, 1000, 333, 980, 389, 333, 722, 778, 444, 722, _
250, 333, 500, 500, 500, 500, 200, 500, 333, 760, 276, 500, 564, 333, 760, 500, 400, 549, 300, 300, 333, 576, 453, 250, 333, 300, 310, 500, 750, 750, 750, 444, 722, 722, 722, 722, 722, 722, 889, 667, 611, 611, 611, 611, 333, 333, 333, 333, 722, 722, 722, 722, 722, 722, 722, 564, 722, 722, 722, 722, 722, 722, 556, 500, _
444, 444, 444, 444, 444, 444, 667, 444, 444, 444, 444, 444, 278, 278, 278, 278, 500, 500, 500, 500, 500, 500, 500, 549, 500, 500, 500, 500, 500, 500, 500, 500}
Now the OP apparently wants to create similar methods for other fonts and wonders how to retrieve the width information.
First of all you need to know the order in which the widths appear in this array. This actually is pretty simple, in CreateFontTimes
itself you see that the index of the first and last width are set:
.FirstChar = 32
.LastChar = 255
And in the calling method LoadFont
you see that the fonts are imported into the PDF with
"/Encoding /WinAnsiEncoding"
and this encoding is specified in the PDF specification in Annex D.2 "Latin Character Set and Encodings" in the column "CHAR CODE (OCTAL)/WIN".
For some reason (probably for ease of maintenance of both the VB6 and the newer version in parallel) there is a leading entry 0 in the array above which later is ignored.
Thus, the order in the array is
0
width of *space* " "
width of *exclam* "!"
width of *quotedbl* """
width of *numbersign* "#"
width of *dollar* "$"
width of *percent* "%"
width of *ampersand* "&"
...
One option to retrieve the widths of a glyph is opening the font file in question in a font editor like font forge and copying the width manually. By double clicking the glyph you see the drawing instructions for it, e.g. for the ampersand this
Following the arrow you find the width, 1593 in this case.
You have to scale this value before using it in vbpdf, though, as PDF fonts usually assume an em width of 1000 while font files may have a different measure which you find in the font information dialog on the "General" tab:
Thus, you have to divide the 1593 by 2048 and then multiply by 1000 which results in 777.83203125 which in the array above is rounded to 778:
awTemp = New Int16() {0, 250, 333, 408, 500, 500, 833, 778, 180, 333, 333, 500, 564, 250, 333, 250, 278, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 278, 278, 564, 564, 564, 444, 921, 722, 667, 667, 722, 611, 556, 722, 722, 333, 389, 722, 611, 889, 722, 722, 556, 722, 667, 556, 611, 722, 722, 944, 722, 722, 611, 333, 278, 333, 469, 500, _
^^^
Obviously looking up the widths manually is quite a boring task which you can speed up by using a program for it. You'll find functions of interest on msdn, e.g.