コード例 #1
0
def create_simple_line(obj, state):
    """Creates an SVG <line> element from a Faint Line object."""

    element = ET.Element('line')
    points = obj.get_points()
    assert len(points) == 4
    element.set('x1', str(points[0]))
    element.set('y1', str(points[1]))

    arrow = obj.arrow
    state.set_arrow(arrow)

    # Fixme: Duplicates poly-line
    if arrow == 'front':
        angle = rad_angle(points[2], points[3], points[0], points[1])
        x, y = arrow_line_end(points[2], points[3], angle, obj.linewidth)
        element.set('x2', str(x))
        element.set('y2', str(y))
    else:
        element.set('x2', str(points[2]))
        element.set('y2', str(points[3]))

    element.set('style', svg_line_style(obj, state) + svg_line_dash_style(obj))

    if arrow == 'front' or arrow == 'both':
        element.set('marker-end', 'url(#Arrowhead)')
    if arrow == 'back' or arrow == 'both':
        element.set('marker-start', 'url(#Arrowtail)')

    return element
コード例 #2
0
def create_simple_line(obj, state):
    """Creates an SVG <line> element from a Faint Line object."""

    element = ET.Element('line')
    points = obj.get_points()
    assert len(points) == 4
    element.set('x1', str(points[0]))
    element.set('y1', str(points[1]))

    arrowhead = obj.get_arrowhead()
    if arrowhead == 1 or arrowhead == 3:
        state.arrowhead = True
    if arrowhead == 2 or arrowhead == 3:
        state.arrowtail = True

    if arrowhead == 1:
        angle = rad_angle(points[2], points[3], points[0], points[1])
        x, y = arrow_line_end(points[2], points[3], angle, obj.get_linewidth())
        element.set('x2', str(x))
        element.set('y2', str(y))
    else:
        element.set('x2', str(points[2]))
        element.set('y2', str(points[3]))

    element.set('style', svg_line_style(obj, state) + svg_line_dash_style(obj))
    if arrowhead == 1 or arrowhead == 3:
        element.set('marker-end', 'url(#Arrowhead)')
    if arrowhead == 2 or arrowhead == 3:
        element.set('marker-start', 'url(#Arrowtail)')
    return element
コード例 #3
0
def create_polyline(obj, state):
    """Creates an SVG <polyline> element from a Faint Line."""

    element = ET.Element('polyline')
    points = obj.get_points()

    arrow = obj.arrow
    state.set_arrow(arrow)

    if arrow == 'front':
        angle = rad_angle(points[-2], points[-1], points[-4], points[-3])
        x, y = arrow_line_end(points[-2], points[-1], angle, obj.linewidth)
        points[-2] = x
        points[-1] = y

    point_str = ",".join([str(pt) for pt in points])
    element.set('points', point_str)

    style = svg_line_style(obj, state) + svg_line_dash_style(obj) + "fill:none"
    element.set('style', style)

    if arrow == 'front' or arrow == 'both':
        element.set('marker-end', 'url(#Arrowhead)')
    elif arrow == 'back' or arrow == 'both':
        element.set('marker-start', 'url(#Arrowtail)')
    return element
コード例 #4
0
def create_polyline(obj, state):
    """Creates an SVG <polyline> element from a Faint Line."""

    element = ET.Element('polyline')
    points = obj.get_points()

    # Fixme: duplication of create_simple_line
    arrowhead = obj.get_arrowhead()

    if arrowhead == 1 or arrowhead == 3:
        state.arrowhead = True
    if arrowhead == 2 or arrowhead == 3:
        state.arrowtail = True

    if arrowhead == 1:
        angle = rad_angle(points[-2], points[-1], points[-4], points[-3])
        x, y = arrow_line_end(points[-2], points[-1], angle,
                              obj.get_linewidth())
        points[-2] = x
        points[-1] = y

    point_str = ",".join([str(pt) for pt in points])
    element.set('points', point_str)

    style = svg_line_style(obj, state) + svg_line_dash_style(obj) + "fill:none"
    element.set('style', style)

    if arrowhead == 1 or arrowhead == 3:
        element.set('marker-end', 'url(#Arrowhead)')
    if arrowhead == 2 or arrowhead == 3:
        element.set('marker-start', 'url(#Arrowtail)')
    return element
コード例 #5
0
def create_simple_line(obj, state):
    """Creates an SVG <line> element from a Faint Line object."""

    element = ET.Element('line')
    points = obj.get_points()
    assert len(points) == 4
    element.set('x1', str(points[0]))
    element.set('y1', str(points[1]))

    arrow = obj.arrow
    if arrow != 'none': # Fixme: Duplicates create_polyline
        arrow_url = state.add_arrowhead(obj.fg)

    # Fixme: Duplicates poly-line
    if arrow == 'front':
        angle = rad_angle(points[2], points[3], points[0], points[1])
        x, y = arrow_line_end(points[2], points[3], angle, obj.linewidth)
        element.set('x2', str(x))
        element.set('y2', str(y))
    else:
        element.set('x2', str(points[2]))
        element.set('y2', str(points[3]))

    element.set('style', svg_line_style(obj, state) + svg_line_dash_style(obj))

    if arrow != 'none':
        # Fixme: Only arrow-head
        element.set('marker-end', 'url(#{marker_id})'.format(marker_id=arrow_url))

    return element
コード例 #6
0
def create_polyline(obj, state):
    """Creates an SVG <polyline> element from a Faint Line."""

    element = ET.Element('polyline')
    points = obj.get_points()

    arrow = obj.arrow
    if arrow != 'none':
        arrow_url = state.add_arrowhead(obj.fg)

    if arrow == 'front':
        angle = rad_angle(points[-2], points[-1], points[-4], points[-3])
        x, y = arrow_line_end(points[-2], points[-1],
            angle, obj.linewidth)
        points[-2] = x
        points[-1] = y

    point_str = ",".join([str(pt) for pt in points])
    element.set('points', point_str)

    style = svg_line_style(obj, state) + svg_line_dash_style(obj) + "fill:none"
    element.set('style', style)

    if arrow != 'none': # Fixme: Duplicates create_line
        element.set('marker-end', 'url(#{marker_id})'.format(marker_id=arrow_url))
    return element
コード例 #7
0
def parse_line(node, state):
    """Parses an SVG <line> element."""
    state = state.updated(node)

    points = [
        svg_coord_attr(node.get(s, '0'), state)
        for s in ('x1', 'y1', 'x2', 'y2')
    ]

    if state.settings.arrow == 'front':
        x0, y0, x1, y1 = points
        angle = rad_angle(x0, y0, x1, y1)
        x, y = arrow_line_end(x1, y1, angle, state.settings.linewidth)
        points[-2] = x
        points[-1] = y

    return state.props.Line(points, state.settings)
コード例 #8
0
def parse_polyline(node, state):
    """Parses an SVG <polyline>-element."""
    state = state.updated(node)

    points = parse_points(node.get('points'))

    if state.settings.arrow == 'front':
        x0, y0, x1, y1 = points[-4:]
        angle = rad_angle(x0, y0, x1, y1)
        x, y = arrow_line_end(x1, y1, angle, state.settings.linewidth)
        points[-2] = x
        points[-1] = y

    if len(points) % 2 != 0:
        state.add_warning("Odd number of coordinates for polyline%s." %
                          maybe_id_ref(node))
        # SVG 1.1 F2 "Error processing" says
        # Render polyline and polygons with invalid points up to the
        # erroneous point.
        points = points[:-1]

    return state.props.Line(points, state.settings)