예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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
예제 #8
0
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
예제 #9
0
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
예제 #10
0
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