RFont

class RFont()

A font object. This object is almost always created with one of the font functions in fontparts-world.

bounds

Return the font bounding box. The font bounding box fits all glyphs.

box

Deprecated: use Font.bounds

preferredSegmentType

Preferred curve type for the default layer.

templateGlyphOrder

Returns the list of glyphNames with template glyphs

templateGlyphs

Return the template glyphs as objects

templateSelectedGlyphNames

A list of all selected template glyphs in the fontwindow

templateSelection

A list of all selected template glyphs in the fontwindow

UIdocument()

changed()

Tell the environment that something has changed in the object. The behavior of this method will vary from environment to environment.

obj.changed()

compileGlyph(glyphName=None, baseName=None, accentNames=[], adjustWidth=False, preflight=False, printErrors=True)

Deprecated: use glyphConstruction

copyGlyphsToPasteboard(glyphNames)

Copy a list of glyph names to the pasteboard.

decompose()

Decompose all glyphs in the font.

document()

Return the document.

extremePoints(round=1)

Add extreme points in all glyphs in the font. Optionally a round value can be provided.

fontWindow()

Return the font window for this font if the font has an interface.

generate(format, path=None, **environmentOptions)

Generate the font to another format.

font.generate("otfcff")
font.generate("otfcff", "/path/to/my/font.otf")

format defines the file format to output. Standard format identifiers can be found in BaseFont.generateFormatToExtension:

Environments are not required to support all of these and environments may define their own format types. path defines the location where the new file should be created. If a file already exists at that location, it will be overwritten by the new file. If path defines a directory, the file will be output as the current file name, with the appropriate suffix for the format, into the given directory. If no path is given, the file will be output into the same directory as the source font with the file named with the current file name, with the appropriate suffix for the format.

Environments may allow unique keyword arguments in this method. For example, if a tool allows decomposing components during a generate routine it may allow this:

font.generate("otfcff", "/p/f.otf", decompose=True)

RoboFont adds additional support for as environmental key words:

  • decompose: decompose while generating the font, this does not change the source data.
  • checkOutlines: removes overlap while generating the font, this does not change the source data.
  • autohint: autothint the generated font
  • releaseMode: set FDK release mode flag while compiling the font
  • glyphOrder: provide a glyphOrder, a list if glyph names
  • progressBar: provide a progress bar
  • layerName: provide a layer name to generate from

generateFormatToExtension(format, fallbackFormat)

   
otf PS OpenType (CFF-based) font (OTF)
ttf PC TrueType/TT OpenType font (TTF)
pfa UNIX ASCII font (ASCII/PFA)
mactype1 Mac Type 1 font (generates suitcase and LWFN file)
macttf Mac TrueType font (generates suitcase)
macttdfont Mac TrueType font (generates suitcase with resources in data fork)
otfcff PS OpenType (CFF-based) font (OTF)
otfttf PC TrueType/TT OpenType font (TTF)
pctype1 PC Type 1 font (binary/PFB)
pcmm PC MultipleMaster font (PFB)
pctype1ascii PC Type 1 font (ASCII/PFA)
pcmmascii PC MultipleMaster font (ASCII/PFA)
ufo1 UFO format version 1
ufo2 UFO format version 2
ufo3 UFO format version 3
unixascii UNIX ASCII font (ASCII/PFA)

getColorForLayer(layerName)

Deprecated: use Font.getLayer(layerName).color

getDisplayOption()

Return the display options for the default layer.

hasChanged()

Return a bool indicating if a font contains changes.

hasInterface()

holdChanges()

Capture changes and bundle them in a single change in a with statement.

newGlyph(name, clear=True)

Make a new glyph with name in the layer.

glyph = layer.newGlyph("A")

The newly created BaseGlyph will be returned.

If the glyph exists in the layer and clear is set to False, the existing glyph will be returned, otherwise the default behavior is to clear the exisiting glyph.

openInterface()

Open the interface for the object

removeOverlap(round=1)

