diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extensions/print_pdf.py | 2 | ||||
| -rw-r--r-- | lib/output.py | 23 | ||||
| -rw-r--r-- | lib/svg/rendering.py | 59 |
3 files changed, 34 insertions, 50 deletions
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index befb7861..387e246b 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -199,7 +199,7 @@ class Print(InkstitchExtension): def render_svgs(self, stitch_plan, realistic=False): svg = deepcopy(self.document).getroot() - render_stitch_plan(svg, stitch_plan, realistic) + render_stitch_plan(svg, stitch_plan, realistic, visual_commands=False) self.strip_namespaces(svg) diff --git a/lib/output.py b/lib/output.py index 21622765..fbcdea6c 100644 --- a/lib/output.py +++ b/lib/output.py @@ -1,12 +1,11 @@ -import pyembroidery import sys -import simpletransform +import pyembroidery from .commands import global_command from .i18n import _ from .stitch_plan import Stitch -from .svg import PIXELS_PER_MM, get_doc_size, get_viewbox_transform +from .svg import PIXELS_PER_MM from .utils import Point @@ -28,24 +27,14 @@ def _string_to_floats(string): return [float(num) for num in floats] -def get_origin(svg): +def get_origin(svg, (minx, miny, maxx, maxy)): origin_command = global_command(svg, "origin") if origin_command: return origin_command.point else: - # default: center of the canvas - - doc_size = list(get_doc_size(svg)) - - # convert the size from viewbox-relative to real-world pixels - viewbox_transform = get_viewbox_transform(svg) - simpletransform.applyTransformToPoint(simpletransform.invertTransform(viewbox_transform), doc_size) - - default = [doc_size[0] / 2.0, doc_size[1] / 2.0] - simpletransform.applyTransformToPoint(viewbox_transform, default) - default = Point(*default) - + bounding_box_center = [(maxx+minx)/2, (maxy+miny)/2] + default = Point(*bounding_box_center) return default @@ -56,7 +45,7 @@ def jump_to_stop_point(pattern, svg): def write_embroidery_file(file_path, stitch_plan, svg, settings={}): - origin = get_origin(svg) + origin = get_origin(svg, stitch_plan.bounding_box) pattern = pyembroidery.EmbPattern() stitch = Stitch(0, 0) diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py index 074380a7..2711f12a 100644 --- a/lib/svg/rendering.py +++ b/lib/svg/rendering.py @@ -5,13 +5,10 @@ import simplepath import simplestyle import simpletransform +from .tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL, SVG_DEFS_TAG, SVG_GROUP_TAG, SVG_PATH_TAG +from .units import PIXELS_PER_MM, get_viewbox_transform from ..i18n import _ -from ..utils import Point -from ..utils import cache -from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG, SVG_DEFS_TAG -from .units import PIXELS_PER_MM -from .units import get_viewbox_transform - +from ..utils import Point, cache # The stitch vector path looks like this: # _______ @@ -172,21 +169,19 @@ 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(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) - })) + destination.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 -def color_block_to_paths(color_block, svg, destination): +def color_block_to_paths(color_block, svg, destination, visual_commands): # If we try to import these above, we get into a mess of circular # imports. from ..commands import add_commands @@ -199,23 +194,23 @@ def color_block_to_paths(color_block, svg, destination): for point_list in color_block_to_point_lists(color_block): if first: first = False - else: + elif visual_commands: add_commands(Stroke(destination[-1]), ["trim"]) color = color_block.color.visible_on_white.to_hex_str() - path = inkex.etree.Element( - SVG_PATH_TAG, - {'style': simplestyle.formatStyle( - {'stroke': color, - 'stroke-width': "0.4", - 'fill': 'none'}), - 'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list), - 'transform': get_correction_transform(svg), - 'embroider_manual_stitch': 'true' - }) + path = inkex.etree.Element(SVG_PATH_TAG, { + 'style': simplestyle.formatStyle({ + 'stroke': color, + 'stroke-width': "0.4", + 'fill': 'none' + }), + 'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list), + 'transform': get_correction_transform(svg), + 'embroider_manual_stitch': 'true' + }) destination.append(path) - if path is not None: + if path is not None and visual_commands: if color_block.trim_after: add_commands(Stroke(path), ["trim"]) @@ -223,7 +218,7 @@ def color_block_to_paths(color_block, svg, destination): add_commands(Stroke(path), ["stop"]) -def render_stitch_plan(svg, stitch_plan, realistic=False): +def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True): layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") if layer is None: layer = inkex.etree.Element(SVG_GROUP_TAG, @@ -247,7 +242,7 @@ def render_stitch_plan(svg, stitch_plan, realistic=False): if realistic: color_block_to_realistic_stitches(color_block, svg, group) else: - color_block_to_paths(color_block, svg, group) + color_block_to_paths(color_block, svg, group, visual_commands) if realistic: defs = svg.find(SVG_DEFS_TAG) |
