def parse_path(node, state): """Parses an SVG <path>-element""" state = state.updated(node) path_def = node.get('d') if path_def is None: state.add_warning("Ignored path-element without definition " "attribute%s." % maybe_id_ref(node)) return path_def = clean_path_definition(path_def) if len(path_def) == 0: state.add_warning("Ignored path-element without definition " "attribute%s." % maybe_id_ref(node)) return try: path_id = state.props.Path(path_def, state.settings) except ValueError: ifaint.copy_text(node.get('d')) # Fixme: Remove state.add_warning("Failed parsing a path definition%s." % maybe_id_ref(node)) return return path_id
def parse_group(node, state, id_to_etree_node=None): """Parses an SVG <g>-element.""" # Fixme: Use id_to_etree_node state = state.updated(node) # Parse the children of the group object_ids = [] for child, func in match_children(node, svg_group_content_functions): result = func(child, state) if result.__class__ is not int: # Expected an object id from the function state.add_warning("Failed parsing child %s of group %s" % (maybe_id_ref(child), maybe_id_ref(node))) else: object_ids.append(result) if len(object_ids) == 0: return return state.props.Group(object_ids)
def parse_polygon(node, state): """Parses an SVG <path>-element.""" state = state.updated(node) points = parse_points(node.get('points', '')) if len(points) % 2 != 0: state.add_warning("Odd number of coordinates for polygon%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.Polygon(points, state.settings)
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)