def extractGlyph(self, glyph, pointPen=None, onlyGeometry=False): """ "rehydrate" to a glyph. this requires a glyph as an argument. if a point pen other than the type of pen returned by glyph.getPointPen() is required for drawing, send this the needed point pen. """ if pointPen is None: pointPen = glyph.getPointPen() glyph.clearContours() glyph.clearComponents() glyph.clearAnchors() glyph.clearGuidelines() glyph.lib.clear() cleanerPen = FilterRedundantPointPen(pointPen) self.drawPoints(cleanerPen) glyph.anchors = [dict(anchor) for anchor in self.anchors] glyph.guidelines = [ _compressGuideline(guideline) for guideline in self.guidelines ] glyph.image = _compressImage(self.image) glyph.lib = deepcopy(dict(self.lib)) glyph.width = self.width glyph.height = self.height glyph.note = self.note if not onlyGeometry: glyph.name = self.name glyph.unicodes = list(self.unicodes) return glyph
def test_compressGuideline(self): guideline = dict(x=100, y=0, angle=90) self.assertEqual(sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', 100), ('y', None)]) guideline = dict(x=100, y=0, angle=270) self.assertEqual(sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', 100), ('y', None)]) guideline = dict(y=100, x=0, angle=0) self.assertEqual(sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', None), ('y', 100)]) guideline = dict(y=100, x=0, angle=180) self.assertEqual(sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', None), ('y', 100)])
def extractGlyph(self, glyph, pointPen=None, onlyGeometry=False): """ "rehydrate" to a glyph. this requires a glyph as an argument. if a point pen other than the type of pen returned by glyph.getPointPen() is required for drawing, send this the needed point pen. """ if pointPen is None: pointPen = glyph.getPointPen() glyph.clearContours() glyph.clearComponents() glyph.clearAnchors() glyph.clearGuidelines() glyph.lib.clear() cleanerPen = FilterRedundantPointPen(pointPen) self.drawPoints(cleanerPen) glyph.anchors = [dict(anchor) for anchor in self.anchors] glyph.guidelines = [_compressGuideline(guideline) for guideline in self.guidelines] glyph.image = _compressImage(self.image) glyph.lib = deepcopy(dict(self.lib)) glyph.width = self.width glyph.height = self.height glyph.note = self.note if not onlyGeometry: glyph.name = self.name glyph.unicodes = list(self.unicodes) return glyph
def test_compressGuideline(self): guideline = dict(x=100, y=0, angle=90) self.assertEqual( sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', 100), ('y', None)] ) guideline = dict(x=100, y=0, angle=270) self.assertEqual( sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', 100), ('y', None)] ) guideline = dict(y=100, x=0, angle=0) self.assertEqual( sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', None), ('y', 100)] ) guideline = dict(y=100, x=0, angle=180) self.assertEqual( sorted(_compressGuideline(guideline).items()), [('angle', None), ('x', None), ('y', 100)] )