This page gives an overview of the differences between the RoboFab and FontParts APIs.

Scripts using the RoboFab API can be updated to the FontParts API with only a few small changes.

API differences

General

RoboFab FontParts
OpenFont(ufoPath, showUI=False) OpenFont(ufoPath, showInterface=False)
*.move((x, y)) *.moveBy((x, y))
*.scale((x, y), center=None) *.scaleBy((x, y), origin=None)
*.skew(value, offset=None) *.skewBy((x, y), origin=None)
*.rotate(value, offset=None) *.rotateBy((x, y), origin=None)
*.update() *.changed()

RFont

RoboFab FontParts
.selection .selectedGlyphNames
.guides .guidelines
.addGuide() .appendGuideline()
.removeGuide() .removeGuideline()
.clearGuides() .clearGuidelines()
.generate(path, format) .generate(format, path)
.compileGlyph() implemented in RF3 (deprecated in FontParts)

compileGlyph was deprecated in FontParts because it was too limited. Glyph Construction was developed as a better, more powerful approach to building glyphs, and is now included as a module in RF3.

RGlyph

RoboFab FontParts
.getLayer('foreground') .getLayer('public.default')
.box .bounds
.mark .markColor
.isCompatible(aGlyph, report) .isCompatible(aGlyph)
.guides .guidelines
.addGuide() .appendGuideline()
.clearGuides() .clearGuidelines()
.autoUnicodes() implemented in RF3 (deprecated in FontParts)
.rasterize() deprecated in RF3 & FontParts

RAnchor

RoboFab FontParts
.position anchor.x, anchor.y

Importing font objects

In RoboFab, the main font objects for the current environment were imported from the robofab.world module:

from robofab.world import RFont, RGlyph # etc

In FontParts, the corresponding objects are found in the fontParts.world module:

from fontParts.world import RFont, RGlyph # etc

FontParts objects are needed only when working outside of RoboFont.

When coding in RoboFont, you can use the native objects from mojo.roboFont instead – see Scripting Environment: Font objects out-of-the-box.

Pens

RoboFab pens were reorganized and moved to other packages.

FontParts does not include pens.

Converter pens now live inside ufoLib, to isolate the implementation of the PointPen infrastructure and protocol. Other pens were moved to the new fontPens package, and other to fontTools.

The following table provides a list of all RoboFab pens and their new locations.

robofab.pens.adapterPens
PointToSegmentPen ufoLib.pointPen.PointToSegmentPen
SegmentToPointPen ufoLib.pointPen.SegmentToPointPen
TransformPointPen fontPens.transformPointPen.TransformPointPen
GuessSmoothPointPen fontPens.guessSmoothPointPen.GuessSmoothPointPen
robofab.pens.angledMarginPen
AngledMarginPen fontPens.angledMarginPen.AngledMarginPen
getAngledMargins fontPens.angledMarginPen.getAngledMargins
setAngledLeftMargin fontPens.angledMarginPen.setAngledLeftMargin
setAngledRightMargin fontPens.angledMarginPen.setAngledRightMargin
centerAngledMargins fontPens.angledMarginPen.centerAngledMargins
guessItalicOffset fontPens.angledMarginPen.guessItalicOffset
robofab.pens.boundsPen
ControlBoundsPen fontTools.pens.boundsPen.ControlBoundsPen
BoundsPen fontTools.pens.boundsPen.BoundsPen
robofab.pens.digestPen
DigestPointPen fontPens.digestPointPen.DigestPointPen
DigestPointStructurePen fontPens.digestPointPen.DigestPointStructurePen
robofab.pens.marginPen
MarginPen fontPens.marginPen.MarginPen
robofab.pens.pointPen
AbstractPointPen ufoLib.pointPen.AbstractPointPen
BasePointToSegmentPen ufoLib.pointPen.BasePointToSegmentPen
PrintingPointPen fontPens.printPointPen.PrintPointPen
SegmentPrintingPointPen fontPens.printPointPen.PrintPointPen
PrintingSegmentPen fontPens.printPen.PrintPen
SegmentPrintingPointPen fontPens.printPen.PrintPen
robofab.pens.printingPens
PrintingPointPen fontPens.printPointPen.PrintPointPen
PrintingSegmentPen fontPens.printPen.PrintPen
SegmentPrintingPointPen fontPens.printPointPen.PrintPointPen
robofab.pens.reverseContourPointPen
ReverseContourPointPen ufoLib.pointPen.ReverseContourPointPen
robofab.pens.filterPen
distance fontPens.penTools.distance
ThresholdPen fontPens.thresholdPen.ThresholdPen
thresholdGlyph fontPens.thresholdPen.thresholdGlyph
_estimateCubicCurveLength fontPens.penTools.estimateCubicCurveLength
_mid fontPens.penTools.middlePoint
_getCubicPoint fontPens.penTools.getCubicPoint
FlattenPen fontPens.flattenPen.FlattenPen
flattenGlyph fontPens.flattenPen.flattenGlyph

