some more options to low level stroke converter

This commit is contained in:
Mario Voigt 2021-10-17 21:38:46 +02:00
parent 319578b3b6
commit 2b8e15b3d7
2 changed files with 16 additions and 15 deletions

View File

@ -5,6 +5,7 @@
<param name="flattenbezier" type="bool" gui-text="Quantization (flatten bezier curves to polylines)">true</param> <param name="flattenbezier" type="bool" gui-text="Quantization (flatten bezier curves to polylines)">true</param>
<param name="flatness" type="float" min="0.001" max="99999.000" precision="3" gui-text="Flatness (tolerance)" gui-description="Minimum flatness = 0.001. The smaller the value the more fine segments you will get.">0.100</param> <param name="flatness" type="float" min="0.001" max="99999.000" precision="3" gui-text="Flatness (tolerance)" gui-description="Minimum flatness = 0.001. The smaller the value the more fine segments you will get.">0.100</param>
<param name="decimals" type="int" min="0" max="16" gui-text="Decimals" gui-description="Accuracy">3</param> <param name="decimals" type="int" min="0" max="16" gui-text="Decimals" gui-description="Accuracy">3</param>
<param name="keep_style" type="bool" gui-text="Keep style">true</param>
<effect needs-live-preview="true"> <effect needs-live-preview="true">
<object-type>path</object-type> <object-type>path</object-type>
<effects-menu> <effects-menu>

View File

@ -13,6 +13,7 @@ class PathsToStrokes(inkex.EffectExtension):
pars.add_argument("--flattenbezier", type=inkex.Boolean, default=False, help="Flatten bezier curves to polylines") pars.add_argument("--flattenbezier", type=inkex.Boolean, default=False, help="Flatten bezier curves to polylines")
pars.add_argument("--flatness", type=float, default=0.1, help="Minimum flatness = 0.1. The smaller the value the more fine segments you will get (quantization).") pars.add_argument("--flatness", type=float, default=0.1, help="Minimum flatness = 0.1. The smaller the value the more fine segments you will get (quantization).")
pars.add_argument("--decimals", type=int, default=3) pars.add_argument("--decimals", type=int, default=3)
pars.add_argument("--keep_style", type=inkex.Boolean, default=False)
def effect(self): def effect(self):
@ -88,31 +89,30 @@ class PathsToStrokes(inkex.EffectExtension):
element.delete() element.delete()
if len(path) == 2 and pathIsClosed is False: if len(path) == 2 and pathIsClosed is False:
line = inkex.Line(id=oldId) ll = inkex.Line(id=oldId)
line.set('x1', '{:0.{dec}f}'.format(path[0][1][0], dec=self.options.decimals)) ll.set('x1', '{:0.{dec}f}'.format(path[0][1][0], dec=self.options.decimals))
line.set('y1', '{:0.{dec}f}'.format(path[0][1][1], dec=self.options.decimals)) ll.set('y1', '{:0.{dec}f}'.format(path[0][1][1], dec=self.options.decimals))
line.set('x2', '{:0.{dec}f}'.format(path[1][1][0], dec=self.options.decimals)) ll.set('x2', '{:0.{dec}f}'.format(path[1][1][0], dec=self.options.decimals))
line.set('y2', '{:0.{dec}f}'.format(path[1][1][1], dec=self.options.decimals)) ll.set('y2', '{:0.{dec}f}'.format(path[1][1][1], dec=self.options.decimals))
line.style = oldStyle
parent.insert(idx, line)
if len(path) > 2 and pathIsClosed is False: if len(path) > 2 and pathIsClosed is False:
polyline = inkex.Polyline(id=oldId) ll = inkex.Polyline(id=oldId)
points = "" points = ""
for i in range(0, len(path)): for i in range(0, len(path)):
points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals) points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals)
polyline.set('points', points) ll.set('points', points)
polyline.style = oldStyle
parent.insert(idx, polyline)
if len(path) > 2 and pathIsClosed is True: if len(path) > 2 and pathIsClosed is True:
polygon = inkex.Polygon(id=oldId) ll = inkex.Polygon(id=oldId)
points = "" points = ""
for i in range(0, len(path) - 1): for i in range(0, len(path) - 1):
points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals) points += '{:0.{dec}f},{:0.{dec}f} '.format(path[i][1][0], path[i][1][1], dec=self.options.decimals)
polygon.set('points', points) ll.set('points', points)
polygon.style = oldStyle if self.options.keep_style is True:
parent.insert(idx, polygon) ll.style = oldStyle
else:
ll.style = "fill:none;stroke:#0000FF;stroke-width:" + str(self.svg.unittouu("1px"))
parent.insert(idx, ll)
if __name__ == '__main__': if __name__ == '__main__':
PathsToStrokes().run() PathsToStrokes().run()