# afmLib: Read and write Adobe Font Metrics files

## Overview:

> Module for reading and writing AFM (Adobe Font Metrics) files.

> Note that this has been designed to read in AFM files generated by Fontographer and has not been tested on many other files. In particular, it does not implement the whole Adobe AFM specification [1] but, it should read most “common” AFM files.

> Here is an example of using afmLib to read, modify and write an AFM file:

>     >>> from fontTools.afmLib import AFM
>     >>> f = AFM("Tests/afmLib/data/TestAFM.afm")
>     >>>
>     >>> # Accessing a pair gets you the kern value
>     >>> f[("V","A")]
>     -60
>     >>>
>     >>> # Accessing a glyph name gets you metrics
>     >>> f["A"]
>     (65, 668, (8, -25, 660, 666))
>     >>> # (charnum, width, bounding box)
>     >>>
>     >>> # Accessing an attribute gets you metadata
>     >>> f.FontName
>     'TestFont-Regular'
>     >>> f.FamilyName
>     'TestFont'
>     >>> f.Weight
>     'Regular'
>     >>> f.XHeight
>     500
>     >>> f.Ascender
>     750
>     >>>
>     >>> # Attributes and items can also be set
>     >>> f[("A","V")] = -150 # Tighten kerning
>     >>> f.FontName = "TestFont Squished"
>     >>>
>     >>> # And the font written out again (remove the # in front)
>     >>> #f.write("testfont-squished.afm")

> Footnotes

> [1]

> Adobe Technote 5004, Adobe Font Metrics File Format Specification.

## Module members:

exception fontTools.afmLib.error

  Bases: `Exception`

class fontTools.afmLib.AFM(path=None)

  Bases: `object`

  read(path)

    Opens, reads and parses a file.

  parsechar(rest)
  parsekernpair(rest)
  parseattr(word, rest)
  parsecomposite(rest)
  write(path, sep='\r')

    Writes out an AFM font to the given path.

  has_kernpair(pair)

    Returns True if the given glyph pair (specified as a tuple) exists in the kerning dictionary.

  kernpairs()

    Returns a list of all kern pairs in the kerning dictionary.

  has_char(char)

    Returns True if the given glyph exists in the font.

  chars()

    Returns a list of all glyph names in the font.

  comments()

    Returns all comments from the file.

  addComment(comment)

    Adds a new comment to the file.

  addComposite(glyphName, components)

    Specifies that the glyph glyphName is made up of the given components. The components list should be of the following form:

        [
                (glyphname, xOffset, yOffset),
                ...
        ]

fontTools.afmLib.readlines(path)

fontTools.afmLib.writelines(path, lines, sep='\r')