113 lines (96 with data), 7.9 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:/usr/local/lib/python2.5/site-packages/matplotlib/afm.py">/usr/local/lib/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) copyighted 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 <jdhunter@ace.bsd.uchicago.edu></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_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 is<br>
the ink height (space is 0)</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 and<br>
c2</tt></dd></dl>
<dl><dt><a name="AFM-get_name_char"><strong>get_name_char</strong></a>(self, c)</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_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-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<br>
Return value is a (dhead, dcmetrics, dkernpairs, dcomposite) tuple where<br>
<br>
dhead : a parse_header dict<br>
dcmetrics : a parse_composites dict<br>
dkernpairs : a parse_kern_pairs dict, possibly {}<br>
dcomposite : a parse_composites dict , possibly {}</tt></dd></dl>
</td></tr></table>
@footer@