diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2018-01-06 15:25:59 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2018-01-06 15:25:59 +0000 |
| commit | b92881dfa2e66b662effa267c57bfbc63fbeedd6 (patch) | |
| tree | 2a128665fc0b28c015495553efde6ee70dd2e9f6 | |
| parent | Add perimetral only lattice 2 optionaly and allow hide knots on point parameter (diff) | |
| parent | Add option to convert objects to paths before plotting (diff) | |
| download | inkscape-b92881dfa2e66b662effa267c57bfbc63fbeedd6.tar.gz inkscape-b92881dfa2e66b662effa267c57bfbc63fbeedd6.zip | |
Merge branch 'convertObjectsToPathsBeforePlotting' of https://gitlab.com/raboof/inkscape
| -rw-r--r-- | share/extensions/hpgl_encoder.py | 26 | ||||
| -rw-r--r-- | share/extensions/hpgl_output.inx | 1 | ||||
| -rwxr-xr-x | share/extensions/hpgl_output.py | 1 | ||||
| -rw-r--r-- | share/extensions/plotter.inx | 1 | ||||
| -rwxr-xr-x | share/extensions/plotter.py | 1 |
5 files changed, 29 insertions, 1 deletions
diff --git a/share/extensions/hpgl_encoder.py b/share/extensions/hpgl_encoder.py index 04387a91b..353b8aa0a 100644 --- a/share/extensions/hpgl_encoder.py +++ b/share/extensions/hpgl_encoder.py @@ -22,6 +22,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import math import re import string +from subprocess import Popen, PIPE +from shutil import copy2 # local libraries import bezmisc import cspsubdiv @@ -52,9 +54,13 @@ class hpglEncoder: "precut":bool "autoAlign":bool "debug":bool + "convertObjects":bool ''' self.options = effect.options - self.doc = effect.document.getroot() + if self.options.convertObjects: + self.doc = self.convertObjectsToPaths(effect.args[-1], effect.document) + else: + self.doc = effect.document.getroot() self.docWidth = effect.unittouu(self.doc.get('width')) self.docHeight = effect.unittouu(self.doc.get('height')) self.hpgl = '' @@ -104,6 +110,24 @@ class hpglEncoder: self.viewBoxTransformX = self.docWidth / effect.unittouu(effect.addDocumentUnit(viewBox2[2])) self.viewBoxTransformY = self.docHeight / effect.unittouu(effect.addDocumentUnit(viewBox2[3])) + def convertObjectsToPaths(self, file, document): + tempfile = inkex.os.path.splitext(file)[0] + "-prepare.svg" + # tempfile is needed here only because we want to force the extension to be .svg + # so that we can open and close it silently + copy2(file, tempfile) + + # Unfortunately this briefly pops up the GUI and cannot be done with -z, see https://bugs.launchpad.net/inkscape/+bug/843260 + p = Popen('inkscape --verb=EditSelectAllInAllLayers --verb=EditUnlinkClone --verb=ObjectToPath --verb=FileSave --verb=FileQuit ' + tempfile, shell=True, stdout=PIPE, stderr=PIPE) + (out, err) = p.communicate() + + if p.returncode != 0: + inkex.errormsg(_("Failed to convert objects to paths. Continued without converting.")) + inkex.errormsg(out) + inkex.errormsg(err) + return document.getroot() + else: + return inkex.etree.parse(tempfile).getroot() + def getHpgl(self): # dryRun to find edges groupmat = [[self.mirrorX * self.scaleX * self.viewBoxTransformX, 0.0, 0.0], [0.0, self.mirrorY * self.scaleY * self.viewBoxTransformY, 0.0]] diff --git a/share/extensions/hpgl_output.inx b/share/extensions/hpgl_output.inx index 673be29bb..609fc03d4 100644 --- a/share/extensions/hpgl_output.inx +++ b/share/extensions/hpgl_output.inx @@ -32,6 +32,7 @@ <param name="precut" type="boolean" _gui-text="Precut" _gui-description="Check this to cut a small line before the real drawing starts to correctly align the tool orientation. (Default: Checked)">true</param> <param name="flat" type="float" min="0.1" max="10.0" precision="1" _gui-text="Curve flatness:" _gui-description="Curves are divided into lines, this number controls how fine the curves will be reproduced, the smaller the finer (Default: '1.2')">1.2</param> <param name="autoAlign" type="boolean" _gui-text="Auto align" _gui-description="Check this to auto align the drawing to the zero point (Plus the tool offset if used). If unchecked you have to make sure that all parts of your drawing are within the document border! (Default: Checked)">true</param> + <param name="convertObjects" type="boolean" _gui-text="Convert objects to paths" _gui-description="Check this to automatically (nondestructively) convert all objects to paths before plotting (Default: Checked)">true</param> </page> </param> <_param name="settingsHelp" type="description">All these settings depend on the plotter you use, for more information please consult the manual or homepage for your plotter.</_param> diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py index d4a23743f..fc212b449 100755 --- a/share/extensions/hpgl_output.py +++ b/share/extensions/hpgl_output.py @@ -44,6 +44,7 @@ class HpglOutput(inkex.Effect): self.OptionParser.add_option('--precut', action='store', type='inkbool', dest='precut', default='TRUE', help='Use precut') self.OptionParser.add_option('--flat', action='store', type='float', dest='flat', default=1.2, help='Curve flatness') self.OptionParser.add_option('--autoAlign', action='store', type='inkbool', dest='autoAlign', default='TRUE', help='Auto align') + self.OptionParser.add_option('--convertObjects',action='store', type='inkbool', dest='convertObjects',default='TRUE', help='Convert objects to paths') def effect(self): self.options.debug = False diff --git a/share/extensions/plotter.inx b/share/extensions/plotter.inx index c91857b05..9b112938e 100644 --- a/share/extensions/plotter.inx +++ b/share/extensions/plotter.inx @@ -87,6 +87,7 @@ <param name="autoAlign" type="boolean" _gui-text="Auto align" _gui-description="Check this to auto align the drawing to the zero point (Plus the tool offset if used). If unchecked you have to make sure that all parts of your drawing are within the document border! (Default: Checked)">true</param> <param name="space" type="description"> </param> <param name="debug" type="boolean" _gui-text="Show debug information" _gui-description="Check this to get verbose information about the plot without actually sending something to the plotter (A.k.a. data dump) (Default: Unchecked)">false</param> + <param name="convertObjects" type="boolean" _gui-text="Convert objects to paths" _gui-description="Check this to automatically (nondestructively) convert all objects to paths before plotting (Default: Checked)">true</param> </page> </param> <_param name="settingsHelp" type="description">All these settings depend on the plotter you use, for more information please consult the manual or homepage for your plotter.</_param> diff --git a/share/extensions/plotter.py b/share/extensions/plotter.py index 1d8e8f79e..43d70eebc 100755 --- a/share/extensions/plotter.py +++ b/share/extensions/plotter.py @@ -56,6 +56,7 @@ class Plot(inkex.Effect): self.OptionParser.add_option('--flat', action='store', type='float', dest='flat', default=1.2, help='Curve flatness') self.OptionParser.add_option('--autoAlign', action='store', type='inkbool', dest='autoAlign', default='TRUE', help='Auto align') self.OptionParser.add_option('--debug', action='store', type='inkbool', dest='debug', default='FALSE', help='Show debug information') + self.OptionParser.add_option('--convertObjects', action='store', type='inkbool', dest='convertObjects', default='TRUE', help='Convert objects to paths') def effect(self): # get hpgl data |
