138 lines (112 with data), 10.4 kB
@header@
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="matplotlib.html"><font color="#ffffff">matplotlib</font></a>.afm</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/jdhunter/dev/lib64/python2.5/site-packages/matplotlib/afm.py">/home/jdhunter/dev/lib64/python2.5/site-packages/matplotlib/afm.py</a></font></td></tr></table>
<p><tt>This is a python interface to Adobe Font Metrics Files. Although a<br>
number of other python implementations exist (and may be more complete<br>
than mine) I decided not to go with them because either they were<br>
either<br>
<br>
1) copyrighted or used a non-BSD compatible license<br>
<br>
2) had too many dependencies and I wanted a free standing lib<br>
<br>
3) Did more than I needed and it was easier to write my own than<br>
figure out how to just get what I needed from theirs<br>
<br>
It is pretty easy to use, and requires only built-in python libs::<br>
<br>
>>> from afm import <a href="#AFM">AFM</a><br>
>>> fh = file('ptmr8a.afm')<br>
>>> afm = <a href="#AFM">AFM</a>(fh)<br>
>>> afm.string_width_height('What the heck?')<br>
(6220.0, 683)<br>
>>> afm.get_fontname()<br>
'Times-Roman'<br>
>>> afm.get_kern_dist('A', 'f')<br>
0<br>
>>> afm.get_kern_dist('A', 'y')<br>
-92.0<br>
>>> afm.get_bbox_char('!')<br>
[130, -9, 238, 676]<br>
>>> afm.get_bbox_font()<br>
[-168, -218, 1000, 898]<br>
<br>
<br>
AUTHOR:<br>
John D. Hunter <jdh2358@gmail.com></tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="os.html">os</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="matplotlib.afm.html#AFM">AFM</a>
</font></dt></dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="AFM">class <strong>AFM</strong></a></font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="AFM-__init__"><strong>__init__</strong></a>(self, fh)</dt><dd><tt>Parse the <a href="#AFM">AFM</a> file in file object *fh*</tt></dd></dl>
<dl><dt><a name="AFM-get_angle"><strong>get_angle</strong></a>(self)</dt><dd><tt>Return the fontangle as float</tt></dd></dl>
<dl><dt><a name="AFM-get_bbox_char"><strong>get_bbox_char</strong></a>(self, c, isord<font color="#909090">=False</font>)</dt></dl>
<dl><dt><a name="AFM-get_capheight"><strong>get_capheight</strong></a>(self)</dt><dd><tt>Return the cap height as float</tt></dd></dl>
<dl><dt><a name="AFM-get_familyname"><strong>get_familyname</strong></a>(self)</dt><dd><tt>Return the font family name, eg, 'Times'</tt></dd></dl>
<dl><dt><a name="AFM-get_fontname"><strong>get_fontname</strong></a>(self)</dt><dd><tt>Return the font name, eg, 'Times-Roman'</tt></dd></dl>
<dl><dt><a name="AFM-get_fullname"><strong>get_fullname</strong></a>(self)</dt><dd><tt>Return the font full name, eg, 'Times-Roman'</tt></dd></dl>
<dl><dt><a name="AFM-get_height_char"><strong>get_height_char</strong></a>(self, c, isord<font color="#909090">=False</font>)</dt><dd><tt>Get the height of character *c* from the bounding box. This<br>
is the ink height (space is 0)</tt></dd></dl>
<dl><dt><a name="AFM-get_horizontal_stem_width"><strong>get_horizontal_stem_width</strong></a>(self)</dt><dd><tt>Return the standard horizontal stem width as float, or *None* if<br>
not specified in <a href="#AFM">AFM</a> file.</tt></dd></dl>
<dl><dt><a name="AFM-get_kern_dist"><strong>get_kern_dist</strong></a>(self, c1, c2)</dt><dd><tt>Return the kerning pair distance (possibly 0) for chars *c1*<br>
and *c2*</tt></dd></dl>
<dl><dt><a name="AFM-get_kern_dist_from_name"><strong>get_kern_dist_from_name</strong></a>(self, name1, name2)</dt><dd><tt>Return the kerning pair distance (possibly 0) for chars<br>
*name1* and *name2*</tt></dd></dl>
<dl><dt><a name="AFM-get_name_char"><strong>get_name_char</strong></a>(self, c, isord<font color="#909090">=False</font>)</dt><dd><tt>Get the name of the character, ie, ';' is 'semicolon'</tt></dd></dl>
<dl><dt><a name="AFM-get_str_bbox"><strong>get_str_bbox</strong></a>(self, s)</dt><dd><tt>Return the string bounding box</tt></dd></dl>
<dl><dt><a name="AFM-get_str_bbox_and_descent"><strong>get_str_bbox_and_descent</strong></a>(self, s)</dt><dd><tt>Return the string bounding box</tt></dd></dl>
<dl><dt><a name="AFM-get_underline_thickness"><strong>get_underline_thickness</strong></a>(self)</dt><dd><tt>Return the underline thickness as float</tt></dd></dl>
<dl><dt><a name="AFM-get_vertical_stem_width"><strong>get_vertical_stem_width</strong></a>(self)</dt><dd><tt>Return the standard vertical stem width as float, or *None* if<br>
not specified in <a href="#AFM">AFM</a> file.</tt></dd></dl>
<dl><dt><a name="AFM-get_weight"><strong>get_weight</strong></a>(self)</dt><dd><tt>Return the font weight, eg, 'Bold' or 'Roman'</tt></dd></dl>
<dl><dt><a name="AFM-get_width_char"><strong>get_width_char</strong></a>(self, c, isord<font color="#909090">=False</font>)</dt><dd><tt>Get the width of the character from the character metric WX<br>
field</tt></dd></dl>
<dl><dt><a name="AFM-get_width_from_char_name"><strong>get_width_from_char_name</strong></a>(self, name)</dt><dd><tt>Get the width of the character from a type1 character name</tt></dd></dl>
<dl><dt><a name="AFM-get_xheight"><strong>get_xheight</strong></a>(self)</dt><dd><tt>Return the xheight as float</tt></dd></dl>
<dl><dt><a name="AFM-string_width_height"><strong>string_width_height</strong></a>(self, s)</dt><dd><tt>Return the string width (including kerning) and string height<br>
as a (*w*, *h*) tuple.</tt></dd></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-parse_afm"><strong>parse_afm</strong></a>(fh)</dt><dd><tt>Parse the Adobe Font Metics file in file handle *fh*. Return value<br>
is a (*dhead*, *dcmetrics*, *dkernpairs*, *dcomposite*) tuple where<br>
*dhead* is a :func:`_parse_header` dict, *dcmetrics* is a<br>
:func:`_parse_composites` dict, *dkernpairs* is a<br>
:func:`_parse_kern_pairs` dict (possibly {}), and *dcomposite* is a<br>
:func:`_parse_composites` dict (possibly {})</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>uni2type1</strong> = {32: 'space', 33: 'exclam', 34: 'quotedbl', 35: 'numbersign', 36: 'dollar', 37: 'percent', 38: 'ampersand', 39: 'quotesingle', 40: 'parenleft', 41: 'parenright', ...}</td></tr></table>
@footer@