コード例 #1
0
def parseLineNode(node):
    s = getSettings(node)

    x1 = float(node.attributes['x1'].value)
    y1 = float(node.attributes['y1'].value)
    x2 = float(node.attributes['x2'].value)
    y2 = float(node.attributes['y2'].value)

    arrowhead = node.hasAttribute("marker-end") and node.attributes[
        "marker-end"].value == "url(#Arrowhead)"
    arrowtail = node.hasAttribute("marker-start") and node.attributes[
        "marker-start"].value == "url(#Arrowtail)"

    if arrowhead and arrowtail:
        s.arrow = 3
        # Fixme: adjustment!
    elif arrowtail:
        s.arrow = 2
    elif arrowhead:
        s.arrow = 1
        # Adjust the arrow line end ( Fixme: More work required )
        lineWidth = s.linewidth
        angle = rad_angle(x2, y2, x1, y1)
        x2, y2 = actual_line_end(x2, y2, angle, lineWidth)
    else:
        s.arrow = 0

    return ["line", (x1, y1, x2, y2), s, parseNodeTransform(node)]
コード例 #2
0
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
コード例 #3
0
def parse_line_node(node, state):
    settings = get_settings(node, state)
    x1 = float(node.attributes['x1'].value)
    y1 = float(node.attributes['y1'].value)
    x2 = float(node.attributes['x2'].value)
    y2 = float(node.attributes['y2'].value)

    parse_marker_attribute(node, settings)
    if settings.arrow in ('front', 'both'):
        # Adjust the arrow line end ( Fixme: More work required )
        line_width = settings.linewidth
        angle = rad_angle(x2, y2, x1, y1)
        x2, y2 = actual_line_end(x2, y2, angle, line_width)
    return ["line", (x1, y1, x2, y2), settings, parse_node_transform(node)]
コード例 #4
0
def parse_polyline_node(node, state):
    settings = get_settings(node, state)
    parse_marker_attribute(node, settings)

    points = node.attributes['points'].value.strip()
    points = points.replace(" ", ",")  # Fixme
    vals = [float(coord) for coord in points.split(',') if len(coord) > 0]

    if settings.arrow in ('front', 'both'):
        angle = rad_angle(vals[-2], vals[-1], vals[-4], vals[-3])
        vals[-2], vals[-1] = actual_line_end(vals[-2], vals[-1], angle,
                                             settings.linewidth)

    return ["polyline", vals, settings, parse_node_transform(node)]
コード例 #5
0
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
コード例 #6
0
def parsePolyLineNode(node):
    s = getSettings(node)
    arrowhead = node.hasAttribute("marker-end") and node.attributes[
        "marker-end"].value == "url(#Arrowhead)"
    arrowtail = node.hasAttribute("marker-start") and node.attributes[
        "marker-start"].value == "url(#Arrowtail)"
    if arrowhead and arrowtail:
        s.arrow = 3
    elif arrowtail:
        s.arrow = 2
    elif arrowhead:
        s.arrow = 1
    else:
        s.arrow = 0
    points = node.attributes['points'].value.strip()
    points = points.replace(" ", ",")  # Fixme
    vals = [float(coord) for coord in points.split(',') if len(coord) > 0]

    if arrowhead:
        angle = rad_angle(vals[-2], vals[-1], vals[-4], vals[-3])
        vals[-2], vals[-1] = actual_line_end(vals[-2], vals[-1], angle,
                                             s.linewidth)
    return ["polyline", vals, s, parseNodeTransform(node)]