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 testUFO2(self): self.makeUFO(formatVersion=2) reader = UFOReader(self.ufoPath, validate=True) kerning = reader.readKerning() self.assertEqual(self.expectedKerning, kerning) groups = reader.readGroups() self.assertEqual(self.expectedGroups, groups) info = TestInfoObject() reader.readInfo(info)
def testUFO2(self): self.makeUFO(formatVersion=2) reader = UFOReader(self.ufoPath) kerning = reader.readKerning() self.assertEqual(self.expectedKerning, kerning) groups = reader.readGroups() self.assertEqual(self.expectedGroups, groups) info = TestInfoObject() reader.readInfo(info)
def run_ufolib_import_validation(self): """ ufoLib UFOReader.readGroups method validates the groups.plist file :return: (list) list of test failure Result objects """ res = Result(self.testpath) ss = StdStreamer(self.ufopath) if file_exists(self.testpath) is False: res.test_failed = False # not a mandatory file in UFO spec, test passes if missing ss.stream_result(res) return self.test_fail_list try: # read groups.plist with ufoLib - the ufoLib library performs type validations on values on read ufolib_reader = UFOReader(self.ufopath, validate=True) ufolib_reader.readGroups() res.test_failed = False ss.stream_result(res) except Exception as e: res.test_failed = True res.test_long_stdstream_string = self.testpath + " failed ufoLib import test with error: " + str( e) ss.stream_result(res) self.test_fail_list.append(res) return self.test_fail_list
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)