matplotlib._afm#

A Python interface to Adobe Font Metrics Files.

Although a number of other Python implementations exist, and may be morecomplete than this, it was decided not to go with them because they wereeither:

  1. copyrighted or used a non-BSD compatible license

  2. had too many dependencies and a free standing lib was needed

  3. did more than needed and it was easier to write afresh rather thanfigure out how to get just what was needed.

It is pretty easy to use, and has no external dependencies:

>>>importmatplotlibasmpl>>>frompathlibimportPath>>>afm_path=Path(mpl.get_data_path(),'fonts','afm','ptmr8a.afm')>>>>>>frommatplotlib._afmimportAFM>>>withafm_path.open('rb')asfh:...afm=AFM(fh)>>>afm.get_fontname()'Times-Roman'

As in the Adobe Font Metrics File Format Specification, all dimensionsare given in units of 1/1000 of the scale factor (point size) of the fontbeing used.

classmatplotlib._afm.AFM(fh)[source]#

Bases:object

Parse the AFM file in file objectfh.

propertyfamily_name#

The font family name, e.g., 'Times'.

get_angle()[source]#

Return the fontangle as float.

get_capheight()[source]#

Return the cap height as float.

get_char_index(c)[source]#

Return the glyph index corresponding to a character code point.

Note, for AFM fonts, we treat the glyph index the same as the codepoint.

get_familyname()[source]#

Return the font family name, e.g., 'Times'.

get_fontname()[source]#

Return the font name, e.g., 'Times-Roman'.

get_fullname()[source]#

Return the font full name, e.g., 'Times-Roman'.

get_glyph_name(glyph_ind)[source]#

Get the name of the glyph, i.e., ord(';') is 'semicolon'.

get_kern_dist_from_name(name1,name2)[source]#

Return the kerning pair distance (possibly 0) for charsname1 andname2.

get_str_bbox_and_descent(s)[source]#

Return the string bounding box and the maximal descent.

get_underline_thickness()[source]#

Return the underline thickness as float.

get_weight()[source]#

Return the font weight, e.g., 'Bold' or 'Roman'.

get_width_char(c)[source]#

Get the width of the character code from the character metric WX field.

get_width_from_char_name(name)[source]#

Get the width of the character from a type1 character name.

get_xheight()[source]#

Return the xheight as float.

propertypostscript_name#
classmatplotlib._afm.CharMetrics(width,name,bbox)[source]#

Bases:tuple

Represents the character metrics of a single character.

Notes

The fields do currently only describe a subset of character metricsinformation defined in the AFM standard.

Create new instance of CharMetrics(width, name, bbox)

bbox#

The bbox of the character (B) as a tuple (llx,lly,urx,ury).

name#

The character name (N).

width#

The character width (WX).

classmatplotlib._afm.CompositePart(name,dx,dy)[source]#

Bases:tuple

Represents the information on a composite element of a composite char.

Create new instance of CompositePart(name, dx, dy)

dx#

x-displacement of the part from the origin.

dy#

y-displacement of the part from the origin.

name#

Name of the part, e.g. 'acute'.