def draw_path(path_data): if not path_data: return None import svg p = svg.path_from_string(path_data) p.fillColor = None p.strokeWidth = 1 p.strokeColor = Color() return p
def import_svg(self): # Parses the string from the node's path parameter and constructs a path self.path_string = self.getValue("path") self.path = svg.path_from_string(self.path_string) self._points = [] # Converts the path data into a list of PathElements for contour in self.path.contours: if not (len(contour.points) == 1 and contour.points[0].x == 0 and contour.points[0].y == 0): first = None curvePoint = PathElement() curvePoint.cmd = CURVETO first_curvepoint = True for point in contour.points: if first is None or point.isLineTo(): # Checks for MOVETO or LINETO PathElements. # The first point of a Curve is always a MOVETO, # The other ones are LINETO's. pe = PathElement() if first is None: first = point pe.cmd = MOVETO else: pe.cmd = LINETO pe.x = point.x pe.y = point.y self._points.append(pe) else: # Checks for CURVETO PathElements. # A new element will only be appended to the points list # when all necessary data has been found by going through the loop if first_curvepoint: curvePoint.ctrl1 = point first_curvepoint = False elif point.isOffCurve(): curvePoint.ctrl2 = point else: curvePoint.x = point.x curvePoint.y = point.y self._points.append(curvePoint) curvePoint = PathElement() curvePoint.cmd = CURVETO first_curvepoint = True if contour.closed: pe = PathElement() pe.cmd = CLOSE self._points.append(pe)