def run_ufolib_import_validation(self): """ ufoLib UFOReader.readKerning method validates the kerning.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 kerning.plist with ufoLib - the ufoLib library performs type validations on values on read ufolib_reader = UFOReader(self.ufopath, validate=True) ufolib_reader.readKerning() 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 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 extractFontFromVFB( pathOrFile, destination, doGlyphs=True, doInfo=True, doKerning=True, doGroups=True, doFeatures=True, doLib=True, customFunctions=[], ): ufoPath = tempfile.mkdtemp(suffix=".ufo") cmds = [_ufo2vfbLocation, "-64", "-fo", 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... # dont validate as vfb2ufo writes invalid ufos source = UFOReader(ufoPath, validate=False) 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 __attrs_post_init__(self) -> None: if self._path is not None: # if lazy argument is not set, default to lazy=True if path is provided if self._lazy is None: self._lazy = True reader = UFOReader(self._path, validate=self._validate) self.layers = LayerSet.read(reader, lazy=self._lazy) self.data = DataSet.read(reader, lazy=self._lazy) self.images = ImageSet.read(reader, lazy=self._lazy) self.info = Info.read(reader) self.features = Features(reader.readFeatures()) self.groups = reader.readGroups() self.kerning = reader.readKerning() self.lib = reader.readLib() self._fileStructure = reader.fileStructure if self._lazy: # keep the reader around so we can close it when done self._reader = reader
def read(cls, reader: UFOReader, lazy: bool = True) -> "Font": """Instantiates a Font object from a :class:`fontTools.ufoLib.UFOReader`. Args: path: The path to the UFO to load. lazy: If True, load glyphs, data files and images as they are accessed. If False, load everything up front. """ self = cls( layers=LayerSet.read(reader, lazy=lazy), data=DataSet.read(reader, lazy=lazy), images=ImageSet.read(reader, lazy=lazy), info=Info.read(reader), features=Features(reader.readFeatures()), groups=reader.readGroups(), kerning=reader.readKerning(), lib=reader.readLib(), lazy=lazy, ) self._fileStructure = reader.fileStructure if lazy: # keep the reader around so we can close it when done self._reader = reader return self