def makePath( pathData, elementAttrs=defaultStyleAttrs): """FOR SYMPY: create an lxml path using a PathData object initialized using sympy Point objects and optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) elementAttrs['d'] = pathData.getD() pathElement = etree.Element('path') document.setAttributesFromDict(pathElement, elementAttrs) return pathElement
def buildUse(id, elementAttrs={} ): """create a use node (for cloning) with id of node to be cloned (set in its elementAttrs). Use elementAttrs to set transform of object.""" elementAttrs = copy(elementAttrs) useElement = etree.Element('use') elementAttrs["{http://www.w3.org/1999/xlink}href"] = '#'+str(id) document.setAttributesFromDict(useElement, elementAttrs) return useElement
def buildPath( pathData, elementAttrs=defaultStyleAttrs): """create an lxml path using a PathData object and optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) elementAttrs['d'] = str(pathData) pathElement = etree.Element('path') document.setAttributesFromDict(pathElement, elementAttrs) return pathElement
def buildText( text, elementAttrs=defaultTextStyleAttrs): """create a text node with given text and optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) textElement = etree.Element('text') document.setAttributesFromDict(textElement, elementAttrs) textElement.text = text return textElement
def makeCircle(circle, elementAttrs=defaultStyleAttrs): """FOR SYMPY: create an lxml circle element from sympy Circle with optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) elementAttrs['cx'] = aNum(circle.center.x) elementAttrs['cy'] = aNum(circle.center.y) elementAttrs['r'] = aNum(circle.radius) circleElement = etree.Element('circle') document.setAttributesFromDict(circleElement, elementAttrs) return circleElement
def buildCircle(point,radius, elementAttrs=defaultStyleAttrs): """create an lxml circle element centered at point with given radius and optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) elementAttrs['cx'] = aNum(point.x) elementAttrs['cy'] = aNum(point.y) elementAttrs['r'] = aNum(radius) circleElement = etree.Element('circle') document.setAttributesFromDict(circleElement, elementAttrs) return circleElement
def buildRect(pointA, height, width, elementAttrs=defaultStyleAttrs): """create an lxml rectangle element with bottom left corner pointA, and given width/height, with optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) elementAttrs['x'] = aNum(pointA.x) elementAttrs['y'] = aNum(pointA.y) elementAttrs['height'] = aNum(height) elementAttrs['width'] = aNum(width) rectElement = etree.Element('rect') document.setAttributesFromDict(rectElement, elementAttrs) return rectElement
def makeLine(line,elementAttrs=defaultStyleAttrs): """FOR SYMPY: create an lxml line element from sympy Line with optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) elementAttrs['x1'] = aNum(line.p1.x) elementAttrs['y1'] = aNum(line.p1.y) elementAttrs['x2'] = aNum(line.p2.x) elementAttrs['y2'] = aNum(line.p2.y) lineElement = etree.Element('line') document.setAttributesFromDict(lineElement, elementAttrs) return lineElement
def buildLine(pointA, pointB,elementAttrs=defaultStyleAttrs): """create an lxml line element from pointA to pointB with optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) elementAttrs['x1'] = aNum(pointA.x) elementAttrs['y1'] = aNum(pointA.y) elementAttrs['x2'] = aNum(pointB.x) elementAttrs['y2'] = aNum(pointB.y) lineElement = etree.Element('line') document.setAttributesFromDict(lineElement, elementAttrs) return lineElement
def makeText( text, position, elementAttrs=defaultTextStyleAttrs): """create a text node with given text and optional elementAttrs dictionary defining node attributes""" elementAttrs = copy(elementAttrs) textElement = etree.Element('text') elementAttrs['x'] = aNum(position.x) elementAttrs['y'] = aNum(position.y) elementAttrs['transform'] = "translate(" + aNum(position.x ) + ", " + aNum(position.y) + ") scale(1,-1) translate(" + aNum(-1*position.x) + "," + aNum(-1*position.y) + ")" textElement.text = text document.setAttributesFromDict(textElement, elementAttrs) return textElement