changed filter small things to use native bezier functions instead svgpathtools library

This commit is contained in:
Mario Voigt 2021-04-19 22:23:44 +02:00
parent 70ffb2b72f
commit a9e6b26811

View File

@ -1,12 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import inkex import inkex
import svgpathtools from inkex.bezier import csplength, csparea
def isclosedac(p): def isclosedac(p):
return abs(p.start-p.end) < 1e-6 return abs(p.start-p.end) < 1e-6
class SmallThingsFilter(inkex.EffectExtension): class SmallThingsFilter(inkex.EffectExtension):
def add_arguments(self, pars): def add_arguments(self, pars):
@ -20,26 +19,21 @@ class SmallThingsFilter(inkex.EffectExtension):
if self.options.threshold == 0: if self.options.threshold == 0:
return return
for path in self.document.xpath("//svg:path", namespaces=inkex.NSS): for element in self.document.xpath("//svg:path", namespaces=inkex.NSS):
try: try:
parsed_path = svgpathtools.parse_path(path.attrib["d"]) csp = element.path.transform(element.composed_transform()).to_superpath()
#if not isclosedac(parsed_path):
# continue
if self.options.measure == "area": if self.options.measure == "area":
calc = parsed_path.area() area = -csparea(csp) #is returned as negative value. we need to invert with -
#inkex.utils.debug(calc) #print calculated area with document units if area < (self.options.threshold * (unit_factor * unit_factor)):
#inkex.utils.debug(str(self.options.threshold * (unit_factor * unit_factor))) #print threshold area with selected units element.delete()
if calc < (self.options.threshold * (unit_factor * unit_factor)):
path.getparent().remove(path) elif self.options.measure == "length":
else: #length slengths, stotal = csplength(csp) #get segment lengths and total length of path in document's internal unit
calc = parsed_path.length() if stotal < (self.options.threshold * unit_factor):
#inkex.utils.debug(calc) #print calculated area with document units element.delete()
#inkex.utils.debug(str(self.options.threshold * (unit_factor * unit_factor))) #print threshold area with selected units except Exception as e:
if calc < (self.options.threshold * unit_factor): #self.msg(e)
path.getparent().remove(path)
except:
pass pass
if __name__ == '__main__': if __name__ == '__main__':