Code

patch by sas from 227449 with my changes for using ps2pdf instead of pstoedit
authorbuliabyak <buliabyak@users.sourceforge.net>
Sat, 14 Jun 2008 04:12:54 +0000 (04:12 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Sat, 14 Jun 2008 04:12:54 +0000 (04:12 +0000)
share/extensions/Makefile.am
share/extensions/eps_input.inx
share/extensions/ps2pdf-ext.py [new file with mode: 0644]
share/extensions/ps_input.inx
share/extensions/run_command.py [new file with mode: 0644]
share/extensions/uniconv-ext.py

index 73b5ad78a796604fd60b689bccd72069b5ac1782..909327cc9f4c6c7c0eedbcd49bbc337f27854332 100644 (file)
@@ -80,6 +80,7 @@ extensions = \
        ps2epsi.sh \
        ps2pdf.cmd \
        ps2pdf.sh \
+       ps2pdf-ext.py \
        pturtle.py \
        radiusrand.py \
        restack.py \
@@ -88,6 +89,7 @@ extensions = \
        render_alphabetsoup_config.py \
        rtree.py \
        rubberstretch.py\
+       run_command.py \
        simplepath.py \
        simplepath.rb \
        simplestyle.py \
index 5529f003b4d5026062a56ced917eed95e4020dbd..14f33764db3507100c5b842e8e9b2faeabf7a03d 100644 (file)
@@ -2,15 +2,18 @@
 <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
     <_name>EPS Input</_name>
     <id>org.inkscape.input.eps</id>
-    <dependency type="executable">pstoedit</dependency>
+    <dependency type="extension">org.inkscape.input.pdf</dependency>    
+    <dependency type="executable" location="path">ps2pdf</dependency>
+    <dependency type="executable" location="extensions">ps2pdf-ext.py</dependency>
     <input>
         <extension>.eps</extension>
         <mimetype>image/x-encapsulated-postscript</mimetype>
-        <_filetypename>Encapsulated Postscript (*.eps)</_filetypename>
-        <_filetypetooltip>Encapsulated Postscript</_filetypetooltip>
+        <_filetypename>Encapsulated PostScript (*.eps)</_filetypename>
+        <_filetypetooltip>Encapsulated PostScript</_filetypetooltip>
         <output_extension>org.inkscape.output.eps</output_extension>
     </input>
     <script>
-        <command reldir="path">pstoedit -f plot-svg</command>
+        <command reldir="extensions" interpreter="python">ps2pdf-ext.py</command>
+        <helper_extension>org.inkscape.input.pdf</helper_extension>
     </script>
 </inkscape-extension>
diff --git a/share/extensions/ps2pdf-ext.py b/share/extensions/ps2pdf-ext.py
new file mode 100644 (file)
index 0000000..80d98c0
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/env python\r
+\r
+"""\r
+pstoedit-ext.py\r
+Python script for running pstoedit in Inkscape extensions\r
+\r
+Copyright (C) 2008 Stephen Silver\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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+"""\r
+\r
+import sys\r
+from run_command import run\r
+\r
+#run('pstoedit -f plot-svg -dt -ssp "%s" "%%s"' % sys.argv[1], "pstoedit")\r
+\rrun('ps2pdf "%s" "%%s"' % sys.argv[1], "ps2pdf")\r
+\r
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99\r
index 54b2b20f1af489b1f7d624582573a9d1fdf41d8b..c7677ffe2642403bfd159ad10258062a88eb6385 100644 (file)
@@ -1,16 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
-    <_name>Postscript Input</_name>
+    <_name>PostScript Input</_name>
     <id>org.inkscape.input.ps</id>
-    <dependency type="executable">pstoedit</dependency>
+    <dependency type="extension">org.inkscape.input.pdf</dependency>
+    <dependency type="executable" location="path">ps2pdf</dependency>
+    <dependency type="executable" location="extensions">ps2pdf-ext.py</dependency>
     <input>
         <extension>.ps</extension>
         <mimetype>image/x-postscript</mimetype>
-        <_filetypename>Postscript (*.ps)</_filetypename>
-        <_filetypetooltip>Postscript</_filetypetooltip>
+        <_filetypename>PostScript (*.ps)</_filetypename>
+        <_filetypetooltip>PostScript</_filetypetooltip>
         <output_extension>org.inkscape.output.ps</output_extension>
     </input>
     <script>
-        <command reldir="path">pstoedit -f plot-svg</command>
+        <command reldir="extensions" interpreter="python">ps2pdf-ext.py</command>
+        <helper_extension>org.inkscape.input.pdf</helper_extension>
     </script>
 </inkscape-extension>
diff --git a/share/extensions/run_command.py b/share/extensions/run_command.py
new file mode 100644 (file)
index 0000000..0919d76
--- /dev/null
@@ -0,0 +1,86 @@
+import os\r
+import sys\r
+import tempfile\r
+\r
+"""\r
+run_command.py\r
+Module for running SVG-generating commands in Inkscape extensions\r
+\r
+Copyright (C) 2008 Stephen Silver\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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+"""\r
+\r
+# Run a command that generates an SVG file from an input file.\r
+# On success, outputs the contents of the SVG file to stdout, and exits\r
+# with a return code of 0.\r
+# On failure, outputs an error message to stderr, and exits with a return\r
+# code of 1.\r
+def run(command_format, prog_name):\r
+    svgfile = tempfile.mktemp(".svg")\r
+    command = command_format % svgfile\r
+    msg = None\r
+    # In order to get a return code from the process, we use subprocess.Popen\r
+    # if it's available (Python 2.4 onwards) and otherwise use popen2.Popen3\r
+    # (Unix only).  As the Inkscape package for Windows includes Python 2.5,\r
+    # this should cover all supported platforms.\r
+    try:\r
+        try:\r
+            from subprocess import Popen, PIPE\r
+            p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)\r
+            rc = p.wait()\r
+            out = p.stdout.read()\r
+            err = p.stderr.read()\r
+        except ImportError:\r
+            try:\r
+                from popen2 import Popen3\r
+                p = Popen3(command, True)\r
+                p.wait()\r
+                rc = p.poll()\r
+                out = p.fromchild.read()\r
+                err = p.childerr.read()\r
+            except ImportError:\r
+                # shouldn't happen...\r
+                msg = "Neither subprocess.Popen nor popen2.Popen3 is available"\r
+        if rc and msg is None:\r
+            msg = "%s failed:\n%s\n%s\n" % (prog_name, out, err)\r
+    except Exception, inst:\r
+        msg = "Error attempting to run %s: %s" % (prog_name, str(inst))\r
+\r
+    # If successful, copy the SVG file to stdout.\r
+    if msg is None:\r
+        try:\r
+            f = open(svgfile, "rb")\r
+            data = f.read()
+            sys.stdout.write(data)\r
+            f.close()\r
+        except IOError, inst:\r
+            msg = "Error reading temporary SVG file: %s" % str(inst)\r
+\r
+    # Clean up.\r
+    try:
+        os.remove(svgfile)\r
+    except Exception:\r
+        pass\r
+\r
+    # Ouput error message (if any) and exit.\r
+    if msg is not None:\r
+        sys.stderr.write(msg + "\n")\r
+        sys.exit(1)\r
+    else:\r
+        sys.exit(0)\r
+\r
+\r
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99\r
index 63a76cad4f7e9297b36c4a2b9ce8eafd7291c978..1197f97bbbc250e24c5bdd427923f94d42b85367 100644 (file)
@@ -19,54 +19,12 @@ GNU General Public License for more details.
 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