Object selection API

FontParts introduces a new object selection API, which offers fine-grained control over selections in different types of objects.

Object Selection Flag

The selected attribute (a boolean) is supported by these objects:

Sub-Object Selected Objects

Objects with sub-objects can now also return a list of selected sub-objects:

Font
font.selectedLayers list of layer objects
font.selectedLayerNames list of strings
font.selectedGlyphs list of glyph objects
font.selectedGlyphNames list of strings
font.selectedGuidelines list of guideline objects
Layer
layer.selectedGlyphs list of glyph objects
layer.selectedGlyphNames list of strings
Glyph
glyph.selectedContours list of contour objects
glyph.selectedComponents list of component objects
glyph.selectedAnchors list of anchor objects
glyph.selectedGuidelines list of guideline objects
Contour
contour.selectedSegments list of segment objects
contour.selectedPoints list of point objects
contour.selectedBPoints list of bPoint objects
Segment
segment.selectedPoints list of point objects

Interface

RoboFab dialogs are also not included in FontParts. Use RoboFont’s mojo.UI module instead.

interface.all.dialogs
Message mojo.UI.Message
AskString mojo.UI.AskString
AskYesNoCancel mojo.UI.AskYesNoCancel
GetFile mojo.UI.GetFile
GetFolder mojo.UI.GetFolder
PutFile mojo.UI.PutFile
SelectFont mojo.UI.SelectFont
SelectGlyph mojo.UI.SelectGlyph
FindGlyph mojo.UI.FindGlyph

Miscellaneous tools

Tools from the robofab.misc module can now be found in fontTools.misc.

robofab.misc.arrayTools
calcBounds fontTools.misc.arrayTools.calcBounds
updateBounds fontTools.misc.arrayTools.updateBounds
pointInRect fontTools.misc.arrayTools.pointInRect
pointsInRect fontTools.misc.arrayTools.pointsInRect
vectorLength fontTools.misc.arrayTools.vectorLength
asInt16 fontTools.misc.arrayTools.asInt16
normRect fontTools.misc.arrayTools.normRect
scaleRect fontTools.misc.arrayTools.scaleRect
offsetRect fontTools.misc.arrayTools.offsetRect
insetRect fontTools.misc.arrayTools.insetRect
sectRect fontTools.misc.arrayTools.sectRect
unionRect fontTools.misc.arrayTools.unionRect
rectCenter fontTools.misc.arrayTools.rectCenter
intRect fontTools.misc.arrayTools.intRect
robofab.misc.bezierTools
calcQuadraticBounds fontTools.misc.bezierTools.calcQuadraticBounds
calcCubicBounds fontTools.misc.bezierTools.calcCubicBounds
splitLine fontTools.misc.bezierTools.splitLine
splitQuadratic fontTools.misc.bezierTools.splitQuadratic
splitCubic fontTools.misc.bezierTools.splitCubic
splitQuadraticAtT fontTools.misc.bezierTools.splitQuadraticAtT
splitCubicAtT fontTools.misc.bezierTools.splitCubicAtT
solveQuadratic fontTools.misc.bezierTools.solveQuadratic
solveCubic fontTools.misc.bezierTools.solveCubic

glifLib

Tools from the robofab.glifLib module (used for reading and writing .glif files) now live in ufoLib.glifLib.

robofab.glifLib
GlyphSet ufoLib.glifLib.GlyphSet
readGlyphFromString ufoLib.glifLib.readGlyphFromString
writeGlyphToString ufoLib.glifLib.writeGlyphToString
glyphNameToFileName ufoLib.glifLib.glyphNameToFileName

Last edited on 15/05/2018