summaryrefslogtreecommitdiff
path: root/lib/svg/svg.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/svg/svg.py')
-rw-r--r--lib/svg/svg.py41
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/svg/svg.py b/lib/svg/svg.py
index 852215f2..5552abd8 100644
--- a/lib/svg/svg.py
+++ b/lib/svg/svg.py
@@ -1,7 +1,8 @@
import simpletransform, simplestyle, inkex
from .units import get_viewbox_transform
-from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG
+from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG, SVG_DEFS_TAG
+from .realistic_rendering import realistic_stitch, realistic_filter
from ..i18n import _
from ..utils import cache
@@ -32,6 +33,28 @@ def get_correction_transform(svg):
return transform
+def color_block_to_realistic_stitches(color_block, svg):
+ paths = []
+
+ for point_list in color_block_to_point_lists(color_block):
+ color = color_block.color.visible_on_white.darker.to_hex_str()
+ start = point_list[0]
+ for point in point_list[1:]:
+ paths.append(inkex.etree.Element(
+ SVG_PATH_TAG,
+ {'style': simplestyle.formatStyle(
+ {
+ 'fill': color,
+ 'stroke': 'none',
+ 'filter': 'url(#realistic-stitch-filter)'
+ }),
+ 'd': realistic_stitch(start, point),
+ 'transform': get_correction_transform(svg)
+ }))
+ start = point
+
+ return paths
+
def color_block_to_paths(color_block, svg):
paths = []
# We could emit just a single path with one subpath per point list, but
@@ -56,8 +79,7 @@ def color_block_to_paths(color_block, svg):
return paths
-
-def render_stitch_plan(svg, stitch_plan):
+def render_stitch_plan(svg, stitch_plan, realistic=False):
layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
if layer is None:
layer = inkex.etree.Element(SVG_GROUP_TAG,
@@ -76,6 +98,17 @@ def render_stitch_plan(svg, stitch_plan):
SVG_GROUP_TAG,
{'id': '__color_block_%d__' % i,
INKSCAPE_LABEL: "color block %d" % (i + 1)})
- group.extend(color_block_to_paths(color_block, svg))
+ if realistic:
+ group.extend(color_block_to_realistic_stitches(color_block, svg))
+ else:
+ group.extend(color_block_to_paths(color_block, svg))
svg.append(layer)
+
+ if realistic:
+ defs = svg.find(SVG_DEFS_TAG)
+
+ if defs is None:
+ defs = inkex.etree.SubElement(svg, SVG_DEFS_TAG)
+
+ defs.append(inkex.etree.fromstring(realistic_filter))