Feature Request: Allow exports based on mime type
Migrated from https://bugs.launchpad.net/inkscape/+bug/1777216
Inkscape v0.92.3 supports the following exports
-l, --export-plain-svg=FILENAME Export document to plain SVG file (no sodipodi or inkscape namespaces)
-P, --export-ps=FILENAME Export document to a PS file
-E, --export-eps=FILENAME Export document to an EPS file
--export-ps-level=PS Level Choose the PostScript Level used to export. Possible choices are 2 and 3 (the default)
-A, --export-pdf=FILENAME Export document to a PDF file
--export-pdf-version=PDF_VERSION Export PDF to given version. (hint: make sure to input the exact string found in the PDF export dialog, e.g. "1.4" which is PDF-a conformant)
--export-latex Export PDF/PS/EPS without text. Besides the PDF/PS/EPS, a LaTeX file is exported, putting the text on top of the PDF/PS/EPS file. Include the result in LaTeX like:
\input{latexfile.tex}
-M, --export-emf=FILENAME Export document to an Enhanced Metafile (EMF) File
-m, --export-wmf=FILENAME Export document to a Windows Metafile (WMF) File
The problem with the above way is, it only allows a subset of options that Inkscape UI supports. For eg., I can save file as "Synfig Animation (*.sif)" from the UI, but there is no option to do this via terminal. The reason for this is because the way options are exposed to the terminal (NOTE that I'm a complete noob w.r.t understanding Inkscape at code level).
If we add a generic mime type based exports, we should be able to support all exports available in the Save As menu can be exposed from the terminal as well.
For example, if we add a generic --export-mime-type=image/sif --export-path=<PATH>
, then inkscape should be able to automatically invoke the output extension that support this mime type (or) throw an error if no one knows the export format.
I looked at the code and I clearly see that the existing code can be trivially modified to suport the above two options. For example, here is the code for exporting to .wmf format (from main.cpp
). This code already does everything but somehow is called only for .wmf/.emf files (not sure of why this is the case). This method can be called with the above generic mime type based arguments as well.
/**
* Export a document to EMF or WMF
*
* \param doc Document to export.
* \param uri URI to export to.
* \param mime MIME type to export as (should be "image/x-emf" or "image/x-wmf")
*/
static int do_export_win_metafile_common(SPDocument* doc, gchar const* uri, char const* mime)
{
Inkscape::Extension::DB::OutputList o;
Inkscape::Extension::db.get_output_list(o);
Inkscape::Extension::DB::OutputList::const_iterator i = o.begin();
while (i != o.end() && strcmp( (*i)->get_mimetype(), mime ) != 0) {
i++;
}
if (i == o.end())
{
g_warning ("Could not find an extension to export to MIME type %s.", mime);
return 1;
}
//check if specified directory exists
if (!Inkscape::IO::file_directory_exists(uri)){
g_warning("File path \"%s\" includes directory that doesn't exist.\n",
uri);
return 1;
}
(*i)->save(doc, uri);
return 0;
}
Unless I'm missing something very obvious, adding this mime-based export support should be trivial. Please let me know if I'm wrong in any of my analaysis (due to my poor understanding).
PS: I'm not a cpp programmer, or else I could have submitted a pull request.
Inkscape Version and Operating System:
- Inkscape Version: Inkscape 0.92.3 (unknown)
- Operating System: Ubuntu
- Operating System Version: 14.04