print "Number of contours before", len(f['A']) # call FontLab to make a new font startNewFontCode = """from robofab.world import NewFont f = NewFont() f.info.fullName = 'Temporary Font generated by RoboFab Remote'""" print runFontLabRemote(startNewFontCode) # send a glyph to FontLab, # it will be inserted in the CurrentFont. transmitGlyph(f['A']) f.removeGlyph('A') # send instructions to remove overlap for this glyph overlapCode = """from robofab.world import CurrentFont from robofab.tools.remote import transmitGlyph f = CurrentFont() f["A"].removeOverlap() f.update() transmitGlyph(f['A']) """ # send the code and catch the output x = runFontLabRemote(overlapCode) # interpret the output receiveGlyph(x, f) print "Number of contours after: ", len(f['A']) # send instructions to FontLab to close the font again. closeFontCode = """from robofab.world import CurrentFont
def importUFO(ufoPath, newFile=True, saveFile=True, closeFile=True, doInfo=True, doKerning=True, doGroups=True, doLib=True, doFeatures=True, doHints=False, doMarks=True, doMasks=True, glyphs=None): # get the VFB path vfbPath = os.path.splitext(ufoPath)[0] + ".vfb" if not newFile: font = None for font in AllFonts(): if font.path == vfbPath: break if font is None: if not os.path.exists(vfbPath): Message("Could not find the FontLab file \"%s\"." % os.path.basename(vfbPath)) return font = OpenFont(vfbPath) else: if saveFile: if os.path.exists(vfbPath): vfbPath = _findAvailablePathName(vfbPath) font = NewFont() # make the font the top font in FL fl.ifont = font.fontIndex # read the UFO font.readUFO(ufoPath, doHints=doHints, doInfo=doInfo, doKerning=doKerning, doGroups=doGroups, doLib=doLib, doFeatures=doFeatures, glyphs=glyphs) # load the masks and marks if doMasks or doMarks: for glyph in font: lib = glyph.lib if doMarks: if lib.has_key(MARK_LIB_KEY): glyph.mark = lib[MARK_LIB_KEY] del lib[MARK_LIB_KEY] if doMasks: if lib.has_key(MASK_LIB_KEY): # open a glyph window fl.EditGlyph(glyph.index) # switch to the mask layer fl.CallCommand(fl_cmd.ViewEditMask) # add the mask data instructions = lib[MASK_LIB_KEY] pen = glyph.getPointPen() instructionsDrawPoints(instructions, pen) # switch back to the edit layer fl.CallCommand(fl_cmd.ViewEditMask) # clear the mask data from the glyph lib del lib[MASK_LIB_KEY] # close all glyph windows. sometimes this actually works. fl.CallCommand(fl_cmd.WindowCloseAllGlyphWindows) # load the WWS names if doInfo: info = readPlist(os.path.join(ufoPath, "fontInfo.plist")) if "openTypeNameWWSFamilyName" in info: font.lib[WWS_FAMILY_KEY] = info["openTypeNameWWSFamilyName"] elif "openTypeNameWWSFamilyName" in font.lib: del font.lib[WWS_FAMILY_KEY] if "openTypeNameWWSSubfamilyName" in info: font.lib[WWS_SUBFAMILY_KEY] = info["openTypeNameWWSSubfamilyName"] elif "openTypeNameWWSSubfamilyName" in font.lib: del font.lib[WWS_SUBFAMILY_KEY] # update the font font.update() # save and close if saveFile: font.save(vfbPath) if closeFile: font.close()
"""Correct contour direction for all glyphs in the font""" from robofab.world import OpenFont from robofab.interface.all.dialogs import ProgressBar font = OpenFont() bar = ProgressBar('Correcting contour direction...', len(font)) for glyph in font: bar.label(glyph.name) glyph.correctDirection() glyph.update() bar.tick() font.update() bar.close()