def createTwoPointLine(doc, lineObj): lineNode = doc.createElement("line") points = lineObj.get_points() assert (len(points) == 4) lineNode.setAttributeNode(createAttr(doc, "x1", str(points[0]))) lineNode.setAttributeNode(createAttr(doc, "y1", str(points[1]))) arrowhead = lineObj.get_arrowhead() if arrowhead == 1: angle = rad_angle(points[2], points[3], points[0], points[1]) x, y = arrow_line_end(points[2], points[3], angle, lineObj.get_linewidth()) lineNode.setAttributeNode(createAttr(doc, "x2", str(x))) lineNode.setAttributeNode(createAttr(doc, "y2", str(y))) else: lineNode.setAttributeNode(createAttr(doc, "x2", str(points[2]))) lineNode.setAttributeNode(createAttr(doc, "y2", str(points[3]))) style = SVGLineStyle(lineObj) + SVGLineDashStyle(lineObj) lineNode.setAttributeNode(createAttr(doc, "style", style)) if arrowhead == 1 or arrowhead == 3: lineNode.setAttributeNode( createAttr(doc, "marker-end", "url(#Arrowhead)")) if arrowhead == 2 or arrowhead == 3: lineNode.setAttributeNode( createAttr(doc, "marker-start", "url(#Arrowtail)")) return lineNode
def createPolyLine( doc, lineObj, state ): polyLine = doc.createElement("polyline") points = lineObj.get_points() # Fixme: Duplication of createTwoPointLine arrowhead = lineObj.get_arrowhead() if arrowhead == 1: angle = rad_angle( points[-2], points[-1], points[-4], points[-3] ) x, y = arrow_line_end( points[-2], points[-1], angle, lineObj.get_linewidth() ) points[-2] = x points[-1] = y ptStr = ",".join([str(pt) for pt in points]) polyLine.setAttributeNode(createAttr(doc, "points", ptStr)) style = SVGLineStyle( lineObj, state ) + SVGLineDashStyle( lineObj ) polyLine.setAttributeNode( createAttr( doc, "style", style + ";fill:none" ) ) if arrowhead == 1 or arrowhead == 3: polyLine.setAttributeNode( createAttr( doc, "marker-end", "url(#Arrowhead)") ) if arrowhead == 2 or arrowhead == 3: polyLine.setAttributeNode( createAttr( doc, "marker-start", "url(#Arrowtail)") ) return polyLine