RFont

class RFont()

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

box

Deprecated: use Font.bounds

preferredSegmentType

Preferred curve type for the default layer.

selection

A list of all selected glyphs in the fontwindow

templateGlyphOrder

Returns the list of glyphNames with template glyphs

templateGlyphs

Return the template glyphs as objects

templateSelection

A list of all selected template glyphs in the fontwindow

UIdocument()

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

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

Deprecated: use glyphConstruction

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.

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.

hasInterface()

newGlyph(name, clear=None)

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, renameGlyphOrder=True)

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

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

save(path=None, showProgress=False, formatVersion=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.

.. 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)

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()

Test install the font in the local machine.

updateComponentReferences(baseGlyphName)

Update all component references.

addObserver(observer, methodName, notification)

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

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.

removeObserver(observer, notification)

Remove an observer object for a notification.

changed()

Notifiy the object has changed.

Inherits from subclass: fontParts.fontshell.font.RFont

copyAttributes

defaultLayer

The name of the font’s default layer.

>>> font.defaultLayer = "My Layer 2"
>>> font.defaultLayer
"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

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

fileName

Deprecated Font.fileName

selected

The object’s selection state.

>>> obj.selected
False
>>> obj.selected = True

guides

Deprecated ‘guides’: use ‘guidelines’

naked()

appendGuideline(position, angle, name=None, color=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.

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.

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

Generate the font to another format.

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

format defines the file format to output. These are the standard format identifiers:

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)

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.

getCharacterMapping()

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

getLayer(name)

Get the BaseLayer with name.

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

getReverseComponentMapping()

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.

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.

__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 does not necessarily insert the glyph directly. In many cases, the environment will create a new glyph and copy the data from glyph to the new glyph. name indicates the name that should be assigned to the glyph after insertion. If name is not given, the glyph’s original name must be used. If the glyph does not have a name, an error must be raised. The data that will be inserted from glyph is the same data as documented in BaseGlyph.copy.

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")

getParent()

getGlyph(glyphName)

getWidth(glyphName)

setChanged()

update()

generateGlyph(*args, **kwargs)

getGlyphNameToFileNameFunc()

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 15/05/2018