RFont()

Usage

# robofab manual
#    Font object
#    Usage examples
# start using the current font
from robofab.world import CurrentFont
f = CurrentFont()

# get a clean, empty new font object,
# appropriate for the current environment
f = robofab.world.RFont()

# get an open dialog and start a new font
f = OpenFont()

# open the font at path
f = OpenFont(path)
➔ Download this.

Description

Perhaps the first object you get to play with. The RFont object is the central part that connects all glyphs with font information (like names, key dimensions etc.). In FontLab the RFont object talks directly to the glyphs and font data in the FontLab font it belongs to. In UFO or NoneLab use, the RFont object contains the data and saves it to UFO. RFont object behave like dictionaries: the glyphname is the key and the returned value is a RGlyph object for that glyph. If the glyph does not exist RFont will raise an IndexError.

RFont has a couple of important sub-objects which are worth checking out. The font's kerning is stored in a RKerning object and can be reached as an attribute at RFont.kerning. Fontnames, key dimensions, flags etc are stored in a RInfo object which is available through RFont.info. The RFont.lib is an RLib object which behaves as a dictionary.

Iterating

One of the most important uses of the RFont object is that it makes it really easy to iterate ("step through") the glyphs in the font.

# robofab manual
#    Font object
#    Iterate through the font object
#    to get to the glyphs.

f = CurrentFont()
for glyph in f:
    print glyph.name

➔ Download this.
a
b
c
..etc..
This makes the code clear and simple.

FontLab / UFO

All basic attributes, methods and behaviour for RFont objects created in FontLab or in NoneLab are identical. However, the RFont objects in FontLab have some additional attributes and methods that make special FontLab functionality available. These extra methods and attributes are listed seperately below.

RFont Attributes

Attribute examples

# robofab manual
# Font object
#    attribute examples

# Most useful attributes of RFont are
# actually stored in <a href="objects/info.html">RFont.info</a>
f = CurrentFont()
print f.info.unitsPerEm

# kerning data is available in the kerning object:
print f.kerning

# len() gives you the "length" of the font, i.e. the number of glyphs
print "glyphs in this font:", len(f)

# treat a font object as a dictionary to get to the glyphs
print f["A"]
➔ Download this.
2048
<RKerning for MyFont>
glyphs in this font: 1120
<Glyph for MyFont.A>

RFont Methods available in FontLab and UFO

Method examples

# robofab manual
#     Font object
#    method examples
from robofab.world import CurrentFont
f = CurrentFont()

# the keys() method returns a list of glyphnames:
print f.keys()

# find unicodes for each glyph by using the postscript name:
f.autoUnicodes()
➔ Download this.
['A', 'B', 'space', 'adieresis.alt1']

FontLab

The following attributes and methods are only available to RoboFab objects in FontLab as they're based on application specific features.

RFont Methods only available in FontLab

RFont Attributes available in FontLab only

Attribute examples

# robofab manual
# Font object
#    method examples, available in FontLab
from robofab.world import CurrentFont
f = CurrentFont()

# the keys() method returns a list of glyphnames:
print f.selection

# generate font binaries
f.generate('otfcff')
➔ Download this.
['A', 'B']