added support for group/child handling for reverse order of subpaths

This commit is contained in:
leyghisbb 2021-05-07 16:54:21 +02:00
parent c7879f3daa
commit 782afcf3f6

View File

@ -21,22 +21,25 @@ from inkex import PathElement, CubicSuperPath
class ReverseOrderSubpaths(inkex.EffectExtension): class ReverseOrderSubpaths(inkex.EffectExtension):
def reverse(self, element):
if element.tag == inkex.addNS('path','svg'):
new = []
sub = element.path.to_superpath()
i = 0
while i < len(sub):
new.append(sub[-1-i])
i += 1
element.path = CubicSuperPath(new).to_path(curves_only=True)
elif element.tag == inkex.addNS('g','svg'):
for child in element.getchildren():
self.reverse(child)
def effect(self): def effect(self):
"""Reverse order of subpaths (combined paths) without reversing node-order or order of paths""" """Reverse order of subpaths (combined paths) without reversing node-order or order of paths"""
if not self.svg.selected: if not self.svg.selected:
raise inkex.AbortExtension("Please select an object.") raise inkex.AbortExtension("Please select an object.")
for id, elem in self.svg.selection.id_dict().items(): for element in self.svg.selection.values():
self.reverse(element)
new=[]
sub=elem.path.to_superpath()
i=0
while i<len(sub):
new.append(sub[-1-i])
i+=1
elem.path = CubicSuperPath(new).to_path(curves_only=True)
if __name__ == '__main__': if __name__ == '__main__':
ReverseOrderSubpaths().run() ReverseOrderSubpaths().run()