# robofab manual
#    Glyph object
#    Usage examples
# start using the current font

from robofab.world import CurrentGlyph
g = CurrentGlyph()

# suppose you've done the right imports
# different ways of creating glyphs
# a new empty glyph object
g = robofab.world.RGlyph()

# a new empty fontlab glyph object
g = robofab.objects.objectsFL.RGlyph()

# a new empty robofab glyph object
g = robofab.objects.objectsRF.RGlyph()

# the easiest way to get a new glyph
# is to ask a font to make you one:
g = aFontObject[glyphName]

➔ Download this.


The RGlyph object represents a glyph, its parts and associated data. In FontLab RGlyph talks directly to a glyph in an open font. In NoneLab the RGlyph refers to data read from (and written to) a specific glif file in a UFO. RGlyph can be used as a list of RContours. When RGlyph is obtained from a RoboFab font object (see examples), the font is the parent object of the glyph.


Attribute examples

# robofab manual
#    Glyph object
#    attribute examples

from robofab.world import CurrentFont, CurrentGlyph
f = CurrentFont()

# create a glyph object by asking the font
g = f["Adieresis"]

# alternatively, create a glyph object for the current glyph
g = CurrentGlyph()

# get the width
print g.width

# get the name
print g.name

# a  list of unicode values for this glyph. Can be more than 1!
print g.unicodes

# set the width
g.width = 1000
print g.width

# get the number of contours in a glyph
# by getting  its length
print len(g)
➔ Download this.
[123, 345]


Method examples

# robofab manual
#    Glyph object
#    method examples

# get a glyph object from a font
f = CurrentFont()
g = f["A"]
print g

# move the glyph 10 units to the right, and 200 units up:
g = f["a"]
g.move((10, 200))
➔ Download this.



Glyph methods only available in FontLab.


# robofab manual
#    Glyph object
#    method examples

#    In FontLab the baseglyph of a component can't be changed easily.
#    This assumes that there will only be
#    one component that needs to be remapped.

def remapComponent(glyph, oldBaseGlyph, newBaseGlyph):
    foundComponent = None
    for component in glyph.components:
        if component.baseGlyph = oldBaseGlyph:
            foundComponent = component
    if foundComponent is None:
    offset = foundComponent.offset
    scale = foundComponent.scale
    glyph.appendComponent(newBaseGlyph, offset=offset, scale=scale)

➔ Download this.