Remove overlap for all glyphs in the font. Optionally a round value can be provided.

renameGlyph(oldName, newName, renameComponents=True, renameGroups=True, renameKerning=True, renameInLayers=True)

Rename a glyph. optionally you can rename this glyph in components, groups, kerning and all layers.

font = CurrentFont()
font.renameGlyph(oldName, newName, renameComponents=True, renameGroups=True, renameKerning=True)

save(path=None, showProgress=False, formatVersion=None, fileStructure=None, removeUnreferencedImages=None)

Save the font to path.

font.save()
font.save("/path/to/my/font-2.ufo")

If path is None, use the font’s original location. The file type must be inferred from the file extension of the given path. If no file extension is given, the environment may fall back to the format of its choice. showProgress indicates if a progress indicator should be displayed during the operation. Environments may or may not implement this behavior. formatVersion indicates the format version that should be used for writing the given file type. For example, if 2 is given for formatVersion and the file type being written if UFO, the file is to be written in UFO 2 format. This value is not limited to UFO format versions. If no format version is given, the original format version of the file should be preserved. If there is no original format version it is implied that the format version is the latest version for the file type as supported by the environment. fileStructure indicates the file structure of the written ufo. The fileStructure can either be None, ‘zip’ or ‘package’, None will use the existing file strucure or the default one for unsaved font. ‘package’ is the default file structure and ‘zip’ will save the font to .ufoz.

.. note

Environments may define their own rules governing when a file should be saved into its original location and when it should not. For example, a font opened from a compiled OpenType font may not be written back into the original OpenType font.

setColorForLayer(layerName, rgba)

Deprecated: use Font.getLayer(layerName).color = r, g, b, a

setDisplayOption(option, value)

Set a display option for the default layer.
option
must be Fill, Stroke, Points, Coordinates or all

setLayerDisplay(layerName, option, value)

Deprecated: use Font.getLayer(layerName).setDisplayOption(option, value)

shallowDocument()

A dummy document. A document is required by some UI views.

showUI()

Deprecated: use openInterface.

templateKeys()

Return the template glyphs names in the font. Template glyphs are not existing glyphs but they are visible in the UI.

testDeinstall()

testInstall(showProgress=True, **environmentOptions)

Test install the font in the local machine.

Optionall environmentOptions can be provided:

decompose: decompose while generating the font, this does not change the source data. checkOutlines: removes overlap while generating the font, this does not change the source data. autohint: autothint the generated font releaseMode: set FDK release mode flag while compiling the font glyphOrder: provide a glyphOrder, a list if glyph names layerName: provide a layer name to generate from

updateComponentReferences(baseGlyphName)

Update all component references.

addObserver(observer, methodName, notification)

Add an observer object. that will receive notification for the given methodName.

asDefcon()

Return the defcon object.

asFontParts()

Return a fontParts object

destroyAllRepresentations(notification=None)

Destroy all representations.

destroyRepresentation(name, **kwargs)

Destroy the stored representation for name and optionally kwargs.

getRepresentation(name, **kwargs)

Get a representation by name.

Optionally arguments could be provided if the representation factory requires arguments.

performUndo()

Create a undo item and add it the the undo manager.

prepareUndo(undoTitle='')

Save the current state of the object.

releaseHeldChanges()

removeObserver(observer, notification)

Remove an observer object for a notification.

undo(undoTitle='')

Capture the current state of the object and create a undo item in a with statement.

Optionally an undoTitle can be provided.

Inherits from subclass: fontParts.fontshell.font.RFont

copyAttributes

defaultLayer

The font’s default layer.

layer = font.defaultLayer
font.defaultLayer = otherLayer

defaultLayerName

The name of the font’s default layer.

font.defaultLayerName = "My Layer 2"
font.defaultLayerName
"My Layer 2"

features

The font’s BaseFeatures object.

font.features.text
"include(features/substitutions.fea);"

glyphOrder

The preferred order of the glyphs in the font.

font.glyphOrder
["C", "B", "A"]
font.glyphOrder = ["A", "B", "C"]

