def extractFontFromVFB(pathOrFile, destination, doGlyphs=True, doInfo=True, doKerning=True, doGroups=True, doFeatures=True, doLib=True, customFunctions=[]): ufoPath = tempfile.mkdtemp(suffix=".ufo") cmds = [_ufo2vfbLocation, "-64", pathOrFile, ufoPath] cmds = subprocess.list2cmdline(cmds) popen = subprocess.Popen(cmds, shell=True) popen.wait() try: # vfb2ufo writes ufo2, and has no update since 2015...so dont get to crazy here... source = UFOReader(ufoPath) if doInfo: source.readInfo(destination.info) if doKerning: kerning = source.readKerning() destination.kerning.update(kerning) if doGroups: groups = source.readGroups() destination.groups.update(groups) if doFeatures: features = source.readFeatures() destination.features.text = features if doLib: lib = source.readLib() destination.lib.update(lib) if doGlyphs: glyphSet = source.getGlyphSet() for glyphName in glyphSet.keys(): destination.newGlyph(glyphName) glyph = destination[glyphName] pointPen = glyph.getPointPen() glyphSet.readGlyph(glyphName=glyphName, glyphObject=glyph, pointPen=pointPen) for function in customFunctions: function(source, destination) finally: shutil.rmtree(ufoPath)
def _loadData(self, path): from ufoLib import UFOReader reader = UFOReader(path) fontLib = reader.readLib() # info reader.readInfo(self.info) # kerning self.kerning.update(reader.readKerning()) self.kerning.setChanged(False) # groups self.groups.update(reader.readGroups()) # features if reader.formatVersion == 1: # migrate features from the lib features = [] classes = fontLib.get("org.robofab.opentype.classes") if classes is not None: del fontLib["org.robofab.opentype.classes"] features.append(classes) splitFeatures = fontLib.get("org.robofab.opentype.features") if splitFeatures is not None: order = fontLib.get("org.robofab.opentype.featureorder") if order is None: order = splitFeatures.keys() order.sort() else: del fontLib["org.robofab.opentype.featureorder"] del fontLib["org.robofab.opentype.features"] for tag in order: oneFeature = splitFeatures.get(tag) if oneFeature is not None: features.append(oneFeature) features = "\n".join(features) else: features = reader.readFeatures() self.features.text = features # hint data self.psHints = PostScriptFontHintValues(self) if postScriptHintDataLibKey in fontLib: del fontLib[postScriptHintDataLibKey] # lib self.lib.update(fontLib) # glyphs self._glyphSet = reader.getGlyphSet() self._hasNotChanged(doGlyphs=False)