def _deep_copy_contours(self, ufo, parent, component, transformation): """Copy contours from component to parent, including nested components.""" for nested in component.components: self._deep_copy_contours( ufo, parent, ufo[nested.baseGlyph], transformation.transform(nested.transformation)) if component != parent: pen = TransformPen(parent.getPen(), transformation) # if the transformation has a negative determinant, it will reverse # the contour direction of the component xx, xy, yx, yy = transformation[:4] if xx * yy - xy * yx < 0: pen = ReverseContourPen(pen) component.draw(pen)
def _set_segments(glyph, segments, reverse_direction): """Draw segments as extracted by GetSegmentsPen back to a glyph.""" glyph.clearContours() pen = glyph.getPen() if reverse_direction: pen = ReverseContourPen(pen) for tag, args in segments: if tag == 'move': pen.moveTo(*args) elif tag == 'line': pen.lineTo(*args) elif tag == 'qcurve': pen.qCurveTo(*args[1:]) elif tag == 'close': pen.closePath() elif tag == 'end': pen.endPath() else: raise AssertionError('Unhandled segment type "%s"' % tag)