SOLVED Mass-import ligatures/svgs



  • Hi, i am new to RoboFont, not sure if this is possible.

    I have a list of ligature definitions (e.g. a_b.liga), and i want to use a script to import the list and then insert a glyph for each ligature (from svg files, e.g. a_b.svg).

    Can i do that with RoboFont? Is there a similar project/tutorial that can point me in the right direction?

    Thanks a lot!
    Flo


  • admin

    hello @flo,

    I’ve had to do something similar in the past, it can be solved with a bit of scripting.

    see svg2robofont.py and the included example.

    let me know if you need some help to get it to work… cheers!


    edit: here’s an example script which imports all SVGs in a folder into glyphs:

    import glob, os
    from svg2robofont import SVGPen
    
    svgs = glob.glob('tests2/*.svg')
    
    f = NewFont()
    
    for svg in svgs:
        name = os.path.splitext(os.path.basename(svg))[0]
        g = f.newGlyph(name)
        svgPen = SVGPen(svg, g.getPen())
        g.width = svgPen.handler.width
    


  • That looks great, will try it and let you know!
    Thanks a lot!



  • That worked great, thanks a lot!

    Now, simply importing the glyph names as a_b.liga does not result in substitution, as i understand i need to add them to the features like this:

    feature liga {
        sub a b by a_b.liga;
        sub ...
        } liga;
    

    How do i do that with a script?


  • admin

    hello @flo, happy to hear that the import script worked.

    you can add features to a font using the Features Editor or with a script:

    feaCode = '''\
    # language statements etc.
    feature liga {
        sub a b by a_b.liga;
        sub ...
        } liga;
    '''
    f = CurrentFont()
    f.features.text = feaCode
    

    good luck!