Exporting a .ufo file with fontParts doesn't create a valid file



  • regarding (1): you can get glyph widths by setting each character with the source font and measuring the text:

    # `font` is a DrawBot command and cannot be used as variable name
    fontName = "LucidaGrande"
    
    font(fontName)
    fontSize(1000)
    w, h = textSize(char)
    myGlyph.width = w
    

    the text font size is set to 1000 because this is the default UPM size when creating a new font, and we need a 1:1 scale in order to get width value.



  • @gferreira Thanks a lot. Everything works now!

    Follow-up questions will be:

    1. As I have an offsetValue to tweak the bending of the letters, would it be simple to do all of this inside Glyphs? This way I can open Glyphs, tweak it as much as I want and export right away as .OTF.

    2. Or how can I export an .OTF directly from DrawBot? I tried with myFont.generate() but something went wrong...

    formats = {
      'OpenType-CFF (.otf)' : 'otfcff',
      'OpenType-TTF (.ttf)' : 'otfttf',
      'PostScript (.pfa)'   : 'pctype1ascii'
    }
    
    # save the ufo
    if ExportUFO == True:
        myFont.save("Bogota.ufo")
        for format in formats.keys():
            print('Generating %s font...' % format)
            print(myFont.generate(formats[format]))
    
    ---------------------------------------------
    Generating OpenType-CFF (.otf) font...
    Traceback (most recent call last):
      File "Bogota5.py", line 126, in <module>
      File "/Applications/DrawBot.app/Contents/Resources/lib/python3.6/fontParts/base/font.py", line 362, in generate
      File "/Applications/DrawBot.app/Contents/Resources/lib/python3.6/fontParts/base/font.py", line 397, in _generate
      File "/Applications/DrawBot.app/Contents/Resources/lib/python3.6/fontParts/base/base.py", line 232, in raiseNotImplementedError
    NotImplementedError: The RFont subclass does not implement this method.
    


  • @frederik maybe you can help me with that one?


  • admin

    font.generate is RoboFont method and is not available inside DrawBot.

    However with ufo2fdk (which is embedded into DrawBot) you must be able to generate binaries (you will need to install FDK locally)

    or install fontMake and build a compiled font from a ufo.

    good luck!!!



  • @frederik Thank you! I don't exactly know how to use the ufo2fdk, but I will try.


  • admin

    Im pushing you to figure it out by yourself first 🙂

    see the documentation and the source of ufo2fdk

    and see documentation of fontMake



  • @frederik Thank you, Frederik. I tried both ufo2fdk I don't how to use, the documentation is a bit confusing for me.

    Anyways, with fontParts I ran the script but it gave me

    KeyError: 'unitsPerEm'
    

    Is it related to my font or to fontParts script in your opinion?


  • admin

    ufo2fdk needs some basic font info settings like descender, xHeight, ascender, capHeight, unitsPerEm

    # some default example values
    font.info.descender=-250
    font.info.xHeight=500
    font.info.ascender=750
    font.info.capHeight=750
    font.info.unitsPerEm=1000
    


  • @frederik Thank you, I managed! It works smoothly now—I was just missing the font.familyName but after adding this, it works.

    I was wondering if I can do it inside DrawBot right away? I tried to import fontmake or ufo2ft as a module but it doesn't work. Could it be that pip doesn't install it globally and DrawBot cannot find it—if that's the case where should I put it so DrawBot can see it?


  • admin

    yes you can use fontMake or ufo2ft, you just have to install it locally for the python3.6 (this is the embedded python in DrawBot)

    If you dont have python3.6 installed, you need to get it from https://www.python.org/downloads/.

    and install fontMake and/or ufo2ft with pip3.6 for py3.6

    good luck!


Log in to reply