groups

The font’s BaseGroups object.

font.groups["myGroup"]
["A", "B", "C"]

guidelines

An type-immutable-list of font-level BaseGuideline objects.

for guideline in font.guidelines:
...     guideline.angle
0
45
90

info

The font’s BaseInfo object.

font.info.familyName
"My Family"

kerning

The font’s BaseKerning object.

font.kerning["A", "B"]
-100

layerOrder

A list of layer names indicating order of the layers in the font.

font.layerOrder = ["My Layer 2", "My Layer 1"]
font.layerOrder
["My Layer 2", "My Layer 1"]

layers

The font’s BaseLayer objects.

for layer in font.layers:
...     layer.name
"My Layer 1"
"My Layer 2"

lib

The font’s BaseLib object.

font.lib["org.robofab.hello"]
"world"

path

The path to the file this object represents.

print font.path
"/path/to/my/font.ufo"

selectedGuidelines

A list of guidelines selected in the font.

Getting selected guideline objects:

for guideline in font.selectedGuidelines:
...     guideline.color = (1, 0, 0, 0.5)

Setting selected guideline objects:

font.selectedGuidelines = someGuidelines

Setting also supports guideline indexes:

font.selectedGuidelines = [0, 2]

selectedLayerNames

A list of names of layers selected in the layer.

Getting selected layer names:

for name in layer.selectedLayerNames:
...     print(name)

Setting selected layer names:

layer.selectedLayerNames = ["A", "B", "C"]

selectedLayers

A list of layers selected in the layer.

Getting selected layer objects:

for layer in layer.selectedLayers:
...     layer.color = (1, 0, 0, 0.5)

Setting selected layer objects:

layer.selectedLayers = someLayers

tempLib

The font’s BaseLib object.

font.tempLib["org.robofab.hello"]
"world"

selectedGlyphNames

A list of names of glyphs selected in the layer.

Getting selected glyph names:

for name in layer.selectedGlyphNames:
...     print(name)

Setting selected glyph names:

layer.selectedGlyphNames = ["A", "B", "C"]

selectedGlyphs

A list of glyphs selected in the layer.

Getting selected glyph objects:

for glyph in layer.selectedGlyphs:
...     glyph.markColor = (1, 0, 0, 0.5)

Setting selected glyph objects:

layer.selectedGlyphs = someGlyphs

selected

The object’s selection state.

obj.selected
False
obj.selected = True

fileName

Deprecated Font.fileName

selection

Deprecated Font.selection

guides

Deprecated ‘guides’: use ‘guidelines’

naked()

appendGuideline(position=None, angle=None, name=None, color=None, guideline=None)

Append a new guideline to the font.

guideline = font.appendGuideline((50, 0), 90)
guideline = font.appendGuideline((0, 540), 0, name="overshoot",
color=(0, 0, 0, 0.2))

position must be a coordinate indicating the position of the guideline. angle indicates the angle of the guideline. name indicates the name for the guideline. This must be a string or None. color indicates the color for the guideline. This must be a color or None. This will return the newly created BaseGuidline object.

guideline may be a BaseGuideline object from which attribute values will be copied. If position, angle, name or color are specified as arguments, those values will be used instead of the values in the given guideline object.

autoUnicodes()

Use heuristics to set Unicode values in all glyphs.

font.autoUnicodes()

Environments will define their own heuristics for automatically determining values.

This applies only to the default layer.

clearGuidelines()

Clear all guidelines.

font.clearGuidelines()

close(save=False)

Close the font.

font.close()

save is a boolean indicating if the font should be saved prior to closing. If save is True, the BaseFont.save method will be called. The default is False.

copyData(source)

Copy data from source into this font. Refer to BaseFont.copy for a list of values that will be copied.

duplicateLayer(layerName, newLayerName)

Duplicate the layer with layerName, assign newLayerName to the new layer and insert the new layer into the font.

layer = font.duplicateLayer("layer 1", "layer 2")

