From 4c986117bfe1f2caa8280d4b0ddbeec69f41b18d Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 26 May 2018 21:26:40 -0400 Subject: first attempt at realistic rendering --- lib/extensions/print_pdf.py | 2 +- lib/svg/svg.py | 157 ++++++++++++++++++++++++++++++++++++++------ lib/threads/color.py | 15 +++++ lib/utils/geometry.py | 6 ++ 4 files changed, 159 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index baeb7eba..43e53318 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -119,7 +119,7 @@ class PrintPreviewServer(Thread): def start_watcher(): self.watcher_thread = Thread(target=self.watch) self.watcher_thread.daemon = True - self.watcher_thread.start() + #self.watcher_thread.start() @self.app.route('/') def index(): diff --git a/lib/svg/svg.py b/lib/svg/svg.py index 852215f2..147fdc84 100644 --- a/lib/svg/svg.py +++ b/lib/svg/svg.py @@ -1,9 +1,124 @@ -import simpletransform, simplestyle, inkex +import math +import simpletransform, simplestyle, simplepath, inkex -from .units import get_viewbox_transform -from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG +from .units import get_viewbox_transform, PIXELS_PER_MM +from .tags import SVG_GROUP_TAG, INKSCAPE_LABEL, INKSCAPE_GROUPMODE, SVG_PATH_TAG, SVG_DEFS_TAG from ..i18n import _ -from ..utils import cache +from ..utils import cache, Point + + +# The stitch vector path looks like this: +# _______ +# (_______) +# +# It's 0.4mm high, which is the approximate thickness of common machine embroidery threads. + +# 1.52 pixels = 0.4mm +stitch_height = 1.52 + +# This vector path starts at the origin and contains a placeholder (%s) for the stitch length. +stitch_path = "M0,0c0.386,0,0.417,0.378,0.428,0.759c0.012,0.382,-0.048,0.754,-0.428,0.759h-%sc-0.357,-0.003,-0.399,-0.376,-0.413,-0.759c-0.014,-0.382,0.067,-0.759,0.413,-0.759z" + +# This filter makes the above stitch path look like a real stitch with lighting. +realistic_filter = """ + + + + + + + + + + + + + + + + + + +""" + +def realistic_stitch(start, end): + """Generate a stitch vector path given a start and end point.""" + + end = Point(*end) + start = Point(*start) + + stitch_length = (end - start).length() + stitch_center = (end + start) / 2.0 + stitch_direction = (end - start) + stitch_angle = math.atan2(stitch_direction.y, stitch_direction.x) + + stitch_length = max(0, stitch_length - 0.2 * PIXELS_PER_MM) + + # create the path by filling in the length in the template + path = simplepath.parsePath(stitch_path % stitch_length) + + simplepath.scalePath(path, 1, 0.8) + + # rotate the path to match the stitch + rotation_center_x = -stitch_length / 2.0 + rotation_center_y = stitch_height / 2.0 + simplepath.rotatePath(path, stitch_angle, cx=rotation_center_x, cy=rotation_center_y) + + # move the path to the location of the stitch + simplepath.translatePath(path, stitch_center.x, stitch_center.y) + + return simplepath.formatPath(path) def color_block_to_point_lists(color_block): @@ -37,22 +152,21 @@ def color_block_to_paths(color_block, svg): # We could emit just a single path with one subpath per point list, but # emitting multiple paths makes it easier for the user to manipulate them. for point_list in color_block_to_point_lists(color_block): - color = color_block.color.visible_on_white.to_hex_str() - paths.append(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', - 'embroider_trim_after': 'true', - })) - - # no need to trim at the end of a thread color - if paths: - paths[-1].attrib.pop('embroider_trim_after') + 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 @@ -78,4 +192,7 @@ def render_stitch_plan(svg, stitch_plan): INKSCAPE_LABEL: "color block %d" % (i + 1)}) group.extend(color_block_to_paths(color_block, svg)) + defs = svg.find(SVG_DEFS_TAG) + defs.append(inkex.etree.fromstring(realistic_filter)) + svg.append(layer) diff --git a/lib/threads/color.py b/lib/threads/color.py index af474127..fede2ecc 100644 --- a/lib/threads/color.py +++ b/lib/threads/color.py @@ -80,3 +80,18 @@ class ThreadColor(object): color = tuple(value * 255 for value in color) return ThreadColor(color, name=self.name, number=self.number, manufacturer=self.manufacturer) + + @property + def darker(self): + hls = list(colorsys.rgb_to_hls(*self.rgb_normalized)) + + # Capping lightness should make the color visible without changing it + # too much. + hls[1] *= 0.75 + + color = colorsys.hls_to_rgb(*hls) + + # convert back to values in the range of 0-255 + color = tuple(value * 255 for value in color) + + return ThreadColor(color, name=self.name, number=self.number, manufacturer=self.manufacturer) diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py index 61b98bcb..7ff9b1cd 100644 --- a/lib/utils/geometry.py +++ b/lib/utils/geometry.py @@ -71,6 +71,12 @@ class Point: else: raise ValueError("cannot multiply Point by %s" % type(other)) + def __div__(self, other): + if isinstance(other, (int, float)): + return self * (1.0 / other) + else: + raise ValueErorr("cannot divide Point by %s" % type(other)) + def __repr__(self): return "Point(%s,%s)" % (self.x, self.y) -- cgit v1.2.3 From d7d2328b59e4a0f0f93830d636b74c2d92ab9d56 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 27 May 2018 15:36:44 -0400 Subject: tinker with rendering --- lib/svg/svg.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/svg/svg.py b/lib/svg/svg.py index 147fdc84..8921ccec 100644 --- a/lib/svg/svg.py +++ b/lib/svg/svg.py @@ -11,23 +11,23 @@ from ..utils import cache, Point # _______ # (_______) # -# It's 0.4mm high, which is the approximate thickness of common machine embroidery threads. +# It's 0.32mm high, which is the approximate thickness of common machine embroidery threads. -# 1.52 pixels = 0.4mm -stitch_height = 1.52 +# 1.216 pixels = 0.32mm +stitch_height = 1.216 # This vector path starts at the origin and contains a placeholder (%s) for the stitch length. -stitch_path = "M0,0c0.386,0,0.417,0.378,0.428,0.759c0.012,0.382,-0.048,0.754,-0.428,0.759h-%sc-0.357,-0.003,-0.399,-0.376,-0.413,-0.759c-0.014,-0.382,0.067,-0.759,0.413,-0.759z" +stitch_path = "M0,0c0.386,0,0.417,0.302,0.428,0.607c0.012,0.306,-0.048,0.603,-0.428,0.607h-%sc-0.357,-0.002,-0.399,-0.3,-0.413,-0.607c-0.014,-0.305,0.067,-0.607,0.413,-0.607z" # This filter makes the above stitch path look like a real stitch with lighting. realistic_filter = """ + x="-0.1" + width="1.2" + y="-0.1" + height="1.2"> + surfaceScale="30"> @@ -108,15 +108,13 @@ def realistic_stitch(start, end): # create the path by filling in the length in the template path = simplepath.parsePath(stitch_path % stitch_length) - simplepath.scalePath(path, 1, 0.8) - # rotate the path to match the stitch rotation_center_x = -stitch_length / 2.0 rotation_center_y = stitch_height / 2.0 simplepath.rotatePath(path, stitch_angle, cx=rotation_center_x, cy=rotation_center_y) # move the path to the location of the stitch - simplepath.translatePath(path, stitch_center.x, stitch_center.y) + simplepath.translatePath(path, stitch_center.x - rotation_center_x, stitch_center.y - rotation_center_y) return simplepath.formatPath(path) -- cgit v1.2.3 From a9b834878b618a3aea6c343e71a2df3046bde3a7 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 29 May 2018 20:55:46 -0400 Subject: optimize path --- lib/svg/svg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/svg/svg.py b/lib/svg/svg.py index 8921ccec..655ddc58 100644 --- a/lib/svg/svg.py +++ b/lib/svg/svg.py @@ -17,7 +17,7 @@ from ..utils import cache, Point stitch_height = 1.216 # This vector path starts at the origin and contains a placeholder (%s) for the stitch length. -stitch_path = "M0,0c0.386,0,0.417,0.302,0.428,0.607c0.012,0.306,-0.048,0.603,-0.428,0.607h-%sc-0.357,-0.002,-0.399,-0.3,-0.413,-0.607c-0.014,-0.305,0.067,-0.607,0.413,-0.607z" +stitch_path = "M0,0c0.4,0,0.4,0.3,0.4,0.6c0,0.3,-0.1,0.6,-0.4,0.6v0.2,-0.2h-%sc-0.4,0,-0.4,-0.3,-0.4,-0.6c0,-0.3,0.1,-0.6,0.4,-0.6v-0.2,0.2z" # This filter makes the above stitch path look like a real stitch with lighting. realistic_filter = """ -- cgit v1.2.3 From 0348b03b91f64c43c5d0adba2f41d0ef21a82c9a Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 30 May 2018 20:10:11 -0400 Subject: add realistic boolean param to render_stitch_plan() --- lib/svg/realistic_rendering.py | 129 ++++++++++++++++++++++++++++++++ lib/svg/svg.py | 166 +++++++++++------------------------------ 2 files changed, 171 insertions(+), 124 deletions(-) create mode 100644 lib/svg/realistic_rendering.py (limited to 'lib') diff --git a/lib/svg/realistic_rendering.py b/lib/svg/realistic_rendering.py new file mode 100644 index 00000000..e31534da --- /dev/null +++ b/lib/svg/realistic_rendering.py @@ -0,0 +1,129 @@ +import simplepath +import math + +from .units import PIXELS_PER_MM +from ..utils import cache, Point + +# The stitch vector path looks like this: +# _______ +# (_______) +# +# It's 0.32mm high, which is the approximate thickness of common machine +# embroidery threads. + +# 1.216 pixels = 0.32mm +stitch_height = 1.216 + +# This vector path starts at the upper right corner of the stitch shape and +# proceeds counter-clockwise.and contains a placeholder (%s) for the stitch +# length. +# +# It contains two invisible "whiskers" of zero width that go above and below +# to ensure that the SVG renderer allocates a large enough canvas area when +# computing the gaussian blur steps. Otherwise, we'd have to expand the +# width and height attributes of the tag to add more buffer space. +# The width and height are specified in multiples of the bounding box +# size, It's the bounding box aligned with the global SVG canvas's axes, not +# the axes of the stitch itself. That means that having a big enough value +# to add enough padding on the long sides of the stitch would waste a ton +# of space on the short sides and significantly slow down rendering. +stitch_path = "M0,0c0.4,0,0.4,0.3,0.4,0.6c0,0.3,-0.1,0.6,-0.4,0.6v0.2,-0.2h-%sc-0.4,0,-0.4,-0.3,-0.4,-0.6c0,-0.3,0.1,-0.6,0.4,-0.6v-0.2,0.2z" + +# This filter makes the above stitch path look like a real stitch with lighting. +realistic_filter = """ + + + + + + + + + + + + + + + + + + +""" + +def realistic_stitch(start, end): + """Generate a stitch vector path given a start and end point.""" + + end = Point(*end) + start = Point(*start) + + stitch_length = (end - start).length() + stitch_center = (end + start) / 2.0 + stitch_direction = (end - start) + stitch_angle = math.atan2(stitch_direction.y, stitch_direction.x) + + stitch_length = max(0, stitch_length - 0.2 * PIXELS_PER_MM) + + # create the path by filling in the length in the template + path = simplepath.parsePath(stitch_path % stitch_length) + + # rotate the path to match the stitch + rotation_center_x = -stitch_length / 2.0 + rotation_center_y = stitch_height / 2.0 + simplepath.rotatePath(path, stitch_angle, cx=rotation_center_x, cy=rotation_center_y) + + # move the path to the location of the stitch + simplepath.translatePath(path, stitch_center.x - rotation_center_x, stitch_center.y - rotation_center_y) + + return simplepath.formatPath(path) diff --git a/lib/svg/svg.py b/lib/svg/svg.py index 655ddc58..5552abd8 100644 --- a/lib/svg/svg.py +++ b/lib/svg/svg.py @@ -1,122 +1,10 @@ -import math -import simpletransform, simplestyle, simplepath, inkex +import simpletransform, simplestyle, inkex -from .units import get_viewbox_transform, PIXELS_PER_MM +from .units import get_viewbox_transform 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, Point - - -# The stitch vector path looks like this: -# _______ -# (_______) -# -# It's 0.32mm high, which is the approximate thickness of common machine embroidery threads. - -# 1.216 pixels = 0.32mm -stitch_height = 1.216 - -# This vector path starts at the origin and contains a placeholder (%s) for the stitch length. -stitch_path = "M0,0c0.4,0,0.4,0.3,0.4,0.6c0,0.3,-0.1,0.6,-0.4,0.6v0.2,-0.2h-%sc-0.4,0,-0.4,-0.3,-0.4,-0.6c0,-0.3,0.1,-0.6,0.4,-0.6v-0.2,0.2z" - -# This filter makes the above stitch path look like a real stitch with lighting. -realistic_filter = """ - - - - - - - - - - - - - - - - - - -""" - -def realistic_stitch(start, end): - """Generate a stitch vector path given a start and end point.""" - - end = Point(*end) - start = Point(*start) - - stitch_length = (end - start).length() - stitch_center = (end + start) / 2.0 - stitch_direction = (end - start) - stitch_angle = math.atan2(stitch_direction.y, stitch_direction.x) - - stitch_length = max(0, stitch_length - 0.2 * PIXELS_PER_MM) - - # create the path by filling in the length in the template - path = simplepath.parsePath(stitch_path % stitch_length) - - # rotate the path to match the stitch - rotation_center_x = -stitch_length / 2.0 - rotation_center_y = stitch_height / 2.0 - simplepath.rotatePath(path, stitch_angle, cx=rotation_center_x, cy=rotation_center_y) - - # move the path to the location of the stitch - simplepath.translatePath(path, stitch_center.x - rotation_center_x, stitch_center.y - rotation_center_y) - - return simplepath.formatPath(path) +from ..utils import cache def color_block_to_point_lists(color_block): @@ -145,10 +33,9 @@ def get_correction_transform(svg): return transform -def color_block_to_paths(color_block, svg): +def color_block_to_realistic_stitches(color_block, svg): paths = [] - # We could emit just a single path with one subpath per point list, but - # emitting multiple paths makes it easier for the user to manipulate them. + 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] @@ -168,8 +55,31 @@ def color_block_to_paths(color_block, svg): 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 + # emitting multiple paths makes it easier for the user to manipulate them. + for point_list in color_block_to_point_lists(color_block): + color = color_block.color.visible_on_white.to_hex_str() + paths.append(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', + 'embroider_trim_after': 'true', + })) + + # no need to trim at the end of a thread color + if paths: + paths[-1].attrib.pop('embroider_trim_after') + + 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, @@ -188,9 +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)) - - defs = svg.find(SVG_DEFS_TAG) - defs.append(inkex.etree.fromstring(realistic_filter)) + 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)) -- cgit v1.2.3 From ae286b17ad450c530d1822208cce75db3bd3faf2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 30 May 2018 22:25:43 -0400 Subject: refactor print_pdf and generate realistic previews --- lib/extensions/print_pdf.py | 86 ++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index 43e53318..91562c09 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -21,7 +21,7 @@ import requests from .base import InkstitchExtension from ..i18n import _, translation as inkstitch_translation from ..svg import PIXELS_PER_MM, render_stitch_plan -from ..svg.tags import SVG_GROUP_TAG +from ..svg.tags import SVG_GROUP_TAG, INKSCAPE_GROUPMODE from ..stitch_plan import patches_to_stitch_plan from ..threads import ThreadCatalog @@ -94,6 +94,8 @@ class PrintPreviewServer(Thread): self.html = kwargs.pop('html') self.metadata = kwargs.pop('metadata') self.stitch_plan = kwargs.pop('stitch_plan') + self.realistic_overview_svg = kwargs.pop('realistic_overview_svg') + self.realistic_color_block_svgs = kwargs.pop('realistic_color_block_svgs') Thread.__init__(self, *args, **kwargs) self.daemon = True self.last_request_time = None @@ -119,7 +121,7 @@ class PrintPreviewServer(Thread): def start_watcher(): self.watcher_thread = Thread(target=self.watch) self.watcher_thread.daemon = True - #self.watcher_thread.start() + self.watcher_thread.start() @self.app.route('/') def index(): @@ -202,6 +204,13 @@ class PrintPreviewServer(Thread): return jsonify(threads) + @self.app.route('/realistic', methods=['GET']) + def get_realistic(): + return jsonify({ + 'overview': self.realistic_overview_svg, + 'color_blocks': self.realistic_color_block_svgs + }) + def stop(self): # for whatever reason, shutting down only seems possible in # the context of a flask request, so we'll just make one @@ -295,38 +304,24 @@ class Print(InkstitchExtension): return env - def strip_namespaces(self): + def strip_namespaces(self, svg): # namespace prefixes seem to trip up HTML, so get rid of them - for element in self.document.iter(): + for element in svg.iter(): if element.tag[0]=='{': element.tag = element.tag[element.tag.index('}',1) + 1:] - def effect(self): - # It doesn't really make sense to print just a couple of selected - # objects. It's almost certain they meant to print the whole design. - # If they really wanted to print just a few objects, they could set - # the rest invisible temporarily. - self.selected = {} + def render_svgs(self, stitch_plan, realistic=False): + svg = deepcopy(self.document).getroot() + render_stitch_plan(svg, stitch_plan, realistic) - if not self.get_elements(): - return - - self.hide_all_layers() - - patches = self.elements_to_patches(self.elements) - stitch_plan = patches_to_stitch_plan(patches) - palette = ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette']) - render_stitch_plan(self.document.getroot(), stitch_plan) - - self.strip_namespaces() + self.strip_namespaces(svg) # Now the stitch plan layer will contain a set of groups, each # corresponding to a color block. We'll create a set of SVG files # corresponding to each individual color block and a final one # for all color blocks together. - svg = self.document.getroot() - layers = svg.findall("./g[@{http://www.inkscape.org/namespaces/inkscape}groupmode='layer']") + layers = svg.findall("./g[@%s='layer']" % INKSCAPE_GROUPMODE) stitch_plan_layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']") # First, delete all of the other layers. We don't need them and they'll @@ -335,9 +330,9 @@ class Print(InkstitchExtension): if layer is not stitch_plan_layer: svg.remove(layer) - overview_svg = inkex.etree.tostring(self.document) - + overview_svg = inkex.etree.tostring(svg) color_block_groups = stitch_plan_layer.getchildren() + color_block_svgs = [] for i, group in enumerate(color_block_groups): # clear the stitch plan layer @@ -347,12 +342,15 @@ class Print(InkstitchExtension): stitch_plan_layer.append(group) # save an SVG preview - stitch_plan.color_blocks[i].svg_preview = inkex.etree.tostring(self.document) + color_block_svgs.append(inkex.etree.tostring(svg)) + + return overview_svg, color_block_svgs + def render_html(self, stitch_plan, overview_svg, selected_palette): env = self.build_environment() template = env.get_template('index.html') - html = template.render( + return template.render( view = {'client_overview': False, 'client_detailedview': False, 'operator_overview': True, 'operator_detailedview': True}, logo = {'src' : '', 'title' : 'LOGO'}, date = date.today(), @@ -371,14 +369,38 @@ class Print(InkstitchExtension): svg_overview = overview_svg, color_blocks = stitch_plan.color_blocks, palettes = ThreadCatalog().palette_names(), - selected_palette = palette, + selected_palette = selected_palette, ) - # We've totally mucked with the SVG. Restore it so that we can save - # metadata into it. - self.document = deepcopy(self.original_document) + def effect(self): + # It doesn't really make sense to print just a couple of selected + # objects. It's almost certain they meant to print the whole design. + # If they really wanted to print just a few objects, they could set + # the rest invisible temporarily. + self.selected = {} + + if not self.get_elements(): + return + + patches = self.elements_to_patches(self.elements) + stitch_plan = patches_to_stitch_plan(patches) + palette = ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette']) + + overview_svg, color_block_svgs = self.render_svgs(stitch_plan, realistic=False) + realistic_overview_svg, realistic_color_block_svgs = self.render_svgs(stitch_plan, realistic=True) + + for i, svg in enumerate(color_block_svgs): + stitch_plan.color_blocks[i].svg_preview = svg + + html = self.render_html(stitch_plan, overview_svg, palette) - print_server = PrintPreviewServer(html=html, metadata=self.get_inkstitch_metadata(), stitch_plan=stitch_plan) + print_server = PrintPreviewServer( + html=html, + metadata=self.get_inkstitch_metadata(), + stitch_plan=stitch_plan, + realistic_overview_svg=realistic_overview_svg, + realistic_color_block_svgs=realistic_color_block_svgs + ) print_server.start() time.sleep(1) -- cgit v1.2.3 From f10393989bdd2e7dd1056930ba060aab3870a592 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 3 Jun 2018 23:24:26 -0400 Subject: realistic rendering checkboxes --- lib/extensions/print_pdf.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index 91562c09..3dcb2743 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -206,10 +206,10 @@ class PrintPreviewServer(Thread): @self.app.route('/realistic', methods=['GET']) def get_realistic(): - return jsonify({ - 'overview': self.realistic_overview_svg, - 'color_blocks': self.realistic_color_block_svgs - }) + realistic = { 'overview': self.realistic_overview_svg } + for i, svg in enumerate(self.realistic_color_block_svgs): + realistic["block%d" % i] = svg + return jsonify(realistic) def stop(self): # for whatever reason, shutting down only seems possible in -- cgit v1.2.3 From fb273a6daa0654a48ca609eef470343733878146 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 8 Jun 2018 23:16:08 -0400 Subject: rasterize realistic SVGs at 600dpi --- lib/extensions/print_pdf.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py index 3dcb2743..6e2eff58 100644 --- a/lib/extensions/print_pdf.py +++ b/lib/extensions/print_pdf.py @@ -204,12 +204,13 @@ class PrintPreviewServer(Thread): return jsonify(threads) - @self.app.route('/realistic', methods=['GET']) - def get_realistic(): - realistic = { 'overview': self.realistic_overview_svg } - for i, svg in enumerate(self.realistic_color_block_svgs): - realistic["block%d" % i] = svg - return jsonify(realistic) + @self.app.route('/realistic/block', methods=['GET']) + def get_realistic_block(index): + return Response(self.realistic_color_block_svgs[index], mimetype='image/svg+xml') + + @self.app.route('/realistic/overview', methods=['GET']) + def get_realistic_overview(): + return Response(self.realistic_overview_svg, mimetype='image/svg+xml') def stop(self): # for whatever reason, shutting down only seems possible in -- cgit v1.2.3 From ba9b50ab861087d094ee3f85324c65092c1b9f78 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 9 Jun 2018 21:23:21 -0400 Subject: fix latent bug in base.py --- lib/extensions/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/extensions/base.py b/lib/extensions/base.py index ff587ca5..52321cfc 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -63,10 +63,10 @@ class InkStitchMetadata(MutableMapping): else: item.getparent().remove(item) - def _find_item(self, name): + def _find_item(self, name, create=True): tag = inkex.addNS(name, "inkstitch") item = self.metadata.find(tag) - if item is None: + if item is None and create: item = inkex.etree.SubElement(self.metadata, tag) return item @@ -80,9 +80,9 @@ class InkStitchMetadata(MutableMapping): return None def __delitem__(self, name): - item = self._find_item(name) + item = self._find_item(name, create=False) - if item: + if item is not None: self.metadata.remove(item) def __iter__(self): -- cgit v1.2.3