The RoboFont 3/ FontParts API does not include the font.compile() method for building accented glyphs.

Convert a dictionary with data for building accented glyphs into a list of Glyph Construction rules.

'''accentsDict2GlyphConstruction'''

# ----
# data
# ----

# a dictionary with data for building accented glyphs,
# as typically used with RoboFab's RFont.compileGlyph

accentsDict = {
    # accented   : [ base, ( (accent1, anchor1), (accent2, anchor2), ... ) ],
    'aogonek'    : [ 'a',  ( ('ogonek', 'bottom'), ) ],
    'agrave'     : [ 'a',  ( ('grave', 'top'), ) ],
    'ccedilla'   : [ 'c',  ( ('cedilla', 'bottom'), ) ],
    'aringacute' : [ 'a',  ( ('ring', 'top'), ('acute', 'top'),) ],
    # ...more items here...
}

# ---------
# functions
# ---------

def accentsDict2GlyphConstruction(accentsDict, useSpaces=True):

    # create an empty string to collect all GlyphConstruction rules
    glyphConstruction = ''

    # iterate over the accented glyphs dict
    for accentedGlyph in accentsDict:

        # get base glyph and accents for this accented glyph
        baseGlyph, accents = accentsDict[accentedGlyph]

        # start a glyph construction rule for this glyph:
        # accentedGlyph = baseGlyph + (some accents)
        glyphConstruction += '%s = %s + ' % (accentedGlyph, baseGlyph)

        # iterate over all accents in accented glyph, using a counter
        for i, (accentName, anchor) in enumerate(accents):
            # if accent is not the first, add a '+' before it
            if not i == 0:
                glyphConstruction += ' + '
            # add accent name and anchor name to glyph construction rule
            glyphConstruction += '%s@%s' % (accentName, anchor)

        # done with this accented glyph; go to the next line
        glyphConstruction += '\n'

    # remove all spaces
    if not useSpaces:
        glyphConstruction = glyphConstruction.replace(' ', '')

    # done!
    return glyphConstruction

# ----
# run!
# ----

glyphConstruction = accentsDict2GlyphConstruction(accentsDict, useSpaces=False)

print(glyphConstruction)

Last edited on 08/09/2018