From f37541c50537899409c24a81eb7f092cdfb1d261 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sun, 17 Oct 2021 19:19:44 +0200 Subject: [PATCH 01/11] added more options to join paths --- .../fablabchemnitz/join_paths/join_paths.inx | 27 ++++---- .../fablabchemnitz/join_paths/join_paths.py | 65 ++++++++++++------- .../fablabchemnitz/join_paths/meta.json | 2 +- 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/extensions/fablabchemnitz/join_paths/join_paths.inx b/extensions/fablabchemnitz/join_paths/join_paths.inx index 46ec34bb..5a744881 100644 --- a/extensions/fablabchemnitz/join_paths/join_paths.inx +++ b/extensions/fablabchemnitz/join_paths/join_paths.inx @@ -1,32 +1,35 @@ - Join Paths / Create Dimples + Join Paths / Create Tabs And Dimples fablabchemnitz.de.join_paths - + true - + 0.0100 + false - + + false false false - + - 45.000 - 4.000 - - - - - + 45.000 + 4.000 + 45.000 + + + + + false diff --git a/extensions/fablabchemnitz/join_paths/join_paths.py b/extensions/fablabchemnitz/join_paths/join_paths.py index d500bb25..194df063 100644 --- a/extensions/fablabchemnitz/join_paths/join_paths.py +++ b/extensions/fablabchemnitz/join_paths/join_paths.py @@ -123,6 +123,7 @@ class JoinPaths(inkex.EffectExtension): def add_arguments(self, pars): pars.add_argument("--optimized", type=inkex.Boolean, default=True) + pars.add_argument("--margin", type=float, default=0.0100) pars.add_argument("--add_dimples", type=inkex.Boolean, default=False) pars.add_argument("--draw_dimple_centers", type=inkex.Boolean, default=False) pars.add_argument("--dimple_invert", type=inkex.Boolean, default=False) @@ -132,6 +133,7 @@ class JoinPaths(inkex.EffectExtension): pars.add_argument("--dimple_height_mode", default="by_height") pars.add_argument("--dimple_height", type=float, default=4) pars.add_argument("--dimple_angle", type=float, default=45) + pars.add_argument("--dimple_tab_angle", type=float, default=45) pars.add_argument("--dimple_height_units", default="mm") pars.add_argument("--tab", default="sampling", help="Tab") @@ -163,7 +165,7 @@ class JoinPaths(inkex.EffectExtension): newParts += parts[:] firstElem = elem else: - if(vectCmpWithMargin(start, newParts[-1][-1][-1], margin = .01)): + if(vectCmpWithMargin(start, newParts[-1][-1][-1], margin = self.options.margin)) and self.options.add_dimples is False: newParts[-1] += parts[0] else: if self.options.add_dimples is True: @@ -179,20 +181,7 @@ class JoinPaths(inkex.EffectExtension): newParts[-1].append([newParts[-1][-1][-1], newParts[-1][-1][-1], p2, p2]) newParts[-1] += parts[0] - #angle=self.options.dimple_angle - #p3 = rotate(midPoint, p2, math.radians(angle)) - #p4 = rotate(midPoint, p2, math.radians(360-angle)) - - #add a new dimple - #line = self.svg.get_current_layer().add(inkex.PathElement(id=self.svg.get_unique_id('dimple'))) - #line.set('d', "m{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], p3[0], p3[1])) - #line.style = {'stroke': '#000000', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px'))} - - #add a new dimple - #line = self.svg.get_current_layer().add(inkex.PathElement(id=self.svg.get_unique_id('dimple'))) - #line.set('d', "m{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], p4[0], p4[1])) - #line.style = {'stroke': '#000000', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px'))} - + #get slope, distance and norm slope dx = midPoint[0]-p1[0] dy = midPoint[1]-p1[1] dist = math.sqrt(dx*dx + dy*dy) @@ -217,7 +206,7 @@ class JoinPaths(inkex.EffectExtension): x3 = midPoint[0] + (dimple_height)*dy y3 = midPoint[1] - (dimple_height)*dx x4 = midPoint[0] - (dimple_height)*dy - y4 = midPoint[1] + (dimple_height)*dx + y4 = midPoint[1] + (dimple_height)*dx dimple_style = {'stroke': '#0000FF', 'fill': 'none', 'stroke-width': str(self.svg.unittouu('1px'))} @@ -236,7 +225,7 @@ class JoinPaths(inkex.EffectExtension): line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(midPoint[0], midPoint[1], p2[0], p2[1])) line.style = dimple_style - if self.options.dimple_type == "lines": + if self.options.dimple_type == "peaks": if self.options.dimple_invert is True: x5 = x3 y5 = y3 @@ -245,17 +234,17 @@ class JoinPaths(inkex.EffectExtension): x4 = x5 y4 = y5 #add a new dimple center - line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple'))) + line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_peak'))) line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], x3, y3, p2[0], p2[1])) line.style = dimple_style if self.options.draw_both_sides is True: #add a new opposite dimple center - line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple'))) + line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_peak'))) line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format(p1[0], p1[1], x4, y4, p2[0], p2[1])) line.style = dimple_style - else: - ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple'))) + elif self.options.dimple_type == "arcs": + ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple_arc'))) ellipse.set('transform', "rotate({:0.6f} {:0.6f} {:0.6f})".format(slope_angle, midPoint[0], midPoint[1])) ellipse.set('sodipodi:arc-type', "arc") ellipse.set('sodipodi:type', "arc") @@ -272,7 +261,7 @@ class JoinPaths(inkex.EffectExtension): ellipse.style = dimple_style if self.options.draw_both_sides is True: - ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple'))) + ellipse = dimpleGroup.add(inkex.Ellipse(id=self.svg.get_unique_id('dimple_arc'))) ellipse.set('transform', "rotate({:0.6f} {:0.6f} {:0.6f})".format(slope_angle, midPoint[0], midPoint[1])) ellipse.set('sodipodi:arc-type', "arc") ellipse.set('sodipodi:type', "arc") @@ -287,7 +276,39 @@ class JoinPaths(inkex.EffectExtension): ellipse.set('sodipodi:start', "{:0.6f}".format(math.radians(90.0))) ellipse.set('sodipodi:end', "{:0.6f}".format(math.radians(270.0))) ellipse.style = dimple_style + + elif self.options.dimple_type == "tabs": + pbottom1 = [p1[0] + (dimple_height)*dy, p1[1] - (dimple_height)*dx] + pbottom2 = [p2[0] + (dimple_height)*dy, p2[1] - (dimple_height)*dx] + ptop1 = [p1[0] - (dimple_height)*dy, p1[1] + (dimple_height)*dx] + ptop2 = [p2[0] - (dimple_height)*dy, p2[1] + (dimple_height)*dx] + l_hypo = dimple_height / (math.cos(math.radians(90.0 - self.options.dimple_tab_angle))) + pbottom1 = rotate(p1, [p1[0] + l_hypo * dx, p1[1] + l_hypo * dy], math.radians(-self.options.dimple_tab_angle)) + pbottom2 = rotate(p2, [p2[0] - l_hypo * dx, p2[1] - l_hypo * dy], math.radians(-360.0 + self.options.dimple_tab_angle)) + ptop1 = rotate(p1, [p1[0] + l_hypo * dx, p1[1] + l_hypo * dy], math.radians(self.options.dimple_tab_angle)) + ptop2 = rotate(p2, [p2[0] - l_hypo * dx, p2[1] - l_hypo * dy], math.radians(360.0 - self.options.dimple_tab_angle)) + + + if self.options.dimple_invert is True: + ptemp1 = pbottom1 + ptemp2 = pbottom2 + pbottom1 = ptop1 + pbottom2 = ptop2 + ptop1 = ptemp1 + ptop2 = ptemp2 + + #add a new tab + line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_tab'))) + line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format( + p1[0], p1[1], pbottom1[0], pbottom1[1], pbottom2[0], pbottom2[1], p2[0], p2[1])) + line.style = dimple_style + if self.options.draw_both_sides is True: + line = dimpleGroup.add(inkex.PathElement(id=self.svg.get_unique_id('dimple_tab'))) + line.set('d', "M{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f} L{:0.6f},{:0.6f}".format( + p1[0], p1[1], ptop1[0], ptop1[1], ptop2[0], ptop2[1], p2[0], p2[1])) + line.style = dimple_style + #cleanup groups if len(dimpleGroup) == 1: ##move up child if group has only one child for child in dimpleGroup: diff --git a/extensions/fablabchemnitz/join_paths/meta.json b/extensions/fablabchemnitz/join_paths/meta.json index cf2e3771..8e0e02f0 100644 --- a/extensions/fablabchemnitz/join_paths/meta.json +++ b/extensions/fablabchemnitz/join_paths/meta.json @@ -1,6 +1,6 @@ [ { - "name": "Join Paths / Create Dimples", + "name": "Join Paths / Create Tabs And Dimples", "id": "fablabchemnitz.de.join_paths", "path": "join_paths", "original_name": "Join Paths Optimized", From f388ca774fea6ac9aaf2a80a20537469a73bb48a Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sun, 17 Oct 2021 19:31:44 +0200 Subject: [PATCH 02/11] fix glitchy group cleaning --- .../styles_to_layers/styles_to_layers.inx | 1 + .../styles_to_layers/styles_to_layers.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.inx b/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.inx index c480fe8b..168e516c 100644 --- a/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.inx +++ b/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.inx @@ -5,6 +5,7 @@ + diff --git a/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.py b/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.py index cc055605..ac63536c 100644 --- a/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.py +++ b/extensions/fablabchemnitz/styles_to_layers/styles_to_layers.py @@ -8,7 +8,7 @@ Features Author: Mario Voigt / FabLab Chemnitz Mail: mario.voigt@stadtfabrikanten.org Date: 19.08.2020 -Last patch: 11.04.2021 +Last patch: 17.10.2021 License: GNU GPL v3 """ import inkex @@ -115,7 +115,11 @@ class StylesToLayers(inkex.EffectExtension): #the Styles to Layers extension still might brick the gradients (some tests failed) if style and element.tag != inkex.addNS('stop','svg') and element.tag != inkex.addNS('tspan','svg'): - if self.options.separateby == "stroke": + if self.options.separateby == "element_tag": + neutral_value = 1 + layer_name = "element_tag-" + element.tag.replace("{http://www.w3.org/2000/svg}", "") + + elif self.options.separateby == "stroke": stroke = re.search('(;|^)stroke:(.*?)(;|$)', style) if stroke is not None: stroke = stroke[0] @@ -287,12 +291,18 @@ class StylesToLayers(inkex.EffectExtension): for newLayerNode in topLevelLayerNodeList: newLayerNode[0].append(newLayerNode[1]) #append newlayer to layer + #clean all empty layers from node list. Please note that the following remove_empty_groups + #call does not apply for this so we need to do it as PREVIOUS step before! + for i in range(0, len(layerNodeList)): + if len(layerNodeList[i][0]) == 0: + layerNodeList[i][0].getparent().remove(layerNodeList[i][0]) + if self.options.cleanup == True: try: import remove_empty_groups remove_empty_groups.RemoveEmptyGroups.effect(self) except: self.msg("Calling 'Remove Empty Groups' extension failed. Maybe the extension is not installed. You can download it from official InkScape Gallery. Skipping ...") - + if __name__ == '__main__': StylesToLayers().run() \ No newline at end of file From 319578b3b612a6eb612f4ded2338191a9ac6ca6a Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sun, 17 Oct 2021 21:04:57 +0200 Subject: [PATCH 03/11] Added Paths to lowlevel strokes extension --- .../braille_l18n.inx} | 4 +- .../braille_l18n.py} | 0 .../{braille-l18n => braille_l18n}/meta.json | 4 +- .../paths_to_lowlevel_strokes/meta.json | 19 +++ .../paths_to_lowlevel_strokes.inx | 19 +++ .../paths_to_lowlevel_strokes.py | 118 ++++++++++++++++++ 6 files changed, 160 insertions(+), 4 deletions(-) rename extensions/fablabchemnitz/{braille-l18n/braille-l18n.inx => braille_l18n/braille_l18n.inx} (86%) rename extensions/fablabchemnitz/{braille-l18n/braille-l18n.py => braille_l18n/braille_l18n.py} (100%) rename extensions/fablabchemnitz/{braille-l18n => braille_l18n}/meta.json (91%) create mode 100644 extensions/fablabchemnitz/paths_to_lowlevel_strokes/meta.json create mode 100644 extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx create mode 100644 extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py diff --git a/extensions/fablabchemnitz/braille-l18n/braille-l18n.inx b/extensions/fablabchemnitz/braille_l18n/braille_l18n.inx similarity index 86% rename from extensions/fablabchemnitz/braille-l18n/braille-l18n.inx rename to extensions/fablabchemnitz/braille_l18n/braille_l18n.inx index 92ad17c9..e36574e0 100644 --- a/extensions/fablabchemnitz/braille-l18n/braille-l18n.inx +++ b/extensions/fablabchemnitz/braille_l18n/braille_l18n.inx @@ -1,7 +1,7 @@ Convert To Localized Braille - fablabchemnitz.de.braille-l18n + fablabchemnitz.de.braille_l18n @@ -20,6 +20,6 @@ \ No newline at end of file diff --git a/extensions/fablabchemnitz/braille-l18n/braille-l18n.py b/extensions/fablabchemnitz/braille_l18n/braille_l18n.py similarity index 100% rename from extensions/fablabchemnitz/braille-l18n/braille-l18n.py rename to extensions/fablabchemnitz/braille_l18n/braille_l18n.py diff --git a/extensions/fablabchemnitz/braille-l18n/meta.json b/extensions/fablabchemnitz/braille_l18n/meta.json similarity index 91% rename from extensions/fablabchemnitz/braille-l18n/meta.json rename to extensions/fablabchemnitz/braille_l18n/meta.json index 5a66fb74..57eb291d 100644 --- a/extensions/fablabchemnitz/braille-l18n/meta.json +++ b/extensions/fablabchemnitz/braille_l18n/meta.json @@ -1,8 +1,8 @@ [ { "name": "Convert To Localized Braille", - "id": "fablabchemnitz.de.braille-l18n", - "path": "braille-l18n", + "id": "fablabchemnitz.de.braille_l18n", + "path": "braille_l18n", "original_name": "Convert to localized Braille", "original_id": "org.inkscape.text.braille-l18n", "license": "BSD-3-Clause License", diff --git a/extensions/fablabchemnitz/paths_to_lowlevel_strokes/meta.json b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/meta.json new file mode 100644 index 00000000..28ca7913 --- /dev/null +++ b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/meta.json @@ -0,0 +1,19 @@ +[ + { + "name": "Paths To Lowlevel Strokes", + "id": "fablabchemnitz.de.paths_to_lowlevel_strokes", + "path": "paths_to_lowlevel_strokes", + "original_name": "Paths To Lowlevel Strokes", + "original_id": "fablabchemnitz.de.paths_to_lowlevel_strokes", + "license": "GNU GPL v3", + "license_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/LICENSE", + "comment": "Created by Mario Voigt", + "source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/paths_to_strokes", + "fork_url": null, + "documentation_url": "https://stadtfabrikanten.org/display/IFM/Paths+To+Lowlevel+Strokes", + "inkscape_gallery_url": null, + "main_authors": [ + "github.com/vmario89" + ] + } +] \ No newline at end of file diff --git a/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx new file mode 100644 index 00000000..23f63431 --- /dev/null +++ b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx @@ -0,0 +1,19 @@ + + + Paths To Lowlevel Strokes + fablabchemnitz.de.paths_to_lowlevel_strokes + true + 0.100 + 3 + + path + + + + + + + + \ No newline at end of file diff --git a/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py new file mode 100644 index 00000000..395e794a --- /dev/null +++ b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python3 + + +from lxml import etree +import inkex +from inkex import bezier, PathElement +from inkex.paths import CubicSuperPath, Path +import copy + +class PathsToStrokes(inkex.EffectExtension): + + def add_arguments(self, pars): + pars.add_argument("--flattenbezier", type=inkex.Boolean, default=False, help="Flatten bezier curves to polylines") + pars.add_argument("--flatness", type=float, default=0.1, help="Minimum flatness = 0.1. The smaller the value the more fine segments you will get (quantization).") + pars.add_argument("--decimals", type=int, default=3) + + def effect(self): + + def flatten(node): + path = node.path.transform(node.composed_transform()).to_superpath() + bezier.cspsubdiv(path, self.options.flatness) + newpath = [] + for subpath in path: + first = True + for csp in subpath: + cmd = 'L' + if first: + cmd = 'M' + first = False + newpath.append([cmd, [csp[1][0], csp[1][1]]]) + node.path = newpath + + def break_contours(element, breakelements = None): + if breakelements == None: + breakelements = [] + if element.tag == inkex.addNS('path','svg'): + if self.options.flattenbezier is True: + flatten(element) + parent = element.getparent() + idx = parent.index(element) + idSuffix = 0 + raw = element.path.to_arrays() + subPaths = [] + prev = 0 + for i in range(len(raw)): # Breaks compound paths into simple paths + if raw[i][0] == 'M' and i != 0: + subPath = raw[prev:i] + subPaths.append(Path(subPath)) + prev = i + subPaths.append(Path(raw[prev:])) #finally add the last path + for subPath in subPaths: + replacedelement = copy.copy(element) + oldId = replacedelement.get('id') + csp = CubicSuperPath(subPath) + if len(subPath) > 1 and csp[0][0] != csp[0][1]: #avoids pointy paths like M "31.4794 57.6024 Z" + replacedelement.path = subPath + if len(subPaths) == 1: + replacedelement.set('id', oldId) + else: + replacedelement.set('id', oldId + str(idSuffix)) + idSuffix += 1 + parent.insert(idx, replacedelement) + breakelements.append(replacedelement) + element.delete() + for child in element.getchildren(): + break_contours(child, breakelements) + return breakelements + + if len(self.svg.selected) == 0: + elementsToWork = break_contours(self.document.getroot()) + else: + elementsToWork = None + for element in self.svg.selected.values(): + elementsToWork = break_contours(element, elementsToWork) + + for element in elementsToWork: + oldId = element.get('id') + oldStyle = element.style + path = element.path.to_absolute().to_arrays() #to_arrays() is deprecated. How to make more modern? + pathIsClosed = False + if path[-1][0] == 'Z' or \ + (path[-1][0] == 'L' and path[0][1] == path[-1][1]) or \ + (path[-1][0] == 'C' and path[0][1] == [path[-1][1][-2], path[-1][1][-1]]) \ + : #if first is last point the path is also closed. The "Z" command is not required + pathIsClosed = True + parent = element.getparent() + idx = parent.index(element) + element.delete() + + if len(path) == 2 and pathIsClosed is False: + line = inkex.Line(id=oldId) + line.set('x1', '{:0.{dec}f}'.format(path[0][1][0], dec=self.options.decimals)) + line.set('y1', '{:0.{dec}f}'.format(path[0][1][1], dec=self.options.decimals)) + line.set('x2', '{:0.{dec}f}'.format(path[1][1][0], dec=self.options.decimals)) + line.set('y2', '{:0.{dec}f}'.format(path[1][1][1], dec=self.options.decimals)) + line.style = oldStyle + parent.insert(idx, line) + + if len(path) > 2 and pathIsClosed is False: + polyline = inkex.Polyline(id=oldId) + points = "" + for i in range(0, len(path)): + points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals) + polyline.set('points', points) + polyline.style = oldStyle + parent.insert(idx, polyline) + + if len(path) > 2 and pathIsClosed is True: + polygon = inkex.Polygon(id=oldId) + points = "" + for i in range(0, len(path) - 1): + points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals) + polygon.set('points', points) + polygon.style = oldStyle + parent.insert(idx, polygon) + +if __name__ == '__main__': + PathsToStrokes().run() \ No newline at end of file From 2b8e15b3d72e7226dae663822a2c68297f1890e3 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sun, 17 Oct 2021 21:38:46 +0200 Subject: [PATCH 04/11] some more options to low level stroke converter --- .../paths_to_lowlevel_strokes.inx | 1 + .../paths_to_lowlevel_strokes.py | 30 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx index 23f63431..1b7ce685 100644 --- a/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx +++ b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.inx @@ -5,6 +5,7 @@ true 0.100 3 + true path diff --git a/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py index 395e794a..9d9489ef 100644 --- a/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py +++ b/extensions/fablabchemnitz/paths_to_lowlevel_strokes/paths_to_lowlevel_strokes.py @@ -13,6 +13,7 @@ class PathsToStrokes(inkex.EffectExtension): pars.add_argument("--flattenbezier", type=inkex.Boolean, default=False, help="Flatten bezier curves to polylines") pars.add_argument("--flatness", type=float, default=0.1, help="Minimum flatness = 0.1. The smaller the value the more fine segments you will get (quantization).") pars.add_argument("--decimals", type=int, default=3) + pars.add_argument("--keep_style", type=inkex.Boolean, default=False) def effect(self): @@ -88,31 +89,30 @@ class PathsToStrokes(inkex.EffectExtension): element.delete() if len(path) == 2 and pathIsClosed is False: - line = inkex.Line(id=oldId) - line.set('x1', '{:0.{dec}f}'.format(path[0][1][0], dec=self.options.decimals)) - line.set('y1', '{:0.{dec}f}'.format(path[0][1][1], dec=self.options.decimals)) - line.set('x2', '{:0.{dec}f}'.format(path[1][1][0], dec=self.options.decimals)) - line.set('y2', '{:0.{dec}f}'.format(path[1][1][1], dec=self.options.decimals)) - line.style = oldStyle - parent.insert(idx, line) + ll = inkex.Line(id=oldId) + ll.set('x1', '{:0.{dec}f}'.format(path[0][1][0], dec=self.options.decimals)) + ll.set('y1', '{:0.{dec}f}'.format(path[0][1][1], dec=self.options.decimals)) + ll.set('x2', '{:0.{dec}f}'.format(path[1][1][0], dec=self.options.decimals)) + ll.set('y2', '{:0.{dec}f}'.format(path[1][1][1], dec=self.options.decimals)) if len(path) > 2 and pathIsClosed is False: - polyline = inkex.Polyline(id=oldId) + ll = inkex.Polyline(id=oldId) points = "" for i in range(0, len(path)): points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals) - polyline.set('points', points) - polyline.style = oldStyle - parent.insert(idx, polyline) + ll.set('points', points) if len(path) > 2 and pathIsClosed is True: - polygon = inkex.Polygon(id=oldId) + ll = inkex.Polygon(id=oldId) points = "" for i in range(0, len(path) - 1): points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals) - polygon.set('points', points) - polygon.style = oldStyle - parent.insert(idx, polygon) + ll.set('points', points) + if self.options.keep_style is True: + ll.style = oldStyle + else: + ll.style = "fill:none;stroke:#0000FF;stroke-width:" + str(self.svg.unittouu("1px")) + parent.insert(idx, ll) if __name__ == '__main__': PathsToStrokes().run() \ No newline at end of file From 0d911143051eb799e34a9ac74a7c45c1955b0657 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sun, 17 Oct 2021 23:24:32 +0200 Subject: [PATCH 05/11] fixes --- .../create_links/create_links.inx | 2 - .../fablabchemnitz/join_paths/join_paths.inx | 16 +- .../fablabchemnitz/join_paths/join_paths.py | 222 +++++++++--------- 3 files changed, 130 insertions(+), 110 deletions(-) diff --git a/extensions/fablabchemnitz/create_links/create_links.inx b/extensions/fablabchemnitz/create_links/create_links.inx index c17a30f3..f560adb1 100644 --- a/extensions/fablabchemnitz/create_links/create_links.inx +++ b/extensions/fablabchemnitz/create_links/create_links.inx @@ -20,7 +20,6 @@ - @@ -44,7 +43,6 @@ - diff --git a/extensions/fablabchemnitz/join_paths/join_paths.inx b/extensions/fablabchemnitz/join_paths/join_paths.inx index 5a744881..dc2d21bd 100644 --- a/extensions/fablabchemnitz/join_paths/join_paths.inx +++ b/extensions/fablabchemnitz/join_paths/join_paths.inx @@ -4,18 +4,20 @@ fablabchemnitz.de.join_paths + true 0.0100 false + false false - false + false false @@ -31,7 +33,17 @@ - false + + false + 1 + 40 + + + + + + +