def run_ufolib_import_validation(self): """ ufoLib UFOReader.getLayerNames method validates the layercontents.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 ): # should only meet this condition if not a mandatory file (runner.py checks) res.test_failed = False ss.stream_result(res) return self.test_fail_list try: # read layercontents.plist with ufoLib - the ufoLib library performs type validations on values on read ufolib_reader = UFOReader(self.ufopath, validate=True) ufolib_reader.getLayerNames() res.test_failed = False ss.stream_result(res) except Exception as e: if ( self.testpath in self.mandatory_filepaths_list ): # if part of mandatory file spec for UFO version, fail early res.test_failed = True res.exit_failure = True # fail early b/c it is mandatory part of spec else: res.test_failed = ( True ) # fail the test, but wait to report until all other tests complete res.test_long_stdstream_string = ( self.testpath + " failed ufoLib import test with error: " + str(e) ) self.test_fail_list.append(res) ss.stream_result(res) return self.test_fail_list
def read(cls, reader: UFOReader, lazy: bool = True) -> LayerSet: """Instantiates a LayerSet 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. """ layers: dict[str, Layer] = {} defaultLayer = None defaultLayerName = reader.getDefaultLayerName() for layerName in reader.getLayerNames(): isDefault = layerName == defaultLayerName if isDefault or not lazy: layer = cls._loadLayer(reader, layerName, lazy, isDefault) if isDefault: defaultLayer = layer layers[layerName] = layer else: layers[layerName] = _LAYER_NOT_LOADED assert defaultLayer is not None self = cls(layers=layers, defaultLayer=defaultLayer) if lazy: self._reader = reader return self
def reloadLayers(self, layerData): """ Reload the layers. This should not be called externally. """ reader = UFOReader(self.font.path, validate=self.font.ufoLibReadValidate) # handle the layers currentLayerOrder = self.layerOrder for layerName, l in layerData.get("layers", {}).items(): # new layer if layerName not in currentLayerOrder: glyphSet = reader.getGlyphSet(layerName, validateRead=self.ufoLibReadValidate, validateWrite=self.font.ufoLibWriteValidate) self.newLayer(layerName, glyphSet) # get the layer layer = self[layerName] # reload the layer info if l.get("info"): layer.color = None layer.lib.clear() layer._glyphSet.readLayerInfo(layer) self._stampLayerInfoDataState(layer) # reload the glyphs glyphNames = l.get("glyphNames", []) if glyphNames: layer.reloadGlyphs(glyphNames) # handle the order if layerData.get("order", False): newLayerOrder = reader.getLayerNames() for layerName in self.layerOrder: if layerName not in newLayerOrder: newLayerOrder.append(layerName) self.layerOrder = newLayerOrder # handle the default layer if layerData.get("default", False): newDefaultLayerName = reader.getDefaultLayerName() self.defaultLayer = self[newDefaultLayerName]
def reloadLayers(self, layerData): """ Reload the layers. This should not be called externally. """ reader = UFOReader(self.font.path, validate=self.font.ufoLibReadValidate) # handle the layers currentLayerOrder = self.layerOrder for layerName, l in layerData.get("layers", {}).items(): # new layer if layerName not in currentLayerOrder: glyphSet = reader.getGlyphSet( layerName, validateRead=self.ufoLibReadValidate, validateWrite=self.font.ufoLibWriteValidate) self.newLayer(layerName, glyphSet) # get the layer layer = self[layerName] # reload the layer info if l.get("info"): layer.color = None layer.lib.clear() layer._glyphSet.readLayerInfo(layer) self._stampLayerInfoDataState(layer) # reload the glyphs glyphNames = l.get("glyphNames", []) if glyphNames: layer.reloadGlyphs(glyphNames) # handle the order if layerData.get("order", False): newLayerOrder = reader.getLayerNames() for layerName in self.layerOrder: if layerName not in newLayerOrder: newLayerOrder.append(layerName) self.layerOrder = newLayerOrder # handle the default layer if layerData.get("default", False): newDefaultLayerName = reader.getDefaultLayerName() self.defaultLayer = self[newDefaultLayerName]