17.05.2014 Views

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.2 Font Metrics and Text Variations<br />

6.2.1 Font and Glyph Metrics<br />

Text position. <strong>PDFlib</strong> maintains the text position independently from the current<br />

point for drawing graphics. While the former can be queried via the textx/texty parameters,<br />

the latter can be queried via currentx/currenty.<br />

Glyph metrics. <strong>PDFlib</strong> uses the glyph and font metrics system used by PostScript and<br />

PDF which shall be briefly discussed here.<br />

The font size which must be specified by <strong>PDFlib</strong> users is the minimum distance between<br />

adjacent text lines which is required to avoid overlapping character parts. The<br />

font size is generally larger than individual characters in a font, since it spans ascender<br />

and descender, plus possibly additional space between lines.<br />

The leading (line spacing) specifies the vertical distance between the baselines of adjacent<br />

lines of text. By default it is set to the value of the font size. The capheight is the<br />

height of capital letters such as T or H in most Latin fonts. The xheight is the height of<br />

lowercase letters such as x in most Latin fonts. The ascender is the height of lowercase<br />

letters such as f or d in most Latin fonts. The descender is the distance from the baseline<br />

to the bottom of lowercase letters such as j or p in most Latin fonts. The descender is<br />

usually negative. The values of xheight, capheight, ascender, and descender are measured<br />

as a fraction of the font size, and must be multiplied with the required font size before<br />

being used.<br />

The gaplen property is only available in TrueType and OpenType fonts (it will be estimated<br />

for other font formats). The gaplen value is read from the font file, and specifies<br />

the difference between the recommended distance between baselines and the sum of<br />

ascender and descender.<br />

<strong>PDFlib</strong> may have to estimate one or more of these values since they are not guaranteed<br />

to be present in the font or metrics file. In order to find out whether real or estimated<br />

values are used you can call info_font( ) to query the xheight with the option faked.<br />

The character metrics for a specific font can be queried from <strong>PDFlib</strong> as follows:<br />

font = p.load_font("Times-Roman", "unicode", "");<br />

capheight = p.info_font(font, "capheight", "");<br />

ascender = p.info_font(font, "ascender", "");<br />

Fig. 6.1 Font and character metrics<br />

font size<br />

capheight<br />

ascender<br />

baseline<br />

descender<br />

152 Chapter 6: Text Output (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!