diff options
| author | Alvin Penner <penner@vaxxine.com> | 2009-07-01 23:35:57 +0000 |
|---|---|---|
| committer | alvinpenner <alvinpenner@users.sourceforge.net> | 2009-07-01 23:35:57 +0000 |
| commit | d3b235cf6b224c7880145d9c8a572bf3d3e8491b (patch) | |
| tree | 1357bc2a487c4318ec2584c040ec4ac4d62c9a22 | |
| parent | -Update Vi translation (diff) | |
| download | inkscape-d3b235cf6b224c7880145d9c8a572bf3d3e8491b.tar.gz inkscape-d3b235cf6b224c7880145d9c8a572bf3d3e8491b.zip | |
modified version of fix by Preben S for LP bug 391923
(bzr r8197)
| -rw-r--r-- | share/extensions/hpgl_output.inx | 38 | ||||
| -rw-r--r-- | share/extensions/hpgl_output.py | 67 |
2 files changed, 72 insertions, 33 deletions
diff --git a/share/extensions/hpgl_output.inx b/share/extensions/hpgl_output.inx index 8b06a11c2..f5cb9b7f8 100644 --- a/share/extensions/hpgl_output.inx +++ b/share/extensions/hpgl_output.inx @@ -1,20 +1,24 @@ <?xml version="1.0" encoding="UTF-8"?> <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> - <_name>HPGL Output</_name> - <id>org.ekips.output.hpgl</id> - <dependency type="extension">org.inkscape.output.svg.inkscape</dependency> - <dependency type="executable" location="extensions">hpgl_output.py</dependency> - <dependency type="executable" location="extensions">inkex.py</dependency> - <param name="flat" type="float" min="0.001" max="1000" _gui-text="hpgl output flatness">10</param> - <output> - <extension>.hpgl</extension> - <mimetype>image/hpgl</mimetype> - <_filetypename>HP Graphics Language file (*.hpgl)</_filetypename> - <_filetypetooltip>Export to an HP Graphics Language file</_filetypetooltip> - <dataloss>true</dataloss> - </output> - <script> - <command reldir="extensions" interpreter="python">hpgl_output.py</command> - <helper_extension>org.inkscape.output.svg.inkscape</helper_extension> - </script> + <_name>HPGL Output</_name> + <id>org.ekips.output.hpgl</id> + <dependency type="extension">org.inkscape.output.svg.inkscape</dependency> + <dependency type="executable" location="extensions">hpgl_output.py</dependency> + <dependency type="executable" location="extensions">inkex.py</dependency> + <param name="flat" type="float" min="0.001" max="1000" _gui-text="hpgl output flatness">0.2</param> + <param name="mirror" type="boolean" _gui-text="Mirror Y-axis">FALSE</param> + <param name="xOrigin" type="float" min="-100000" max="100000" _gui-text="X-origin (px)">0.0</param> + <param name="yOrigin" type="float" min="-100000" max="100000" _gui-text="Y-origin (px)">0.0</param> + <param name="plotInvisibleLayers" type="boolean" _gui-text="Plot invisible layers">FALSE</param> + <output> + <extension>.hpgl</extension> + <mimetype>image/hpgl</mimetype> + <_filetypename>HP Graphics Language file (*.hpgl)</_filetypename> + <_filetypetooltip>Export to an HP Graphics Language file</_filetypetooltip> + <dataloss>true</dataloss> + </output> + <script> + <command reldir="extensions" interpreter="python">hpgl_output.py</command> + <helper_extension>org.inkscape.output.svg.inkscape</helper_extension> + </script> </inkscape-extension> diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py index 606718995..7e2dbc8ac 100644 --- a/share/extensions/hpgl_output.py +++ b/share/extensions/hpgl_output.py @@ -16,34 +16,69 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ''' -import inkex, cubicsuperpath, simplepath, cspsubdiv +import inkex, cubicsuperpath, simplepath, simplestyle, cspsubdiv class MyEffect(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) self.OptionParser.add_option("-f", "--flatness", action="store", type="float", - dest="flat", default=10.0, + dest="flat", default=0.2, help="Minimum flatness of the subdivided curves") + self.OptionParser.add_option("-m", "--mirror", + action="store", type="inkbool", + dest="mirror", default="FALSE", + help="Mirror Y-Axis") + self.OptionParser.add_option("-x", "--xOrigin", + action="store", type="float", + dest="xOrigin", default=0.0, + help="X Origin (pixels)") + self.OptionParser.add_option("-y", "--yOrigin", + action="store", type="float", + dest="yOrigin", default=0.0, + help="Y Origin (pixels)") + self.OptionParser.add_option("-p", "--plotInvisibleLayers", + action="store", type="inkbool", + dest="plotInvisibleLayers", default="FALSE", + help="Plot invisible layers") + self.hpgl = ['IN;SP1;'] def output(self): print ''.join(self.hpgl) def effect(self): - path = '//svg:path' - for node in self.document.getroot().xpath(path, namespaces=inkex.NSS): - d = node.get('d') - if len(simplepath.parsePath(d)): - p = cubicsuperpath.parsePath(d) - cspsubdiv.cspsubdiv(p, self.options.flat) - for sp in p: - first = True - for csp in sp: - cmd = 'PD' - if first: - cmd = 'PU' - first = False - self.hpgl.append('%s%s,%s;' % (cmd,csp[1][0],csp[1][1])) + mirror = 1.0 + if self.options.mirror: + mirror = -1.0 + x0 = self.options.xOrigin + y0 = self.options.yOrigin + scale = 1016.0/90 + i = 0 + layerPath = '//svg:g[@inkscape:groupmode="layer"]' + for layer in self.document.getroot().xpath(layerPath, namespaces=inkex.NSS): + i += 1 + style = layer.get('style') + if style: + style = simplestyle.parseStyle(style) + if style['display']=='none': + if not self.options.plotInvisibleLayers: + continue + nodePath = ('//svg:g[@inkscape:groupmode="layer"][%d]/descendant::svg:path') % i + for node in self.document.getroot().xpath(nodePath, namespaces=inkex.NSS): + d = node.get('d') + if len(simplepath.parsePath(d)): + p = cubicsuperpath.parsePath(d) + cspsubdiv.cspsubdiv(p, self.options.flat) + for sp in p: + first = True + for csp in sp: + cmd = 'PD' + if first: + cmd = 'PU' + first = False + self.hpgl.append('%s%d,%d;' % (cmd,(csp[1][0] - x0)*scale,(csp[1][1] - y0)*scale*mirror)) if __name__ == '__main__': #pragma: no cover e = MyEffect() e.affect() + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 |
