SOLVED How to copy anchors from one font to another



  • Hi!
    Is it possible to copy all anchors with there (x, y) positions from one font to another?
    Thanks,
    Anna



  • hello @horashann,

    yes, this can be done with a simple script:

    # get source and destination fonts
    srcFont = AllFonts().getFontsByFamilyName('MyFontFamily').getFontsByStyleName('Regular')[0]
    dstFont = AllFonts().getFontsByFamilyName('MyFontFamily').getFontsByStyleName('Italic')[0]
    
    # iterate over selected glyphs in the source font
    for glyphName in srcFont.selectedGlyphNames:
    
        # get the source glyph
        srcGlyph = srcFont[glyphName]
    
        # if the glyph doesn't have any anchors, skip it
        if not len(srcGlyph.anchors):
            continue
    
        # get the destination glyph
        dstGlyph = dstFont[glyphName]
    
        # iterate over all anchors in the source glyph
        for anchor in srcGlyph.anchors:
    
            # copy anchor to destination glyph
            dstGlyph.appendAnchor(anchor.name, (anchor.x, anchor.y))
    
    # done!
    

    make sure to replace MyFontFamily and Regular / Italic with the family name and style names of your fonts.

    cheers!