inkstitch/lib/elements/utils.py

66 wiersze
2.0 KiB
Python
Czysty Zwykły widok Historia

2021-03-12 04:17:19 +00:00
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
from ..commands import is_command
2020-05-27 16:39:04 +00:00
from ..svg.tags import (EMBROIDERABLE_TAGS, SVG_IMAGE_TAG, SVG_PATH_TAG,
SVG_POLYLINE_TAG, SVG_TEXT_TAG)
from .auto_fill import AutoFill
2020-05-16 21:01:00 +00:00
from .clone import Clone, is_clone
from .element import EmbroideryElement
2020-05-27 16:39:04 +00:00
from .empty_d_object import EmptyDObject
from .fill import Fill
2020-05-16 21:01:00 +00:00
from .image import ImageObject
from .polyline import Polyline
from .satin_column import SatinColumn
from .stroke import Stroke
2020-05-16 21:01:00 +00:00
from .text import TextObject
2020-05-16 21:01:00 +00:00
def node_to_elements(node): # noqa: C901
if node.tag == SVG_POLYLINE_TAG:
return [Polyline(node)]
2020-05-16 21:01:00 +00:00
elif is_clone(node):
return [Clone(node)]
2020-05-27 16:39:04 +00:00
elif node.tag == SVG_PATH_TAG and not node.get('d', ''):
return [EmptyDObject(node)]
2020-05-16 21:01:00 +00:00
elif node.tag in EMBROIDERABLE_TAGS:
element = EmbroideryElement(node)
if element.get_boolean_param("satin_column") and element.get_style("stroke"):
return [SatinColumn(node)]
else:
elements = []
2020-05-18 16:46:26 +00:00
if element.get_style("fill", "black") and not element.get_style('fill-opacity', 1) == "0":
if element.get_boolean_param("auto_fill", True):
elements.append(AutoFill(node))
else:
elements.append(Fill(node))
if element.get_style("stroke"):
if not is_command(element.node):
elements.append(Stroke(node))
if element.get_boolean_param("stroke_first", False):
elements.reverse()
return elements
2020-05-16 21:01:00 +00:00
elif node.tag == SVG_IMAGE_TAG:
return [ImageObject(node)]
elif node.tag == SVG_TEXT_TAG:
return [TextObject(node)]
else:
return []
def nodes_to_elements(nodes):
elements = []
for node in nodes:
elements.extend(node_to_elements(node))
return elements