-
 """
 
-import os
-import random
-import subprocess
 import sys
-import tempfile
-
-# We need a filename ending in ".svg" for UniConvertor.
-# This is a hack.
-chars = list("0123456789abcdefghijklmnopqrstuvwxyz")
-while True:
-    random.shuffle(chars)
-    svgfile = os.path.join(tempfile.gettempdir(), ''.join(chars) + '.svg')
-    if not os.path.exists(svgfile):
-        break
-
-# Run UniConvertor, and determine our return code.
-try:
-    p = subprocess.Popen('uniconv "%s" "%s"' % (sys.argv[1], svgfile),
-                         shell=True, stderr=subprocess.PIPE)
-    err = p.stderr.read()
-    rc = p.wait()
-    if rc:
-        sys.stderr.write("UniConvertor failed: %s\n" % err)
-        rc = 1
-except Exception, inst:
-    sys.stderr.write("Spawn error: %s\n" % str(inst))
-    rc = 1
-
-# If successful, copy the SVG file to stdout.
-if rc == 0:
-    try:
-        f = open(svgfile, "rU")
-        for line in f:
-            sys.stdout.write(line)
-        f.close()
-    except IOError, inst:
-        sys.stderr.write("Error reading temporary SVG file: %s\n" % str(inst))
-        rc = 1
+from run_command import run
 
-# Clean up and return.
-try:
-    os.remove(svgfile)
-except Exception:
-    pass
-sys.exit(rc)
+run('uniconv "%s" "%%s"' % sys.argv[1], "UniConvertor")
 
 
 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99