getCharacterMapping()

Create a dictionary of unicode -> [glyphname, …] mappings. All glyphs are loaded. Note that one glyph can have multiple unicode values, and a unicode value can have multiple glyphs pointing to it.

getFlatKerning()

Get the font’s kerning as a flat dictionary.

getLayer(name)

Get the BaseLayer with name.

layer = font.getLayer("My Layer 2")

getReverseComponentMapping()

Get a reversed map of component references in the font. { ‘A’ : [‘Aacute’, ‘Aring’] ‘acute’ : [‘Aacute’] ‘ring’ : [‘Aring’] etc. }

insertLayer(layer, name=None)

Insert layer into the font.

layer = font.insertLayer(otherLayer, name="layer 2")

This will not insert the layer directly. Rather, a new layer will be created and the data from layer will be copied to to the new layer. name indicates the name that should be assigned to the layer after insertion. If name is not given, the layer’s original name must be used. If the layer does not have a name, an error must be raised. The data that will be inserted from layer is the same data as documented in BaseLayer.copy.

interpolate(factor, minFont, maxFont, round=True, suppressError=True)

Interpolate all possible data in the font.

font.interpolate(0.5, otherFont1, otherFont2)
font.interpolate((0.5, 2.0), otherFont1, otherFont2, round=False)

The interpolation occurs on a 0 to 1.0 range where minFont is located at 0 and maxFont is located at 1.0. factor is the interpolation value. It may be less than 0 and greater than 1.0. It may be a integer/float or a tuple of two integer/float. If it is a tuple, the first number indicates the x factor and the second number indicates the y factor. round indicates if the result should be rounded to integers. suppressError indicates if incompatible data should be ignored or if an error should be raised when such incompatibilities are found.

isCompatible(other)

Evaluate interpolation compatibility with other.

compatible, report = self.isCompatible(otherFont)
compatible
False
report
[Fatal] Glyph: "test1" + "test2"
[Fatal] Glyph: "test1" contains 1 contours | "test2" contains 2 contours

This will return a bool indicating if the font is compatible for interpolation with other and a string of compatibility notes.

newLayer(name, color=None)

Make a new layer with name and color. name must be a string and color must be a color or None.

layer = font.newLayer("My Layer 3")

The will return the newly created BaseLayer.

removeGuideline(guideline)

Remove guideline from the font.

font.removeGuideline(guideline)
font.removeGuideline(2)

guideline can be a guideline object or an integer representing the guideline index.

removeLayer(name)

Remove the layer with name from the font.

font.removeLayer("My Layer 3")

round()

Round all approriate data to integers.

font.round()

This is the equivalent of calling the round method on:

  • info
  • kerning
  • the default layer
  • font-level guidelines

This applies only to the default layer.

swapLayerNames(layerName, otherLayerName)

Assign layerName to the layer currently named otherLayerName and assign the name otherLayerName to the layer currently named layerName.

font.swapLayerNames("before drawing revisions", "after drawing revisions")

__contains__(name)

Test if the layer contains a glyph with name.

"A" in layer
True

insertGlyph(glyph, name=None)

Insert glyph into the layer.

glyph = layer.insertGlyph(otherGlyph, name="A")

This method is deprecated. BaseFont.__setitem__ instead.

keys()

Get a list of all glyphs in the layer.

layer.keys()
["B", "C", "A"]

The order of the glyphs is undefined.

removeGlyph(name)

Remove the glyph with name from the layer.

layer.removeGlyph("A")

This method is deprecated. BaseFont.__delitem__ instead.

getGlyph(glyphName)

getWidth(glyphName)

setChanged()

update()

generateGlyph(*args, **kwargs)

getGlyphNameToFileNameFunc()

getParent()

setParent(parent)

addGuide(position, angle, name=None)

Deprecated: use appendGuideline(position, angle)

clearGuides()

Deprecated: use clearGuidelines()

removeGuide(guideline)

Deprecated: use removeGuideline(guideline)

Last edited on 08/12/2024