Fix issue with breaking apart paths in vpypetools

This commit is contained in:
Mario Voigt 2021-04-13 15:12:18 +02:00
parent 5fc0054a77
commit 0a586ad157

View File

@ -158,22 +158,33 @@ class vpypetools (inkex.EffectExtension):
newpath.append([cmd, [csp[1][0], csp[1][1]]]) newpath.append([cmd, [csp[1][0], csp[1][1]]])
node.path = newpath node.path = newpath
def convertPath(node): # flatten the node's path to linearize, split up the path to it's subpaths (break apart) and add all points to the vpype lines collection
def convertPath(node, nodes = None):
if nodes is None:
nodes = []
if node.tag == inkex.addNS('path','svg'): if node.tag == inkex.addNS('path','svg'):
nodesToWork.append(node) nodes.append(node)
if self.options.flattenbezier is True: if self.options.flattenbezier is True:
flatten(node) flatten(node)
d = node.get('d')
p = CubicSuperPath(d) raw = node.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:
subPaths.append(raw[prev:i])
prev = i
subPaths.append(raw[prev:])
for subPath in subPaths:
points = [] points = []
for subpath in p: for csp in subPath:
for csp in subpath:
points.append(Point(round(csp[1][0], self.options.decimals), round(csp[1][1], self.options.decimals))) points.append(Point(round(csp[1][0], self.options.decimals), round(csp[1][1], self.options.decimals)))
lc.append(LineString(points)) lc.append(LineString(points))
children = node.getchildren() children = node.getchildren()
if children is not None: if children is not None:
for child in children: for child in children:
convertPath(child) convertPath(child, nodes)
return nodes
doc = None #create a vpype document doc = None #create a vpype document
@ -192,12 +203,12 @@ class vpypetools (inkex.EffectExtension):
''' '''
applytransform.ApplyTransform().recursiveFuseTransform(self.document.getroot()) applytransform.ApplyTransform().recursiveFuseTransform(self.document.getroot())
if len(self.svg.selected) == 0: if len(self.svg.selected) == 0:
convertPath(self.document.getroot()) nodesToWork = convertPath(self.document.getroot())
for element in nodesToWork: for element in nodesToWork:
input_bbox += element.bounding_box() input_bbox += element.bounding_box()
else: else:
for id, item in self.svg.selected.items(): for id, item in self.svg.selected.items():
convertPath(item) nodesToWork = convertPath(item)
#input_bbox = inkex.elements._selected.ElementList.bounding_box(self.svg.selected) # get BoundingBox for selection #input_bbox = inkex.elements._selected.ElementList.bounding_box(self.svg.selected) # get BoundingBox for selection
input_bbox = self.svg.selection.bounding_box() # get BoundingBox for selection input_bbox = self.svg.selection.bounding_box() # get BoundingBox for selection
if len(lc) == 0: if len(lc) == 0: