# path

- parser

class fontTools.svgLib.path.SVGPath(filename=None, transform=None)

  Parse SVG `path` elements from a file or string, and draw them onto a glyph object that supports the FontTools Pen protocol.

  For example, reading from an SVG file and drawing to a Defcon Glyph:

  > import defcon glyph = defcon.Glyph() pen = glyph.getPen() svg = SVGPath(“path/to/a.svg”) svg.draw(pen)

  Or reading from a string containing SVG data, using the alternative ‘fromstring’ (a class method):

  > data = ‘<?xml version=”1.0” …’ svg = SVGPath.fromstring(data) svg.draw(pen)

  Both constructors can optionally take a ‘transform’ matrix (6-float tuple, or a FontTools Transform object) to modify the draw output.

  draw(pen)
  classmethod fromstring(data, transform=None)

fontTools.svgLib.path.parse_path(pathdef, pen, current_pos=(0, 0), arc_class=<class 'fontTools.svgLib.path.arc.EllipticalArc'>)

  Parse SVG path definition (i.e. “d” attribute of <path> elements) and call a ‘pen’ object’s moveTo, lineTo, curveTo, qCurveTo and closePath methods.

  If ‘current_pos’ (2-float tuple) is provided, the initial moveTo will be relative to that instead being absolute.

  If the pen has an “arcTo” method, it is called with the original values of the elliptical arc curve commands:

  > pen.arcTo(rx, ry, rotation, arc_large, arc_sweep, (x, y))

  Otherwise, the arcs are approximated by series of cubic Bezier segments (“curveTo”), one every 90 degrees.