diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2021-07-25 07:24:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-25 07:24:34 +0200 |
| commit | 2f35a4a192eb6aa3b68b715da6c1ba984084e0e5 (patch) | |
| tree | 7a28d41ff83730e3bf53ee65b315783497503cec /lib/svg | |
| parent | 36815f977d7236311e9b345c33fbc74390766385 (diff) | |
Fix Style Issues (#1154)
Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/svg')
| -rw-r--r-- | lib/svg/path.py | 3 | ||||
| -rw-r--r-- | lib/svg/rendering.py | 38 |
2 files changed, 18 insertions, 23 deletions
diff --git a/lib/svg/path.py b/lib/svg/path.py index b503cc75..53cf80f2 100644 --- a/lib/svg/path.py +++ b/lib/svg/path.py @@ -4,7 +4,6 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. import inkex -from lxml import etree from .tags import SVG_GROUP_TAG, SVG_LINK_TAG from .units import get_viewbox_transform @@ -96,6 +95,6 @@ def point_lists_to_csp(point_lists): def line_strings_to_path(line_strings): csp = line_strings_to_csp(line_strings) - return etree.Element("path", { + return inkex.PathElement(attrib={ "d": str(inkex.paths.CubicSuperPath(csp)) }) diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py index c28c7003..7be1e8b0 100644 --- a/lib/svg/rendering.py +++ b/lib/svg/rendering.py @@ -4,16 +4,14 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. import math +from math import pi import inkex -from lxml import etree -from math import pi +from .tags import (INKSCAPE_GROUPMODE, INKSCAPE_LABEL, INKSTITCH_ATTRIBS) +from .units import PIXELS_PER_MM, get_viewbox_transform from ..i18n import _ from ..utils import Point, cache -from .tags import (INKSCAPE_GROUPMODE, INKSCAPE_LABEL, INKSTITCH_ATTRIBS, - SVG_DEFS_TAG, SVG_GROUP_TAG, SVG_PATH_TAG) -from .units import PIXELS_PER_MM, get_viewbox_transform # The stitch vector path looks like this: # _______ @@ -174,7 +172,7 @@ def color_block_to_realistic_stitches(color_block, svg, destination): color = color_block.color.visible_on_white.darker.to_hex_str() start = point_list[0] for point in point_list[1:]: - destination.append(etree.Element(SVG_PATH_TAG, { + destination.append(inkex.PathElement(attrib={ 'style': "fill: %s; stroke: none; filter: url(#realistic-stitch-filter);" % color, 'd': realistic_stitch(start, point), 'transform': get_correction_transform(svg) @@ -200,7 +198,7 @@ def color_block_to_paths(color_block, svg, destination, visual_commands): color = color_block.color.visible_on_white.to_hex_str() - path = etree.Element(SVG_PATH_TAG, { + path = inkex.PathElement(attrib={ 'style': "stroke: %s; stroke-width: 0.4; fill: none;" % color, 'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list), 'transform': get_correction_transform(svg), @@ -219,10 +217,11 @@ def color_block_to_paths(color_block, svg, destination, visual_commands): def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True): layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") if layer is None: - layer = etree.Element(SVG_GROUP_TAG, - {'id': '__inkstitch_stitch_plan__', - INKSCAPE_LABEL: _('Stitch Plan'), - INKSCAPE_GROUPMODE: 'layer'}) + layer = inkex.Group(attrib={ + 'id': '__inkstitch_stitch_plan__', + INKSCAPE_LABEL: _('Stitch Plan'), + INKSCAPE_GROUPMODE: 'layer' + }) else: # delete old stitch plan del layer[:] @@ -233,19 +232,16 @@ def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True): svg.append(layer) for i, color_block in enumerate(stitch_plan): - group = etree.SubElement(layer, - SVG_GROUP_TAG, - {'id': '__color_block_%d__' % i, - INKSCAPE_LABEL: "color block %d" % (i + 1)}) + group = inkex.Group(attrib={ + 'id': '__color_block_%d__' % i, + INKSCAPE_LABEL: "color block %d" % (i + 1) + }) + layer.append(group) if realistic: color_block_to_realistic_stitches(color_block, svg, group) else: color_block_to_paths(color_block, svg, group, visual_commands) if realistic: - defs = svg.find(SVG_DEFS_TAG) - - if defs is None: - defs = etree.SubElement(svg, SVG_DEFS_TAG) - - defs.append(etree.fromstring(realistic_filter)) + filter_document = inkex.load_svg(realistic_filter) + svg.defs.append(filter_document.getroot()) |
