RoboFab

Support RoboFab

Up

See also

RoboFab Mailinglist

Join the RoboFab users community at Google groups.

Google Groups

Email:

Visit this group

RoboFab Sponsors

RGlyph()

Usage

# 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 examples/usageGlyph.py

Description

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.

Attributes

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 examples/glyphAttributes.py
230
Adieresis
[123, 345]
1000
4

Methods

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 examples/glyphMethods.py

FontLab

Methods

Glyph methods only available in FontLab.

Useful

# 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
            break
    if foundComponent is None:
        return
    offset = foundComponent.offset
    scale = foundComponent.scale
    glyph.removeComponent(component)
    glyph.appendComponent(newBaseGlyph, offset=offset, scale=scale)

download examples/remapComponent.py