# pens: Inspect and manipulate glyph outlines

## Overview:

The fontTools pens are a collection of classes that can operate on a font glyph via the points and the contours of the glyph’s outlines.

Some pens trace through the outlines and generate graphical output, such as a new glyph outline or a formatted image, but other pens analyze the outlines and return information about the glyph.

Pens that alter or produce a pen-compatible `ttGlyph` object can be chained together by calling he `draw()` method of each glyph object, in turn, with a subsequent pen argument.

The majority of the pens process glyph outlines in a segment-oriented manner, meaning that they operate by processing the Bezier segments of each glyph or glyph component in sequential order. This model corresponds to the way that glyph data is stored in both TrueType-flavored and CFF-flavored OpenType fonts; the documentation often refers to pens of this type as SegmentPens.

New pens can be written by sub-classing the `AbstractPen` or, somewhat more practically, `BasePen` classes. The general Pen Protocol is documented on the basePen page:

- basePen: Base classes for segment-oriented pens
  - `AbstractPen`
  - `NullPen`
  - `BasePen`
  - `PenError`
  - `decomposeSuperBezierSegment()`
  - `decomposeQuadraticSegment()`

There are also several “point-oriented” pens in the collection. These pens serve to interpret the storage format used in Unified Font Object (UFO) source files, which records all of the points of each contour in sequential order, rather than as Bezier-curve segments. Thus, these PointPens operate only on sequences of points.

UFO’s point-only file format can be deterministically converted into segment-oriented form and vice-versa; therefore all pens are available to be used with UFO sources. General examples can be found on the pointPen page:

- pointPen: Point-oriented pen classes
  - PointPens
  - `AbstractPointPen`
  - `BasePointToSegmentPen`
  - `PointToSegmentPen`
  - `SegmentToPointPen`
  - `GuessSmoothPointPen`
  - `ReverseContourPointPen`
  - `ReverseFlipped`

but there are also `-PointPen` variants available for several of the other pens, included alongside the modules for their segment-oriented version.

## Pen modules

Note:

  Some of the platform-specific pen modules rely on importing external Python libraries; these cases are noted on the relevant pen modules’ pages.

- areaPen
  - `AreaPen`
- boundsPen
  - `BoundsPen`
  - `ControlBoundsPen`
- cu2quPen
  - `Cu2QuPen`
  - `Cu2QuPointPen`
  - `Cu2QuMultiPen`
- filterPen
  - `FilterPen`
  - `ContourFilterPen`
  - `FilterPointPen`
  - `DecomposingFilterPen`
  - `DecomposingFilterPointPen`
  - `ContourFilterPointPen`
  - `OnCurveFirstPointPen`
- momentsPen
  - `MomentsPen`
- perimeterPen
  - `PerimeterPen`
- pointInsidePen
  - `PointInsidePen`
- recordingPen
  - `replayRecording()`
  - `RecordingPen`
  - `DecomposingRecordingPen`
  - `DecomposingRecordingPointPen`
  - `RecordingPointPen`
  - `lerpRecordings()`
- reverseContourPen
  - `reversedContour()`
  - `ReverseContourPen`
- roundingPen
  - `RoundingPen`
  - `RoundingPointPen`
- statisticsPen
  - `StatisticsPen`
  - `StatisticsControlPen`
- svgPathPen
  - `pointToString()`
  - `SVGPathPen`
  - `main()`
- t2CharStringPen
  - `T2CharStringPen`
- teePen
  - `TeePen`
- transformPen
  - `TransformPen`
  - `TransformPointPen`
- ttGlyphPen
  - `TTGlyphPen`
  - `TTGlyphPointPen`

- cairoPen
  - `CairoPen`
- cocoaPen
  - `CocoaPen`
- freetypePen
  - `FreeTypePen`
- qtPen
  - `QtPen`
- quartzPen
  - `QuartzPen`
- reportLabPen
  - `ReportLabPen`
- wxPen
  - `WxPen`