from glyphConstruction import ParseGlyphConstructionListFromString, GlyphConstructionBuilder # define glyph constructions txt = '''\ ?agrave = a + grave@center,top aacute = a + acute@center,top ''' # get the actual glyph constructions from text constructions = ParseGlyphConstructionListFromString(txt) # get the current font font = CurrentFont() # collect glyphs to ignore if they already exist in the font ignoreExisting = [L.split('=')[0].strip()[1:] for L in txt.split('\n') if L.startswith('?')] # iterate over all glyph constructions for construction in constructions: # build a construction glyph constructionGlyph = GlyphConstructionBuilder(construction, font) # if the construction for this glyph was preceded by `?` # and the glyph already exists in the font, skip it if constructionGlyph.name in font and constructionGlyph.name in ignoreExisting: continue # get the destination glyph in the font glyph = font.newGlyph(constructionGlyph.name, clear=True) # draw the construction glyph into the destination glyph constructionGlyph.draw(glyph.getPen()) # copy construction glyph attributes to the destination glyph glyph.name = constructionGlyph.name glyph.unicode = constructionGlyph.unicode glyph.width = constructionGlyph.width glyph.markColor = 1, 1, 0, 0.5 # if no unicode was given, try to set it automatically if glyph.unicode is None: glyph.autoUnicodes()