diff options
| author | bulia byak <buliabyak@gmail.com> | 2008-06-14 04:12:54 +0000 |
|---|---|---|
| committer | buliabyak <buliabyak@users.sourceforge.net> | 2008-06-14 04:12:54 +0000 |
| commit | 6bd9f46bfe5e567626239fb8e8d62e00b1021657 (patch) | |
| tree | 9eb5ac260b85930cb16519d814ce83abd9ff7cb4 | |
| parent | disable unused pdf-input-cairo (diff) | |
| download | inkscape-6bd9f46bfe5e567626239fb8e8d62e00b1021657.tar.gz inkscape-6bd9f46bfe5e567626239fb8e8d62e00b1021657.zip | |
patch by sas from 227449 with my changes for using ps2pdf instead of pstoedit
(bzr r5924)
| -rw-r--r-- | share/extensions/Makefile.am | 2 | ||||
| -rw-r--r-- | share/extensions/eps_input.inx | 11 | ||||
| -rw-r--r-- | share/extensions/ps2pdf-ext.py | 30 | ||||
| -rw-r--r-- | share/extensions/ps_input.inx | 13 | ||||
| -rw-r--r-- | share/extensions/run_command.py | 86 | ||||
| -rw-r--r-- | share/extensions/uniconv-ext.py | 46 |
6 files changed, 135 insertions, 53 deletions
diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 73b5ad78a..909327cc9 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -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 \ diff --git a/share/extensions/eps_input.inx b/share/extensions/eps_input.inx index 5529f003b..14f33764d 100644 --- a/share/extensions/eps_input.inx +++ b/share/extensions/eps_input.inx @@ -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 index 000000000..80d98c040 --- /dev/null +++ b/share/extensions/ps2pdf-ext.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python
+
+"""
+pstoedit-ext.py
+Python script for running pstoedit in Inkscape extensions
+
+Copyright (C) 2008 Stephen Silver
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+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 sys
+from run_command import run
+
+#run('pstoedit -f plot-svg -dt -ssp "%s" "%%s"' % sys.argv[1], "pstoedit")
+
run('ps2pdf "%s" "%%s"' % sys.argv[1], "ps2pdf")
+
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99
diff --git a/share/extensions/ps_input.inx b/share/extensions/ps_input.inx index 54b2b20f1..c7677ffe2 100644 --- a/share/extensions/ps_input.inx +++ b/share/extensions/ps_input.inx @@ -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 index 000000000..0919d767d --- /dev/null +++ b/share/extensions/run_command.py @@ -0,0 +1,86 @@ +import os
+import sys
+import tempfile
+
+"""
+run_command.py
+Module for running SVG-generating commands in Inkscape extensions
+
+Copyright (C) 2008 Stephen Silver
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+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
+"""
+
+# Run a command that generates an SVG file from an input file.
+# On success, outputs the contents of the SVG file to stdout, and exits
+# with a return code of 0.
+# On failure, outputs an error message to stderr, and exits with a return
+# code of 1.
+def run(command_format, prog_name):
+ svgfile = tempfile.mktemp(".svg")
+ command = command_format % svgfile
+ msg = None
+ # In order to get a return code from the process, we use subprocess.Popen
+ # if it's available (Python 2.4 onwards) and otherwise use popen2.Popen3
+ # (Unix only). As the Inkscape package for Windows includes Python 2.5,
+ # this should cover all supported platforms.
+ try:
+ try:
+ from subprocess import Popen, PIPE
+ p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
+ rc = p.wait()
+ out = p.stdout.read()
+ err = p.stderr.read()
+ except ImportError:
+ try:
+ from popen2 import Popen3
+ p = Popen3(command, True)
+ p.wait()
+ rc = p.poll()
+ out = p.fromchild.read()
+ err = p.childerr.read()
+ except ImportError:
+ # shouldn't happen...
+ msg = "Neither subprocess.Popen nor popen2.Popen3 is available"
+ if rc and msg is None:
+ msg = "%s failed:\n%s\n%s\n" % (prog_name, out, err)
+ except Exception, inst:
+ msg = "Error attempting to run %s: %s" % (prog_name, str(inst))
+
+ # If successful, copy the SVG file to stdout.
+ if msg is None:
+ try:
+ f = open(svgfile, "rb")
+ data = f.read() + sys.stdout.write(data)
+ f.close()
+ except IOError, inst:
+ msg = "Error reading temporary SVG file: %s" % str(inst)
+
+ # Clean up.
+ try: + os.remove(svgfile)
+ except Exception:
+ pass
+
+ # Ouput error message (if any) and exit.
+ if msg is not None:
+ sys.stderr.write(msg + "\n")
+ sys.exit(1)
+ else:
+ sys.exit(0)
+
+
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99
diff --git a/share/extensions/uniconv-ext.py b/share/extensions/uniconv-ext.py index 63a76cad4..1197f97bb 100644 --- a/share/extensions/uniconv-ext.py +++ b/share/extensions/uniconv-ext.py @@ -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 |
