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): if self.options.measure == "area":
# continue area = -csparea(csp) #is returned as negative value. we need to invert with -
if area < (self.options.threshold * (unit_factor * unit_factor)):
if self.options.measure == "area": element.delete()
calc = parsed_path.area()
#inkex.utils.debug(calc) #print calculated area with document units elif self.options.measure == "length":
#inkex.utils.debug(str(self.options.threshold * (unit_factor * unit_factor))) #print threshold area with selected units slengths, stotal = csplength(csp) #get segment lengths and total length of path in document's internal unit
if calc < (self.options.threshold * (unit_factor * unit_factor)): if stotal < (self.options.threshold * unit_factor):
path.getparent().remove(path) element.delete()
else: #length except Exception as e:
calc = parsed_path.length() #self.msg(e)
#inkex.utils.debug(calc) #print calculated area with document units
#inkex.utils.debug(str(self.options.threshold * (unit_factor * unit_factor))) #print threshold area with selected units
if calc < (self.options.threshold * unit_factor):
path.getparent().remove(path)
except:
pass pass
if __name__ == '__main__': if __name__ == '__main__':