@header@
 
 
matplotlib.afm
index
/home/jdhunter/dev/lib64/python2.5/site-packages/matplotlib/afm.py

This is a python interface to Adobe Font Metrics Files.  Although a
number of other python implementations exist (and may be more complete
than mine) I decided not to go with them because either they were
either
 
  1) copyrighted or used a non-BSD compatible license
 
  2) had too many dependencies and I wanted a free standing lib
 
  3) Did more than I needed and it was easier to write my own than
     figure out how to just get what I needed from theirs
 
It is pretty easy to use, and requires only built-in python libs::
 
    >>> from afm import AFM
    >>> fh = file('ptmr8a.afm')
    >>> afm = AFM(fh)
    >>> afm.string_width_height('What the heck?')
    (6220.0, 683)
    >>> afm.get_fontname()
    'Times-Roman'
    >>> afm.get_kern_dist('A', 'f')
    0
    >>> afm.get_kern_dist('A', 'y')
    -92.0
    >>> afm.get_bbox_char('!')
    [130, -9, 238, 676]
    >>> afm.get_bbox_font()
    [-168, -218, 1000, 898]
 
 
AUTHOR:
  John D. Hunter <jdh2358@gmail.com>

 
Modules
       
os
sys

 
Classes
       
AFM

 
class AFM
     Methods defined here:
__init__(self, fh)
Parse the AFM file in file object *fh*
get_angle(self)
Return the fontangle as float
get_bbox_char(self, c, isord=False)
get_capheight(self)
Return the cap height as float
get_familyname(self)
Return the font family name, eg, 'Times'
get_fontname(self)
Return the font name, eg, 'Times-Roman'
get_fullname(self)
Return the font full name, eg, 'Times-Roman'
get_height_char(self, c, isord=False)
Get the height of character *c* from the bounding box.  This
is the ink height (space is 0)
get_horizontal_stem_width(self)
Return the standard horizontal stem width as float, or *None* if
not specified in AFM file.
get_kern_dist(self, c1, c2)
Return the kerning pair distance (possibly 0) for chars *c1*
and *c2*
get_kern_dist_from_name(self, name1, name2)
Return the kerning pair distance (possibly 0) for chars
*name1* and *name2*
get_name_char(self, c, isord=False)
Get the name of the character, ie, ';' is 'semicolon'
get_str_bbox(self, s)
Return the string bounding box
get_str_bbox_and_descent(self, s)
Return the string bounding box
get_underline_thickness(self)
Return the underline thickness as float
get_vertical_stem_width(self)
Return the standard vertical stem width as float, or *None* if
not specified in AFM file.
get_weight(self)
Return the font weight, eg, 'Bold' or 'Roman'
get_width_char(self, c, isord=False)
Get the width of the character from the character metric WX
field
get_width_from_char_name(self, name)
Get the width of the character from a type1 character name
get_xheight(self)
Return the xheight as float
string_width_height(self, s)
Return the string width (including kerning) and string height
as a (*w*, *h*) tuple.

 
Functions
       
parse_afm(fh)
Parse the Adobe Font Metics file in file handle *fh*. Return value
is a (*dhead*, *dcmetrics*, *dkernpairs*, *dcomposite*) tuple where
*dhead* is a :func:`_parse_header` dict, *dcmetrics* is a
:func:`_parse_composites` dict, *dkernpairs* is a
:func:`_parse_kern_pairs` dict (possibly {}), and *dcomposite* is a
:func:`_parse_composites` dict (possibly {})

 
Data
        uni2type1 = {32: 'space', 33: 'exclam', 34: 'quotedbl', 35: 'numbersign', 36: 'dollar', 37: 'percent', 38: 'ampersand', 39: 'quotesingle', 40: 'parenleft', 41: 'parenright', ...}
@footer@