def _drawElements(self, glyph, color, distance, mode): assert mode == 'canvas' or mode == 'foreground' assert self.elementShape in SHAPE_OPTIONS if mode == 'foreground': phantomGlyph = RGlyph() for eachContour in glyph: for indexSegment, eachSegment in enumerate(eachContour): if indexSegment != len(eachContour) - 1: nextSegment = eachContour[indexSegment + 1] else: if eachContour.open is True: continue else: nextSegment = eachContour[0] pt1 = eachSegment.onCurve.x, eachSegment.onCurve.y pt4 = nextSegment.onCurve.x, nextSegment.onCurve.y if nextSegment.offCurve: pt2 = nextSegment.offCurve[0].x, nextSegment.offCurve[0].y pt3 = nextSegment.offCurve[1].x, nextSegment.offCurve[1].y else: pt2 = pt1 pt3 = pt4 pt1 = eachSegment.onCurve.x, eachSegment.onCurve.y pt4 = nextSegment.onCurve.x, nextSegment.onCurve.y if eachSegment.onCurve.naked().uniqueID in glyph.lib[PLUGIN_KEY] and \ nextSegment.onCurve.naked().uniqueID in glyph.lib[PLUGIN_KEY]: startLib = glyph.lib[PLUGIN_KEY][ eachSegment.onCurve.naked().uniqueID] endLib = glyph.lib[PLUGIN_KEY][ nextSegment.onCurve.naked().uniqueID] bezPoints = collectsPointsOnBezierCurveWithFixedDistance( pt1, pt2, pt3, pt4, distance) for indexBezPt, eachBezPt in enumerate(bezPoints): factor = indexBezPt / float(len(bezPoints)) width = lerp(startLib['width'], endLib['width'], factor) height = lerp(startLib['height'], endLib['height'], factor) angle = lerp(startLib['angle'], endLib['angle'], factor) if mode == 'canvas': save() fill(*color) translate(eachBezPt[0][0], eachBezPt[0][1]) rotate(angle) if self.elementShape == 'Oval': oval(-width / 2., -height / 2., width, height) else: rect(-width / 2., -height / 2., width, height) restore() else: matrix = Identity matrix = matrix.translate(eachBezPt[0][0], eachBezPt[0][1]) matrix = matrix.rotate(math.radians(angle)) if self.elementShape == 'Oval': robofabOval(phantomGlyph, 0, 0, width, height) else: robofabRect(phantomGlyph, 0, 0, width, height) phantomGlyph[len(phantomGlyph) - 1].transform(matrix) if mode == 'foreground': phantomGlyph.removeOverlap() flattenGlyph(phantomGlyph, 20) thresholdGlyph(phantomGlyph, 5) if version[0] == '2': glyph.getLayer('public.default', clear=True).appendGlyph(phantomGlyph, (0, 0)) else: glyph.getLayer('foreground', clear=True).appendGlyph(phantomGlyph, (0, 0))