Scribus cmdline import/export (patch)
Hi Peter and Craig,
A while back we discussed an idea of packaging the scribus pdf/ps import/export code for use with Inkscape, since Inkscape's pdf/ps (esp. EPS import) support is so poor.
However it occurs to me that another solution would be to simply give scribus some commandline options for doing import/export. E.g.
scribus -i filename.eps -e filename.svg
Inkscape would then be able to make use of scribus' import/export capabilities via its extension mechanism. Since for all practical intents and purposes, people would need to use scribus for getting eps/pdf converted to svg for use in inkscape already anyway, I don't think this imposes much additional dependency hassle for them.
I looked into the scribus code a bit to see how this could be implemented. I wasn't sure how to call the import/export plugins, but I sketched out the code for handling the -i/-e commandline options as a start... See the attached patch. I put TODO's where the code to invoke the import/export plugins would go.
I think that if it supported command line options for your input/output operators, scribus would become more widely useful, especially for commercial users (look at http://www.pdftron.com/store.html).
Bryce
--- main.cpp.orig 2005-09-24 22:48:40.000000000 -0700 +++ main.cpp 2005-09-24 22:17:48.000000000 -0700 @@ -52,6 +52,8 @@ #define ARG_NOSPLASH "--no-splash" #define ARG_NOGUI "--no-gui" #define ARG_DISPLAY "--display" +#define ARG_IMPORT "--import" +#define ARG_EXPORT "--export"
#define ARG_VERSION_SHORT "-v" #define ARG_HELP_SHORT "-h" @@ -60,12 +62,16 @@ #define ARG_NOSPLASH_SHORT "-s" #define ARG_NOGUI_SHORT "-g" #define ARG_DISPLAY_SHORT "-d" +#define ARG_IMPORT_SHORT "-i" +#define ARG_EXPORT_SHORT "-e"
QString lang = ""; bool showSplash = true; bool useGui = true; QString file; +QString import_filename = ""; +QString export_filename = "";
void showUsage(); void showAvailLangs(); @@ -102,6 +108,20 @@ lang = argv[i]; } else if (arg == ARG_NOSPLASH || arg == ARG_NOSPLASH_SHORT) { showSplash = false; + } else if ((arg == ARG_IMPORT || arg == ARG_IMPORT_SHORT) && (++i < argc)) { + import_filename = QFile::decodeName(argv[i]); + if (!QFileInfo(import_filename).exists()) { + std::cout << std::endl; + if (import_filename.left(1) == "-" || import_filename.left(2) == "--") { + std::cout << "Invalid argument: " << import_filename << std::endl; + } else { + std::cout << "File " << import_filename << "does not exist, aborting." << std::endl; + } + showUsage(); + return 0; + } + } else if ((arg == ARG_EXPORT || arg == ARG_EXPORT_SHORT) && (++i < argc)) { + export_filename = QFile::decodeName(argv[i]); } else if (arg == ARG_NOGUI || arg == ARG_NOGUI_SHORT) { useGui = false; } else if ((arg == ARG_DISPLAY || arg==ARG_DISPLAY_SHORT) && ++i < argc) { @@ -123,7 +143,8 @@ }
if (useGui) - return mainGui(argc, argv); + return mainGui(argc, argv); + }
/*! @@ -145,6 +166,8 @@ std::cout << "-la, --langs-available Lists the currently installed interface languages" << std::endl; std::cout << "-h, --help Print help (this message) and exit" << std::endl; std::cout << "-v, --version Output version information and exit" << std::endl; + std::cout << "-i, --import <file> Import given filename" << std::endl; + std::cout << "-e, --export <file> Export given filename" << std::endl; /* std::cout << "-file|-- name Open file 'name'" << std::endl; std::cout << "name Open file 'name', the file name must not begin with '-'" << std::endl; @@ -214,10 +237,24 @@
scribus->show(); scribus->ShowSubs(); - if (file != "") - scribus->LadeDoc(file); + if (file != "") { + scribus->LadeDoc(file); + } else if (import_filename != "") { + // TODO: Import the file... + } scribus->setFocus(); - return app.exec(); + + if (export_filename != "") { + QFile f(export_filename); + if (f.exists()) { + std::cout << "Cannot overwrite existing file " << export_filename << std::endl; + return -1; + } + // TODO: Export the file... + return 0; + } else { + return app.exec(); + } }
/*!
On Sat, 2005-09-24 at 23:26 -0700, Bryce Harrington wrote:
Hi Peter and Craig,
A while back we discussed an idea of packaging the scribus pdf/ps import/export code for use with Inkscape, since Inkscape's pdf/ps (esp. EPS import) support is so poor.
Indeed. It's a nice idea. Much of the current PS/PDF import and export code is very tightly Scribus specific though, and it all uses a lot of Qt container classes etc. I'm not sure how practical that'd be.
However it occurs to me that another solution would be to simply give scribus some commandline options for doing import/export. E.g.
scribus -i filename.eps -e filename.svg
This has been desired for a long time. See http://bugs.scribus.net/view.php?id=238 . We're still not at the point where that's quite practical, though we're certainly getting there.
Being able to do it without an X-server and with a low startup time may well be post-Qt4-migration stuff though (Riku will know much more than me about this).
I looked into the scribus code a bit to see how this could be implemented. I wasn't sure how to call the import/export plugins
As chance would have it, that's something I'm going to be working on soon. There's just a pile of university stuff to deal with first.
For importers/exporters that already have plugins, you can use the plugin manager to call them. There's code in fileloader.cpp for that, but it might be a bit tricky to follow.
The general approach you could take is:
#include "scplugin.h" #include "pluginmanager.h"
ScActionPlugin* plug = dynamic_cast<ScActionPlugin*>(PluginManager::instance().getPlugin("importps")); if (plug) { bool result = plug->run("/path/to/PS-file-to-import"); // Act on result code } else { // Inform the user that you couldn't do what they asked because // you couldn't access the required plugin. }
There is currently no good way to enumerate supported formats, etc, automatically. That's planned, though, and should hopefully happen during 1.3.2cvs development.
Once that's done, your TODO should simply become a call into FileLoader.
-- Craig Ringer
On Sun, Sep 25, 2005 at 04:16:40PM +0800, Craig Ringer wrote:
On Sat, 2005-09-24 at 23:26 -0700, Bryce Harrington wrote:
However it occurs to me that another solution would be to simply give scribus some commandline options for doing import/export. E.g.
scribus -i filename.eps -e filename.svg
This has been desired for a long time. See http://bugs.scribus.net/view.php?id=238 . We're still not at the point where that's quite practical, though we're certainly getting there.
Being able to do it without an X-server and with a low startup time may well be post-Qt4-migration stuff though (Riku will know much more than me about this).
I was thinking about this too. With Inkscape when we first started doing intensive commandline stuff, we had some branches of code that relied on X for error dialogs and such, but did it anyway, and sorted out the X issues later. They're annoying, but straightforward to solve. A converter that requires X to run is certainly superior to no converter at all...
For purposes of conversion, startup time is really a secondary issue; it probably isn't worth it as a driver for you.
I looked into the scribus code a bit to see how this could be implemented. I wasn't sure how to call the import/export plugins
As chance would have it, that's something I'm going to be working on soon. There's just a pile of university stuff to deal with first.
Cool.
For importers/exporters that already have plugins, you can use the plugin manager to call them. There's code in fileloader.cpp for that, but it might be a bit tricky to follow.
The general approach you could take is:
#include "scplugin.h" #include "pluginmanager.h"
ScActionPlugin* plug = dynamic_cast<ScActionPlugin*>(PluginManager::instance().getPlugin("importps")); if (plug) { bool result = plug->run("/path/to/PS-file-to-import"); // Act on result code } else { // Inform the user that you couldn't do what they asked because // you couldn't access the required plugin. }
Okay, if I get time I'll investigate this.
There is currently no good way to enumerate supported formats, etc, automatically. That's planned, though, and should hopefully happen during 1.3.2cvs development.
Once that's done, your TODO should simply become a call into FileLoader.
Thanks, Bryce
participants (2)
-
Bryce Harrington
-
Craig Ringer