# `glyf`: Glyph Data table

The `glyf` table is an OpenType table.

class fontTools.ttLib.tables._g_l_y_f.table__g_l_y_f(tag=None)

  Bases: `DefaultTable`

  Glyph Data table

  This class represents the glyf table, which contains outlines for glyphs in TrueType format. In many cases, it is easier to access and manipulate glyph outlines through the `GlyphSet` object returned from `fontTools.ttLib.ttFont.getGlyphSet()`:

      >> from fontTools.pens.boundsPen import BoundsPen
      >> glyphset = font.getGlyphSet()
      >> bp = BoundsPen(glyphset)
      >> glyphset["A"].draw(bp)
      >> bp.bounds
      (19, 0, 633, 716)

  However, this class can be used for low-level access to the `glyf` table data. Objects of this class support dictionary-like access, mapping glyph names to `Glyph` objects:

      >> glyf = font["glyf"]
      >> len(glyf["Aacute"].components)
      2

  Note that when adding glyphs to the font via low-level access to the `glyf` table, the new glyphs must also be added to the `hmtx`/`vmtx` table:

      >> font["glyf"]["divisionslash"] = Glyph()
      >> font["hmtx"]["divisionslash"] = (640, 0)

  setGlyphOrder(glyphOrder)

    Sets the glyph order

    Parameters:

      glyphOrder ([str]) – List of glyph names in order.

  getGlyphName(glyphID)

    Returns the name for the glyph with the given ID.

    Raises a `KeyError` if the glyph name is not found in the font.

  getGlyphID(glyphName)

    Returns the ID of the glyph with the given name.

    Raises a `ValueError` if the glyph is not found in the font.

  removeHinting()

    Removes TrueType hints from all glyphs in the glyphset.

    See `Glyph.removeHinting()`.

  getPhantomPoints(glyphName, ttFont, defaultVerticalOrigin=None)

    Old public name for self._getPhantomPoints(). See: https://github.com/fonttools/fonttools/pull/2266

  getCoordinatesAndControls(glyphName, ttFont, defaultVerticalOrigin=None)

    Old public name for self._getCoordinatesAndControls(). See: https://github.com/fonttools/fonttools/pull/2266

  setCoordinates(glyphName, ttFont)

    Old public name for self._setCoordinates(). See: https://github.com/fonttools/fonttools/pull/2266

class fontTools.ttLib.tables._g_l_y_f.Glyph(data=b'')

  Bases: `object`

  This class represents an individual TrueType glyph.

  TrueType glyph objects come in two flavours: simple and composite. Simple glyph objects contain contours, represented via the `.coordinates`, `.flags`, `.numberOfContours`, and `.endPtsOfContours` attributes; composite glyphs contain components, available through the `.components` attributes.

  Because the `.coordinates` attribute (and other simple glyph attributes mentioned above) is only set on simple glyphs and the `.components` attribute is only set on composite glyphs, it is necessary to use the `isComposite()` method to test whether a glyph is simple or composite before attempting to access its data.

  For a composite glyph, the components can also be accessed via array-like access:

      >> assert(font["glyf"]["Aacute"].isComposite())
      >> font["glyf"]["Aacute"][0]
      <fontTools.ttLib.tables._g_l_y_f.GlyphComponent at 0x1027b2ee0>

  recalcBounds(glyfTable, *, boundsDone=None)

    Recalculates the bounds of the glyph.

    Each glyph object stores its bounding box in the `xMin`/`yMin`/`xMax`/`yMax` attributes. These bounds must be recomputed when the `coordinates` change. The `table__g_l_y_f` bounds must be provided to resolve component bounds.

  tryRecalcBoundsComposite(glyfTable, *, boundsDone=None)

    Try recalculating the bounds of a composite glyph that has certain constrained properties. Namely, none of the components have a transform other than an integer translate, and none uses the anchor points.

    Each glyph object stores its bounding box in the `xMin`/`yMin`/`xMax`/`yMax` attributes. These bounds must be recomputed when the `coordinates` change. The `table__g_l_y_f` bounds must be provided to resolve component bounds.

    Return True if bounds were calculated, False otherwise.

  isComposite()

    Test whether a glyph has components

  getCoordinates(glyfTable, *, round=<function noRound>)

    Return the coordinates, end points and flags

    This method returns three values: A `GlyphCoordinates` object, a list of the indexes of the final points of each contour (allowing you to split up the coordinates list into contours) and a list of flags.

    On simple glyphs, this method returns information from the glyph’s own contours; on composite glyphs, it “flattens” all components recursively to return a list of coordinates representing all the components involved in the glyph.

    To interpret the flags for each point, see the “Simple Glyph Flags” section of the glyf table specification <https://docs.microsoft.com/en-us/typography/opentype/spec/glyf#simple-glyph-description>.

  getComponentNames(glyfTable)

    Returns a list of names of component glyphs used in this glyph

    This method can be used on simple glyphs (in which case it returns an empty list) or composite glyphs.

  trim(remove_hinting=False)

    Remove padding and, if requested, hinting, from a glyph. This works on both expanded and compacted glyphs, without expanding it.

  removeHinting()

    Removes TrueType hinting instructions from the glyph.

  draw(pen, glyfTable, offset=0)

    Draws the glyph using the supplied pen object.

    Parameters:

      - pen – An object conforming to the pen protocol.

      - glyfTable – A `table__g_l_y_f` object, to resolve components.

      - offset (int) – A horizontal offset. If provided, all coordinates are translated by this offset.

  drawPoints(pen, glyfTable, offset=0)

    Draw the glyph using the supplied pointPen. As opposed to Glyph.draw(), this will not change the point indices.

class fontTools.ttLib.tables._g_l_y_f.GlyphComponent

  Bases: `object`

  Represents a component within a composite glyph.

  The component is represented internally with four attributes: `glyphName`, `x`, `y` and `transform`. If there is no “two-by-two” matrix (i.e no scaling, reflection, or rotation; only translation), the `transform` attribute is not present.

  getComponentInfo()

    Return information about the component

    This method returns a tuple of two values: the glyph name of the component’s base glyph, and a transformation matrix. As opposed to accessing the attributes directly, `getComponentInfo` always returns a six-element tuple of the component’s transformation matrix, even when the two-by-two `.transform` matrix is not present.

class fontTools.ttLib.tables._g_l_y_f.GlyphCoordinates(iterable=[])

  Bases: `object`

  A list of glyph coordinates.

  Unlike an ordinary list, this is a numpy-like matrix object which supports matrix addition, scalar multiplication and other operations described below.

  property array

    Returns the underlying array of coordinates

  static zeros(count)

    Creates a new `GlyphCoordinates` object with all coordinates set to (0,0)

  copy()

    Creates a new `GlyphCoordinates` object which is a copy of the current one.

  translate(p)

        >>> GlyphCoordinates([(1,2)]).translate((.5,0))

  scale(p)

        >>> GlyphCoordinates([(1,2)]).scale((.5,0))

  transform(t)

        >>> GlyphCoordinates([(1,2)]).transform(((.5,0),(.2,.5)))