This page gives an overview of the multiple ways to add and remove glyphs in RoboFont.

Adding glyphs

Adding glyphs using the Add Glyphs sheet

Use the Add Glyphs sheet to create new glyphs manually from a list of glyph names. A basic syntax for building glyphs from components is supported.

Adding glyphs with Glyph Construction

The Glyph Construction extension provides a more powerful language for building glyphs.

Adding glyphs with a script

It’s also possible to add glyphs to a font using a script. The example below includes a check to avoid overwriting existing glyphs:

font = CurrentFont()

# add a new glyph to the font
# if the glyph already exists, it will be overwritten
font.newGlyph('hello')

# use clear=False if you don't want to overwrite an existing glyph
font.newGlyph('A', clear=False)

# add several glyphs at once with a loop
newGlyphNames = ['test1', 'test2', 'test3']
for glyphName in newGlyphNames:
    font.newGlyph(glyphName)

Removing glyphs

Removing glyphs manually

  1. select the glyphs to be removed in the Font Overview
  2. press the backspace key

When a glyph is deleted from the font, it is also automatically removed from font.glyphOrder.

Depending on your settings in Font Overview Preferences, the deleted glyphs will also be removed from groups and/or kerning pairs.

This setting is applied only when deleting glyphs manually in the Font Overview. Glyphs which are deleted via scripts are not removed from groups or kerning.

Deleted glyphs are not removed automatically from OpenType features. If the OpenType compiler encounters a glyph which is not in the font, it will raise an error and the font will not be generated.

Removing glyphs with a script

It’s also possible to remove remove a glyph from a font using a script. The example below includes a check to avoid an error if the glyph is not in the font:

font = CurrentFont()

glyphName = 'hello'

# before removing a glyph, make sure it actually exists in the font
if glyphName in font:
    del font[glyphName]
else:
    print("font does not contain a glyph named '%s'" % glyphName)

# if we try to remove a glyph which is not in the font,
# and error will be raised
del font['spam']
Traceback (most recent call last):
  File "<untitled>", line 3, in <module>
  File "/Applications/RoboFont.app/Contents/Resources/lib/python3.6/fontParts/base/layer.py", line 136, in __delitem__
ValueError: No glyph with the name 'spam' exists.

When a glyph is removed from a font with a script, it is not automatically removed from groups, kerning, or components. This is not necessarily a problem, since the UFO3 specification allows groups, kerning and components to reference glyphs which are not in the font.

font.removeGlyph(glyphName) is deprecated.

Removing glyphs from groups

The example script below shows how to remove all occurrences of a glyph in groups:

font = CurrentFont()

# glyph to be removed
glyphName = 'B'

# iterate over all groups in the font
for groupName in font.groups.keys():

    # get the group as a list of glyph names
    group = list(font.groups[groupName])

    # if the glyph is in the group:
    if glyphName in group:

        # remove the glyph name
        print("removing '%s' from group '%s'..." % (glyphName, groupName))
        group.remove(glyphName)

        # put the group back into the font
        font.groups[groupName] = group

Removing glyphs from kerning

The example script below shows how to remove all kerning pairs which include a glyph:

font = CurrentFont()

# the glyph to be removed
glyphName = 'A'

# iterate over all kerning pairs in the font
for kerningPair in font.kerning.keys():

    # if the glyph is in the kerning pair:
    if glyphName in kerningPair:

        # remove the kerning pair
        print('removing kerning pair (%s, %s)...' % kerningPair)
        del font.kerning[kerningPair]

Removing glyphs from components

The example script below shows how to remove all components referencing a glyph:

font = CurrentFont()

# the glyph to be removed
glyphName = 'a'

# iterate over all glyphs in the font
for glyph in font:

    # skip glyphs which components
    if not glyph.components:
        continue

    # iterate over all components in glyph
    for component in glyph.components:

        # if the base glyph is the glyph to be removed
        if component.baseGlyph == glyphName:
            # delete the component
            glyph.removeComponent(component)

Removing template glyphs

Removing template glyphs manually

Use ⌥ + backspace in the Font Overview to remove template glyphs from the font.

Removing template glyphs with a script

The example script below shows how to remove a template glyph from a font:

font = CurrentFont()

# the template glyph to be removed
glyphName = 'a'

# get the current template glyphs
templateGlyphs = font.templateGlyphOrder

# remove template glyph name from list
templateGlyphs.remove(glyphName)

# save the list of template glyphs back into the font
f.templateGlyphOrder = templateGlyphs
Last edited on 02/06/2020