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)

The RFont.compileGlyph method was deprecated in FontParts because it was considered too limited.

Glyph Construction is recommended as a more powerful approach to building glyphs. The glyphConstruction module is now embedded in RoboFont 3.

See Building accented glyphs with a script for more information and examples.

RGlyph

RoboFab FontParts
.getLayer('foreground') .getLayer('public.default')
.box .bounds
.mark .markColor
.selection (deprecated in FontParts) see Object selection API
.isCompatible(aGlyph, report) .isCompatible(aGlyph)
.guides .guidelines
.addGuide() .appendGuideline()
.clearGuides() .clearGuidelines()
.autoUnicodes() implemented in RF3 (deprecated in FontParts)
.rasterize() deprecated in RF3 & FontParts
.index 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.

Pens

RoboFab pens were reorganized and moved to other packages.

FontParts does not include pens.

Converter pens were moved into the 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 ufoLib is now part of FontTools. From RoboFont 3.2 onwards, all pens from the ufoLib.pointPen module can also be found in fontTools.pens.pointPen.

The ufoLib module will be deprecated.

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 RLayer objects
font.selectedLayerNames list of layer names (strings)
font.selectedGlyphs list of RGlyph objects
font.selectedGlyphNames list of glyph names (strings)
font.selectedGuidelines list of RGuideline objects
Layer
layer.selectedGlyphs list of RGlyph objects
layer.selectedGlyphNames list of glyph names (strings)
Glyph
glyph.selectedContours list of RContour objects
glyph.selectedComponents list of RComponent objects
glyph.selectedAnchors list of RAnchor objects
glyph.selectedGuidelines list of RGuideline objects
Contour
contour.selectedSegments list of RSegment objects
contour.selectedPoints list of RPoint objects
contour.selectedBPoints list of bPoint objects
Segment
segment.selectedPoints list of RPoint 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.

The ufoLib is now part of FontTools. From RoboFont 3.2 onwards, all tools from the ufoLib.glifLib module can also be found in fontTools.ufoLib.glifLib.

The ufoLib module will be deprecated.

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

Last edited on 01/09/2021