Code

added HPGL export extension, courtesy of Aaron Spike
authorprokoudine <prokoudine@users.sourceforge.net>
Thu, 5 Jun 2008 15:56:03 +0000 (15:56 +0000)
committerprokoudine <prokoudine@users.sourceforge.net>
Thu, 5 Jun 2008 15:56:03 +0000 (15:56 +0000)
po/POTFILES.in
share/extensions/Makefile.am
share/extensions/hpgl_output.inx [new file with mode: 0644]
share/extensions/hpgl_output.py [new file with mode: 0644]

index 3c20358b315ea717319be9aa8a97af523fac8084..a520095b74eb44131d2b9d4ddff898fe27cf471e 100644 (file)
@@ -373,6 +373,7 @@ share/extensions/svg_and_media_zip_output.py
 [type: gettext/xml] share/extensions/grid_cartesian.inx
 [type: gettext/xml] share/extensions/grid_polar.inx
 [type: gettext/xml] share/extensions/handles.inx
+[type: gettext/xml] share/extensions/hpgl_output.inx
 [type: gettext/xml] share/extensions/inkscape_help_askaquestion.inx
 [type: gettext/xml] share/extensions/inkscape_help_commandline.inx
 [type: gettext/xml] share/extensions/inkscape_help_faq.inx
index 62fa9eeda8fe45c93a01b592083349f7cec175d4..73b5ad78a796604fd60b689bccd72069b5ac1782 100644 (file)
@@ -59,6 +59,7 @@ extensions = \
        grid_cartesian.py \
        grid_polar.py \
        handles.py \
+       hpgl_output.py \
        ill2svg.pl \
        inkex.py \
        interp.py \
@@ -167,6 +168,7 @@ modules = \
        grid_cartesian.inx \
        grid_polar.inx \
        handles.inx \
+       hpgl_output.inx \
        inkscape_help_askaquestion.inx \
        inkscape_help_commandline.inx \
        inkscape_help_faq.inx\
diff --git a/share/extensions/hpgl_output.inx b/share/extensions/hpgl_output.inx
new file mode 100644 (file)
index 0000000..f351a79
--- /dev/null
@@ -0,0 +1,19 @@
+<?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>
+  <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>\r
+  </output>
+  <script>
+    <command reldir="extensions" interpreter="python">hpgl_output.py</command>
+    <helper_extension>org.inkscape.output.svg.inkscape</helper_extension>\r
+  </script>\r
+</inkscape-extension>\r
diff --git a/share/extensions/hpgl_output.py b/share/extensions/hpgl_output.py
new file mode 100644 (file)
index 0000000..f94456a
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/env python \r
+'''\r
+Copyright (C) 2008 Aaron Spike, aaron@ekips.org\r
+\r
+This program is free software; you can redistribute it and/or modify\r
+it under the terms of the GNU General Public License as published by\r
+the Free Software Foundation; either version 2 of the License, or\r
+(at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with this program; if not, write to the Free Software\r
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+'''\r
+import inkex, cubicsuperpath, simplepath, cspsubdiv\r
+\r
+class MyEffect(inkex.Effect):\r
+    def __init__(self):\r
+        inkex.Effect.__init__(self)\r
+        self.OptionParser.add_option("-f", "--flatness",\r
+                        action="store", type="float", \r
+                        dest="flat", default=10.0,\r
+                        help="Minimum flatness of the subdivided curves")\r
+        self.hpgl = ['IN;SP1;']\r
+    def output(self):\r
+        print ''.join(self.hpgl)\r
+    def effect(self):\r
+        path = '//svg:path'
+        for node in self.document.getroot().xpath(path, namespaces=inkex.NSS):\r
+            d = node.get('d')\r
+            p = cubicsuperpath.parsePath(d)\r
+            cspsubdiv.cspsubdiv(p, self.options.flat)\r
+            for sp in p:\r
+                first = True\r
+                for csp in sp:\r
+                    cmd = 'PD'\r
+                    if first:\r
+                        cmd = 'PU'\r
+                    first = False\r
+                    self.hpgl.append('%s%s,%s;' % (cmd,csp[1][0],csp[1][1]))\r
+\r
+e = MyEffect()\r
+e.affect()
\ No newline at end of file