RoboFab





RFont()

Usage

#Usage examples
# start using the current font
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)
    

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.

f = CurrentFont()
for glyph in f:
	print glyph.name
>>>a
>>>b
>>>c
etc..
This makes the code clear and simple.

FontLab / UFO

All basic attributes, methods and behaviour for RFont objects made 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

# Most useful attributes of RFont are
# actually stored in RFont.info
f = CurrentFont()
print f.info.unitsPerEm
>>> 2048

# len() gives you the "length" of the font, i.e. the number of glyphs
print len(f)
>>> 1120

# treat a font object as a dictionary to get to the glyphs
print f["A"]
>>> < Glyph for MyFont.A >

RFont Methods available in FontLab and UFO

Method examples

f = CurrentFont()

# the keys() method returns a list of glyphnames:
print f.keys()
>>> ['A', 'B', 'space', 'adieresis.alt1']

# find unicodes for each glyph by using the postscript name:
f.autoUnicodes()

RFont Methods available in FontLab only

RFont Attributes available in FontLab only

Attribute examples

f = CurrentFont()

# the keys() method returns a list of glyphnames:
print f.selected
>>> ['A']