no message

This commit is contained in:
leyghisbb 2020-08-30 11:23:15 +02:00
parent 519a8db48f
commit 82fa7efd18

View File

@ -1,47 +1,41 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# We will use the inkex module with the predefined Effect base class.
import inkex import inkex
import measure import measure
import re
from inkex.paths import Path from inkex.paths import Path
from inkex import paths from inkex import paths
# The simplestyle module provides functions for style parsing.
from simplestyle import *
def getArea(path): def getArea(path):
return abs(measure.csparea(paths.CubicSuperPath(path + "z"))) return abs(measure.csparea(paths.CubicSuperPath(path + "z")))
class LaserSort(inkex.Effect): class LaserSort(inkex.Effect):
def __init__(self): def __init__(self):
inkex.Effect.__init__(self) inkex.Effect.__init__(self)
def effect(self): def effect(self):
elements = self.document.xpath('//svg:path',namespaces=inkex.NSS) elements = self.document.xpath('//svg:path',namespaces=inkex.NSS)
for el in elements: for el in elements:
oldpathstring = el.attrib['d'] oldpathstring = el.attrib['d']
nodes = Path(oldpathstring).to_arrays() nodes = Path(oldpathstring).to_arrays()
currentSection = [] currentSection = []
sections = [currentSection] sections = [currentSection]
for node in nodes: for node in nodes:
command = node.pop(0) command = node.pop(0)
currentSection.append(command + ' ' + ' '.join(list(map(lambda c: ','.join(map(str, c)), node)))) currentSection.append(command + ' ' + ' '.join(list(map(lambda c: ','.join(map(str, c)), node))))
if command.lower() == 'z': if command.lower() == 'z':
currentSection = [] currentSection = []
sections.append(currentSection) sections.append(currentSection)
sections = list(map(lambda n: ' '.join(n), filter(lambda n: len(n) > 0, sections))) sections = list(map(lambda n: ' '.join(n), filter(lambda n: len(n) > 0, sections)))
if (sections[-1][-2].lower() != 'z'): if (sections[-1][-2].lower() != 'z'):
nonClosedSection = ' ' + sections.pop() nonClosedSection = ' ' + sections.pop()
else: else:
nonClosedSection = '' nonClosedSection = ''
sections = filter(lambda s: s[0].lower() != 'z', sections) sections = filter(lambda s: s[0].lower() != 'z', sections)
sections = sorted(sections, key=getArea) sections = sorted(sections, key=getArea)
newpathstring = "z ".join(sections) + nonClosedSection newpathstring = "z ".join(sections) + nonClosedSection
el.set('d', newpathstring) el.set('d', newpathstring)
# Create effect instance and apply it. LaserSort().run()
LaserSort().run()