summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2014-03-27 01:33:44 +0000
committerMartin Owens <doctormo@gmail.com>2014-03-27 01:33:44 +0000
commit5a4fb2325f60d292b47330f540b26a3279341c90 (patch)
treed2aa7967be25450b83e625025366c618101ae49f /src/main.cpp
parentThe Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff)
parentRemove Snap menu item and improve grid menu item text (diff)
downloadinkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz
inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp451
1 files changed, 362 insertions, 89 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 261df9145..25f813c2b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,7 +11,7 @@
* Michael Meeks <michael@helixcode.com>
* Chema Celorio <chema@celorio.com>
* Pawel Palucha
- * Bryce Harrington <bryce@bryceharrington.com>
+ * Bryce Harrington <bryce@bryceharrington.org>
* ... and various people who have worked with various projects
* Jon A. Cruz <jon@oncruz.org>
* Abhishek Sharma
@@ -26,12 +26,13 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include "path-prefix.h"
// This has to be included prior to anything that includes setjmp.h, it croaks otherwise
#include <png.h>
-#include "ui/widget/panel.h"
+#include "ui/widget/panel.h" // This has to be the first to include <glib.h> because of Glibmm's dependence on a deprecated feature...
+
+#include "path-prefix.h"
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
@@ -47,7 +48,6 @@
#endif /* Not def: POPT_TABLEEND */
#include <libxml/tree.h>
-#include <glib.h>
#include <glib/gprintf.h>
#include <glib-object.h>
#include <gtk/gtk.h>
@@ -61,13 +61,14 @@
#include "macros.h"
#include "file.h"
#include "document.h"
+#include "layer-model.h"
+#include "selection.h"
#include "sp-object.h"
#include "interface.h"
#include "print.h"
#include "color.h"
#include "sp-item.h"
#include "sp-root.h"
-#include "unit-constants.h"
#include "svg/svg.h"
#include "svg/svg-color.h"
@@ -78,7 +79,6 @@
#include "sp-namedview.h"
#include "sp-guide.h"
-#include "sp-object-repr.h"
#include "xml/repr.h"
#include "io/sys.h"
@@ -86,6 +86,7 @@
#include "debug/logger.h"
#include "debug/log-display-config.h"
+#include "helper/action-context.h"
#include "helper/png-write.h"
#include "helper/geom.h"
@@ -101,8 +102,16 @@
#endif // WIN32
#include "extension/init.h"
+// Not ideal, but there doesn't appear to be a nicer system in place for
+// passing command-line parameters to extensions before initialization...
+#ifdef WITH_DBUS
+#include "extension/dbus/dbus-init.h"
+#endif // WITH_DBUS
#include <glibmm/i18n.h>
+#include <glibmm/main.h>
+#include <glibmm/miscutils.h>
+
#include <gtkmm/main.h>
#ifndef HAVE_BIND_TEXTDOMAIN_CODESET
@@ -117,9 +126,10 @@
#include <gdk/gdkkeysyms.h>
-#if !GTK_CHECK_VERSION(2,22,0)
-#include "compat-key-syms.h"
-#endif
+#include "path-chemistry.h"
+#include "sp-text.h"
+#include "sp-flowtext.h"
+#include "text-editing.h"
enum {
SP_ARG_NONE,
@@ -132,6 +142,7 @@ enum {
SP_ARG_EXPORT_AREA,
SP_ARG_EXPORT_AREA_DRAWING,
SP_ARG_EXPORT_AREA_PAGE,
+ SP_ARG_EXPORT_MARGIN,
SP_ARG_EXPORT_AREA_SNAP,
SP_ARG_EXPORT_WIDTH,
SP_ARG_EXPORT_HEIGHT,
@@ -143,11 +154,12 @@ enum {
SP_ARG_EXPORT_SVG,
SP_ARG_EXPORT_PS,
SP_ARG_EXPORT_EPS,
+ SP_ARG_EXPORT_PS_LEVEL,
SP_ARG_EXPORT_PDF,
+ SP_ARG_EXPORT_PDF_VERSION,
SP_ARG_EXPORT_LATEX,
-#ifdef WIN32
SP_ARG_EXPORT_EMF,
-#endif //WIN32
+ SP_ARG_EXPORT_WMF,
SP_ARG_EXPORT_TEXT_TO_PATH,
SP_ARG_EXPORT_IGNORE_FILTERS,
SP_ARG_EXTENSIONDIR,
@@ -160,6 +172,10 @@ enum {
SP_ARG_SHELL,
SP_ARG_VERSION,
SP_ARG_VACUUM_DEFS,
+#ifdef WITH_DBUS
+ SP_ARG_DBUS_LISTEN,
+ SP_ARG_DBUS_NAME,
+#endif // WITH_DBUS
SP_ARG_VERB_LIST,
SP_ARG_VERB,
SP_ARG_SELECT,
@@ -168,11 +184,11 @@ enum {
int sp_main_gui(int argc, char const **argv);
int sp_main_console(int argc, char const **argv);
-static void sp_do_export_png(SPDocument *doc);
-static void do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const *mime);
-#ifdef WIN32
-static void do_export_emf(SPDocument* doc, gchar const* uri, char const *mime);
-#endif //WIN32
+static int sp_do_export_png(SPDocument *doc);
+static int do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const *mime);
+static int do_export_emf(SPDocument* doc, gchar const* uri, char const *mime);
+static int do_export_wmf(SPDocument* doc, gchar const* uri, char const *mime);
+static int do_export_win_metafile_common(SPDocument* doc, gchar const* uri, char const *mime);
static void do_query_dimension (SPDocument *doc, bool extent, Geom::Dim2 const axis, const gchar *id);
static void do_query_all (SPDocument *doc);
static void do_query_all_recurse (SPObject *o);
@@ -183,6 +199,7 @@ static gchar *sp_export_dpi = NULL;
static gchar *sp_export_area = NULL;
static gboolean sp_export_area_drawing = FALSE;
static gboolean sp_export_area_page = FALSE;
+static gchar *sp_export_margin = NULL;
static gboolean sp_export_latex = FALSE;
static gchar *sp_export_width = NULL;
static gchar *sp_export_height = NULL;
@@ -195,10 +212,11 @@ static gboolean sp_export_id_only = FALSE;
static gchar *sp_export_svg = NULL;
static gchar *sp_export_ps = NULL;
static gchar *sp_export_eps = NULL;
+static gint sp_export_ps_level = 2;
static gchar *sp_export_pdf = NULL;
-#ifdef WIN32
+static gchar *sp_export_pdf_version = NULL;
static gchar *sp_export_emf = NULL;
-#endif //WIN32
+static gchar *sp_export_wmf = NULL;
static gboolean sp_export_text_to_path = FALSE;
static gboolean sp_export_ignore_filters = FALSE;
static gboolean sp_export_font = FALSE;
@@ -210,7 +228,10 @@ static gboolean sp_query_all = FALSE;
static gchar *sp_query_id = NULL;
static gboolean sp_shell = FALSE;
static gboolean sp_vacuum_defs = FALSE;
-
+#ifdef WITH_DBUS
+static gboolean sp_dbus_listen = FALSE;
+static gchar *sp_dbus_name = NULL;
+#endif // WITH_DBUS
static gchar *sp_export_png_utf8 = NULL;
static gchar *sp_export_svg_utf8 = NULL;
static gchar *sp_global_printer_utf8 = NULL;
@@ -226,6 +247,7 @@ static void resetCommandlineGlobals() {
sp_export_area = NULL;
sp_export_area_drawing = FALSE;
sp_export_area_page = FALSE;
+ sp_export_margin = NULL;
sp_export_latex = FALSE;
sp_export_width = NULL;
sp_export_height = NULL;
@@ -238,10 +260,11 @@ static void resetCommandlineGlobals() {
sp_export_svg = NULL;
sp_export_ps = NULL;
sp_export_eps = NULL;
+ sp_export_ps_level = 2;
sp_export_pdf = NULL;
-#ifdef WIN32
+ sp_export_pdf_version = NULL;
sp_export_emf = NULL;
-#endif //WIN32
+ sp_export_wmf = NULL;
sp_export_text_to_path = FALSE;
sp_export_ignore_filters = FALSE;
sp_export_font = FALSE;
@@ -252,6 +275,10 @@ static void resetCommandlineGlobals() {
sp_query_all = FALSE;
sp_query_id = NULL;
sp_vacuum_defs = FALSE;
+#ifdef WITH_DBUS
+ sp_dbus_listen = FALSE;
+ sp_dbus_name = NULL;
+#endif // WITH_DBUS
sp_export_png_utf8 = NULL;
sp_export_svg_utf8 = NULL;
@@ -313,6 +340,11 @@ struct poptOption options[] = {
N_("Exported area is the entire page"),
NULL},
+ {"export-margin", 0,
+ POPT_ARG_STRING, &sp_export_margin, SP_ARG_EXPORT_MARGIN,
+ N_("Only for PS/EPS/PDF, sets margin in mm around exported area (default 0)"),
+ N_("VALUE")},
+
{"export-area-snap", 0,
POPT_ARG_NONE, &sp_export_area_snap, SP_ARG_EXPORT_AREA_SNAP,
N_("Snap the bitmap export area outwards to the nearest integer values (in SVG user units)"),
@@ -370,26 +402,41 @@ struct poptOption options[] = {
N_("Export document to an EPS file"),
N_("FILENAME")},
+ {"export-ps-level", 0,
+ POPT_ARG_INT, &sp_export_ps_level, SP_ARG_EXPORT_PS_LEVEL,
+ N_("Choose the PostScript Level used to export. Possible choices are"
+ " 2 (the default) and 3"),
+ N_("PS Level")},
+
{"export-pdf", 'A',
POPT_ARG_STRING, &sp_export_pdf, SP_ARG_EXPORT_PDF,
N_("Export document to a PDF file"),
N_("FILENAME")},
+ {"export-pdf-version", 0,
+ POPT_ARG_STRING, &sp_export_pdf_version, SP_ARG_EXPORT_PDF_VERSION,
+ // TRANSLATORS: "--export-pdf-version" is an Inkscape command line option; see "inkscape --help"
+ N_("Export PDF to given version. (hint: make sure to input the exact string found in the PDF export dialog, e.g. \"PDF 1.4\" which is PDF-a conformant)"),
+ N_("PDF_VERSION")},
+
{"export-latex", 0,
POPT_ARG_NONE, &sp_export_latex, SP_ARG_EXPORT_LATEX,
N_("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}"),
NULL},
-#ifdef WIN32
{"export-emf", 'M',
POPT_ARG_STRING, &sp_export_emf, SP_ARG_EXPORT_EMF,
N_("Export document to an Enhanced Metafile (EMF) File"),
N_("FILENAME")},
-#endif //WIN32
+
+ {"export-wmf", 'm',
+ POPT_ARG_STRING, &sp_export_wmf, SP_ARG_EXPORT_WMF,
+ N_("Export document to a Windows Metafile (WMF) File"),
+ N_("FILENAME")},
{"export-text-to-path", 'T',
POPT_ARG_NONE, &sp_export_text_to_path, SP_ARG_EXPORT_TEXT_TO_PATH,
- N_("Convert text object to paths on export (PS, EPS, PDF)"),
+ N_("Convert text object to paths on export (PS, EPS, PDF, SVG)"),
NULL},
{"export-ignore-filters", 0,
@@ -441,6 +488,18 @@ struct poptOption options[] = {
POPT_ARG_NONE, &sp_vacuum_defs, SP_ARG_VACUUM_DEFS,
N_("Remove unused definitions from the defs section(s) of the document"),
NULL},
+
+#ifdef WITH_DBUS
+ {"dbus-listen", 0,
+ POPT_ARG_NONE, &sp_dbus_listen, SP_ARG_DBUS_LISTEN,
+ N_("Enter a listening loop for D-Bus messages in console mode"),
+ NULL},
+
+ {"dbus-name", 0,
+ POPT_ARG_STRING, &sp_dbus_name, SP_ARG_DBUS_NAME,
+ N_("Specify the D-Bus bus name to listen for messages on (default is org.inkscape)"),
+ N_("BUS-NAME")},
+#endif // WITH_DBUS
{"verb-list", 0,
POPT_ARG_NONE, NULL, SP_ARG_VERB_LIST,
@@ -473,7 +532,8 @@ gchar * blankParam = g_strdup("");
#ifdef WIN32
/**
- * Set up the PATH and PYTHONPATH environment variables on Windows
+ * Set up the PATH, INKSCAPE_LOCALEDIR and PYTHONPATH environment
+ * variables on Windows
* @param exe Inkscape executable directory in UTF-8
*/
static void _win32_set_inkscape_env(gchar const *exe)
@@ -525,6 +585,13 @@ static void _win32_set_inkscape_env(gchar const *exe)
printf("python not found\n\n");
}*/
+ // INKSCAPE_LOCALEDIR is needed by Python/Gettext
+ gchar *localepath = g_build_filename(exe, PACKAGE_LOCALE_DIR, NULL);
+ g_setenv("INKSCAPE_LOCALEDIR", localepath, TRUE);
+
+ // prevent "please insert disk" messages. fixes bug #950781
+ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
+
g_free(python);
g_free(scripts);
g_free(perl);
@@ -537,6 +604,8 @@ static void _win32_set_inkscape_env(gchar const *exe)
g_free(new_path);
g_free(new_pythonpath);
+
+ g_free(localepath);
}
#endif
@@ -617,6 +686,8 @@ main(int argc, char **argv)
bindtextdomain(GETTEXT_PACKAGE, BR_LOCALEDIR(""));
# else
bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
+ // needed by Python/Gettext
+ g_setenv("PACKAGE_LOCALE_DIR", PACKAGE_LOCALE_DIR, TRUE);
# endif
#endif
@@ -675,10 +746,10 @@ main(int argc, char **argv)
|| !strcmp(argv[i], "-A")
|| !strncmp(argv[i], "--export-pdf", 12)
|| !strncmp(argv[i], "--export-latex", 14)
-#ifdef WIN32
|| !strcmp(argv[i], "-M")
|| !strncmp(argv[i], "--export-emf", 12)
-#endif //WIN32
+ || !strcmp(argv[i], "-m")
+ || !strncmp(argv[i], "--export-wmf", 12)
|| !strcmp(argv[i], "-W")
|| !strncmp(argv[i], "--query-width", 13)
|| !strcmp(argv[i], "-H")
@@ -690,6 +761,9 @@ main(int argc, char **argv)
|| !strcmp(argv[i], "-Y")
|| !strncmp(argv[i], "--query-y", 9)
|| !strcmp(argv[i], "--vacuum-defs")
+#ifdef WITH_DBUS
+ || !strcmp(argv[i], "--dbus-listen")
+#endif // WITH_DBUS
|| !strcmp(argv[i], "--shell")
)
{
@@ -723,7 +797,7 @@ main(int argc, char **argv)
-void fixupSingleFilename( gchar **orig, gchar **spare )
+static void fixupSingleFilename( gchar **orig, gchar **spare )
{
if ( orig && *orig && **orig ) {
GError *error = NULL;
@@ -741,7 +815,7 @@ void fixupSingleFilename( gchar **orig, gchar **spare )
-GSList *fixupFilenameEncoding( GSList* fl )
+static GSList *fixupFilenameEncoding( GSList* fl )
{
GSList *newFl = NULL;
while ( fl ) {
@@ -780,11 +854,11 @@ GSList *fixupFilenameEncoding( GSList* fl )
return newFl;
}
-int sp_common_main( int argc, char const **argv, GSList **flDest )
+static int sp_common_main( int argc, char const **argv, GSList **flDest )
{
/// \todo fixme: Move these to some centralized location (Lauris)
- sp_object_type_register("sodipodi:namedview", SP_TYPE_NAMEDVIEW);
- sp_object_type_register("sodipodi:guide", SP_TYPE_GUIDE);
+ //sp_object_type_register("sodipodi:namedview", SP_TYPE_NAMEDVIEW);
+ //sp_object_type_register("sodipodi:guide", SP_TYPE_GUIDE);
// temporarily switch gettext encoding to locale, so that help messages can be output properly
@@ -826,6 +900,13 @@ int sp_common_main( int argc, char const **argv, GSList **flDest )
if ( sp_global_printer )
sp_global_printer_utf8 = g_strdup( sp_global_printer );
}
+
+#ifdef WITH_DBUS
+ // Before initializing extensions, we must set the DBus bus name if required
+ if (sp_dbus_name != NULL) {
+ Inkscape::Extension::Dbus::dbus_set_bus_name(sp_dbus_name);
+ }
+#endif
// Return the list if wanted, else free it up.
if ( flDest ) {
@@ -840,6 +921,16 @@ int sp_common_main( int argc, char const **argv, GSList **flDest )
return 0;
}
+namespace Inkscape {
+namespace UI {
+namespace Tools {
+
+guint get_group0_keyval(GdkEventKey* event);
+
+}
+}
+}
+
static void
snooper(GdkEvent *event, gpointer /*data*/) {
if (inkscape_mapalt()) /* returns the map of the keyboard modifier to map to Alt, zero if no mapping */
@@ -882,7 +973,7 @@ snooper(GdkEvent *event, gpointer /*data*/) {
static gboolean altL_pressed = FALSE;
static gboolean altR_pressed = FALSE;
static gboolean alt_pressed = FALSE;
- guint get_group0_keyval(GdkEventKey* event);
+
guint keyval = 0;
switch (event->type) {
case GDK_MOTION_NOTIFY:
@@ -892,7 +983,7 @@ snooper(GdkEvent *event, gpointer /*data*/) {
alt_pressed = TRUE && (event->button.state & GDK_MOD1_MASK);
break;
case GDK_KEY_PRESS:
- keyval = get_group0_keyval(&event->key);
+ keyval = Inkscape::UI::Tools::get_group0_keyval(&event->key);
if (keyval == GDK_KEY_Alt_L) altL_pressed = TRUE;
if (keyval == GDK_KEY_Alt_R) altR_pressed = TRUE;
alt_pressed = alt_pressed || altL_pressed || altR_pressed;
@@ -903,7 +994,7 @@ snooper(GdkEvent *event, gpointer /*data*/) {
event->key.state &= ~GDK_MOD1_MASK;
break;
case GDK_KEY_RELEASE:
- keyval = get_group0_keyval(&event->key);
+ keyval = Inkscape::UI::Tools::get_group0_keyval(&event->key);
if (keyval == GDK_KEY_Alt_L) altL_pressed = FALSE;
if (keyval == GDK_KEY_Alt_R) altR_pressed = FALSE;
if (!altL_pressed && !altR_pressed)
@@ -994,8 +1085,20 @@ sp_main_gui(int argc, char const **argv)
/**
* Process file list
*/
-void sp_process_file_list(GSList *fl)
+static int sp_process_file_list(GSList *fl)
{
+ int retVal = 0;
+#ifdef WITH_DBUS
+ if (!fl) {
+ // If we've been asked to listen for D-Bus messages, enter a main loop here
+ // The main loop may be exited by calling "exit" on the D-Bus application interface.
+ if (sp_dbus_listen) {
+ Gtk::Main main_dbus_loop(0, NULL);
+ main_dbus_loop.run();
+ }
+ }
+#endif // WITH_DBUS
+
while (fl) {
const gchar *filename = (gchar *)fl->data;
@@ -1019,11 +1122,28 @@ void sp_process_file_list(GSList *fl)
}
if (doc == NULL) {
g_warning("Specified document %s cannot be opened (does not exist or not a valid SVG file)", filename);
+ retVal++;
} else {
+
+ inkscape_add_document(doc);
+
if (sp_vacuum_defs) {
doc->vacuumDocument();
}
- if (sp_vacuum_defs && !sp_export_svg) {
+
+ // Execute command-line actions (selections and verbs) using our local models
+ bool has_performed_actions = Inkscape::CmdLineAction::doList(inkscape_active_action_context());
+
+#ifdef WITH_DBUS
+ // If we've been asked to listen for D-Bus messages, enter a main loop here
+ // The main loop may be exited by calling "exit" on the D-Bus application interface.
+ if (sp_dbus_listen) {
+ Gtk::Main main_dbus_loop(0, NULL);
+ main_dbus_loop.run();
+ }
+#endif // WITH_DBUS
+
+ if (!sp_export_svg && (sp_vacuum_defs || has_performed_actions)) {
// save under the name given in the command line
sp_repr_save_file(doc->rdoc, filename, SP_SVG_NS_URI);
}
@@ -1031,9 +1151,32 @@ void sp_process_file_list(GSList *fl)
sp_print_document_to_file(doc, sp_global_printer);
}
if (sp_export_png || (sp_export_id && sp_export_use_hints)) {
- sp_do_export_png(doc);
+ retVal |= sp_do_export_png(doc);
}
if (sp_export_svg) {
+ if (sp_export_text_to_path) {
+ GSList *items = NULL;
+ SPRoot *root = doc->getRoot();
+ for ( SPObject *iter = root->firstChild(); iter ; iter = iter->getNext()) {
+ SPItem* item = (SPItem*) iter;
+ if (! (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item) || SP_IS_GROUP(item))) {
+ continue;
+ }
+
+ te_update_layout_now_recursive(item);
+ items = g_slist_append(items, item);
+ }
+
+ GSList *selected = NULL;
+ GSList *to_select = NULL;
+
+ sp_item_list_to_curves(items, &selected, &to_select);
+
+ g_slist_free (items);
+ g_slist_free (selected);
+ g_slist_free (to_select);
+ }
+
Inkscape::XML::Document *rdoc;
Inkscape::XML::Node *repr;
rdoc = sp_repr_document_new("svg:svg");
@@ -1043,19 +1186,20 @@ void sp_process_file_list(GSList *fl)
doc->getBase(), sp_export_svg);
}
if (sp_export_ps) {
- do_export_ps_pdf(doc, sp_export_ps, "image/x-postscript");
+ retVal |= do_export_ps_pdf(doc, sp_export_ps, "image/x-postscript");
}
if (sp_export_eps) {
- do_export_ps_pdf(doc, sp_export_eps, "image/x-e-postscript");
+ retVal |= do_export_ps_pdf(doc, sp_export_eps, "image/x-e-postscript");
}
if (sp_export_pdf) {
- do_export_ps_pdf(doc, sp_export_pdf, "application/pdf");
+ retVal |= do_export_ps_pdf(doc, sp_export_pdf, "application/pdf");
}
-#ifdef WIN32
if (sp_export_emf) {
- do_export_emf(doc, sp_export_emf, "image/x-emf");
+ retVal |= do_export_emf(doc, sp_export_emf, "image/x-emf");
+ }
+ if (sp_export_wmf) {
+ retVal |= do_export_wmf(doc, sp_export_wmf, "image/x-wmf");
}
-#endif //WIN32
if (sp_query_all) {
do_query_all (doc);
} else if (sp_query_width || sp_query_height) {
@@ -1064,17 +1208,20 @@ void sp_process_file_list(GSList *fl)
do_query_dimension (doc, false, sp_query_x? Geom::X : Geom::Y, sp_query_id);
}
+ inkscape_remove_document(doc);
+
delete doc;
}
fl = g_slist_remove(fl, fl->data);
}
+ return retVal;
}
/**
* Run the application as an interactive shell, parsing command lines from stdin
* Returns -1 on error.
*/
-int sp_main_shell(char const* command_name)
+static int sp_main_shell(char const* command_name)
{
int retval = 0;
@@ -1123,7 +1270,9 @@ int sp_main_shell(char const* command_name)
poptSetOtherOptionHelp(ctx, _("[OPTIONS...] [FILE...]\n\nAvailable options:"));
if ( ctx ) {
GSList *fl = sp_process_args(ctx);
- sp_process_file_list(fl);
+ if (sp_process_file_list(fl)) {
+ retval = -1;
+ }
poptFreeContext(ctx);
} else {
retval = 1; // not sure why. But this was the previous return value
@@ -1132,6 +1281,7 @@ int sp_main_shell(char const* command_name)
g_strfreev(argv);
} else {
g_warning("Cannot parse commandline: %s", useme);
+ retval = -1;
}
}
}
@@ -1146,12 +1296,15 @@ int sp_main_console(int argc, char const **argv)
{
/* We are started in text mode */
+#if !GLIB_CHECK_VERSION(2,36,0)
/* Do this g_type_init(), so that we can use Xft/Freetype2 (Pango)
* in a non-Gtk environment. Used in libnrtype's
* FontInstance.cpp and FontFactory.cpp.
* http://mail.gnome.org/archives/gtk-list/2003-December/msg00063.html
*/
g_type_init();
+#endif
+
char **argv2 = const_cast<char **>(argv);
gtk_init_check( &argc, &argv2 );
//setlocale(LC_ALL, "");
@@ -1160,7 +1313,11 @@ int sp_main_console(int argc, char const **argv)
int retVal = sp_common_main( argc, argv, &fl );
g_return_val_if_fail(retVal == 0, 1);
- if (fl == NULL && !sp_shell) {
+ if (fl == NULL && !sp_shell
+#ifdef WITH_DBUS
+ && !sp_dbus_listen
+#endif // WITH_DBUS
+ ) {
g_print("Nothing to do!\n");
exit(0);
}
@@ -1168,10 +1325,13 @@ int sp_main_console(int argc, char const **argv)
inkscape_application_init(argv[0], false);
if (sp_shell) {
- sp_main_shell(argv[0]); // Run as interactive shell
- exit(0);
+ int retVal = sp_main_shell(argv[0]); // Run as interactive shell
+ exit((retVal < 0) ? 1 : 0);
} else {
- sp_process_file_list(fl); // Normal command line invokation
+ int retVal = sp_process_file_list(fl); // Normal command line invokation
+ if (retVal){
+ exit(1);
+ }
}
return 0;
@@ -1252,7 +1412,7 @@ do_query_all_recurse (SPObject *o)
}
-static void sp_do_export_png(SPDocument *doc)
+static int sp_do_export_png(SPDocument *doc)
{
Glib::ustring filename;
bool filename_from_hint = false;
@@ -1283,7 +1443,7 @@ static void sp_do_export_png(SPDocument *doc)
if (o) {
if (!SP_IS_ITEM (o)) {
g_warning("Object with id=\"%s\" is not a visible item. Nothing exported.", sp_export_id);
- return;
+ return 1;
}
items = g_slist_prepend (items, SP_ITEM(o));
@@ -1330,11 +1490,11 @@ static void sp_do_export_png(SPDocument *doc)
area = *areaMaybe;
} else {
g_warning("Unable to determine a valid bounding box. Nothing exported.");
- return;
+ return 1;
}
} else {
g_warning("Object with id=\"%s\" was not found in the document. Nothing exported.", sp_export_id);
- return;
+ return 1;
}
}
@@ -1343,7 +1503,7 @@ static void sp_do_export_png(SPDocument *doc)
gdouble x0,y0,x1,y1;
if (sscanf(sp_export_area, "%lg:%lg:%lg:%lg", &x0, &y0, &x1, &y1) != 4) {
g_warning("Cannot parse export area '%s'; use 'x0:y0:x1:y1'. Nothing exported.", sp_export_area);
- return;
+ return 1;
}
area = Geom::Rect(Geom::Interval(x0,x1), Geom::Interval(y0,y1));
} else if (sp_export_area_page || !(sp_export_id || sp_export_area_drawing)) {
@@ -1355,9 +1515,9 @@ static void sp_do_export_png(SPDocument *doc)
// set filename and dpi from options, if not yet set from the hints
if (filename.empty()) {
- if (!sp_export_png) {
+ if (!sp_export_png || sp_export_png[0] == '\0') {
g_warning ("No export filename given and no filename hint. Nothing exported.");
- return;
+ return 1;
}
filename = sp_export_png;
}
@@ -1366,7 +1526,7 @@ static void sp_do_export_png(SPDocument *doc)
dpi = atof(sp_export_dpi);
if ((dpi < 0.1) || (dpi > 10000.0)) {
g_warning("DPI value %s out of range [0.1 - 10000.0]. Nothing exported.", sp_export_dpi);
- return;
+ return 1;
}
g_print("DPI: %g\n", dpi);
}
@@ -1377,7 +1537,7 @@ static void sp_do_export_png(SPDocument *doc)
// default dpi
if (dpi == 0.0) {
- dpi = PX_PER_IN;
+ dpi = Inkscape::Util::Quantity::convert(1, "in", "px");
}
unsigned long int width = 0;
@@ -1388,9 +1548,9 @@ static void sp_do_export_png(SPDocument *doc)
width = strtoul(sp_export_width, NULL, 0);
if ((width < 1) || (width > PNG_UINT_31_MAX) || (errno == ERANGE) ) {
g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX);
- return;
+ return 1;
}
- dpi = (gdouble) width * PX_PER_IN / area.width();
+ dpi = (gdouble) Inkscape::Util::Quantity::convert(width, "in", "px") / area.width();
}
if (sp_export_height) {
@@ -1398,17 +1558,17 @@ static void sp_do_export_png(SPDocument *doc)
height = strtoul(sp_export_height, NULL, 0);
if ((height < 1) || (height > PNG_UINT_31_MAX)) {
g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX);
- return;
+ return 1;
}
- dpi = (gdouble) height * PX_PER_IN / area.height();
+ dpi = (gdouble) Inkscape::Util::Quantity::convert(height, "in", "px") / area.height();
}
if (!sp_export_width) {
- width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5);
+ width = (unsigned long int) (Inkscape::Util::Quantity::convert(area.width(), "px", "in") * dpi + 0.5);
}
if (!sp_export_height) {
- height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5);
+ height = (unsigned long int) (Inkscape::Util::Quantity::convert(area.height(), "px", "in") * dpi + 0.5);
}
guint32 bgcolor = 0x00000000;
@@ -1461,19 +1621,31 @@ static void sp_do_export_png(SPDocument *doc)
path = filename;
}
- g_print("Background RRGGBBAA: %08x\n", bgcolor);
+ int retcode = 0;
+ //check if specified directory exists
- g_print("Area %g:%g:%g:%g exported to %lu x %lu pixels (%g dpi)\n", area[Geom::X][0], area[Geom::Y][0], area[Geom::X][1], area[Geom::Y][1], width, height, dpi);
+ if (!Inkscape::IO::file_directory_exists(filename.c_str())) {
+ g_warning("File path \"%s\" includes directory that doesn't exist.\n", filename.c_str());
+ retcode = 1;
+ } else {
+ g_print("Background RRGGBBAA: %08x\n", bgcolor);
- g_print("Bitmap saved as: %s\n", filename.c_str());
+ g_print("Area %g:%g:%g:%g exported to %lu x %lu pixels (%g dpi)\n", area[Geom::X][0], area[Geom::Y][0], area[Geom::X][1], area[Geom::Y][1], width, height, dpi);
- if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) {
- sp_export_png_file(doc, path.c_str(), area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL);
- } else {
- g_warning("Calculated bitmap dimensions %lu %lu are out of range (1 - %lu). Nothing exported.", width, height, (unsigned long int)PNG_UINT_31_MAX);
+ if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) {
+ if( sp_export_png_file(doc, path.c_str(), area, width, height, dpi,
+ dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL) == 1 ) {
+ g_print("Bitmap saved as: %s\n", filename.c_str());
+ } else {
+ g_warning("Bitmap failed to save to: %s", filename.c_str());
+ }
+ } else {
+ g_warning("Calculated bitmap dimensions %lu %lu are out of range (1 - %lu). Nothing exported.", width, height, (unsigned long int)PNG_UINT_31_MAX);
+ }
}
g_slist_free (items);
+ return retcode;
}
@@ -1485,7 +1657,7 @@ static void sp_do_export_png(SPDocument *doc)
* \param mime MIME type to export as.
*/
-static void do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime)
+static int do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime)
{
Inkscape::Extension::DB::OutputList o;
Inkscape::Extension::db.get_output_list(o);
@@ -1497,14 +1669,14 @@ static void do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime
if (i == o.end())
{
g_warning ("Could not find an extension to export to MIME type %s.", mime);
- return;
+ return 1;
}
if (sp_export_id) {
SPObject *o = doc->getObjectById(sp_export_id);
if (o == NULL) {
g_warning("Object with id=\"%s\" was not found in the document. Nothing exported.", sp_export_id);
- return;
+ return 1;
}
(*i)->set_param_string ("exportId", sp_export_id);
} else {
@@ -1517,25 +1689,21 @@ static void do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime
}
if (sp_export_area_drawing) {
- (*i)->set_param_bool ("areaDrawing", TRUE);
- } else {
- (*i)->set_param_bool ("areaDrawing", FALSE);
+ (*i)->set_param_optiongroup ("area", "drawing");
}
if (sp_export_area_page) {
if (sp_export_eps) {
g_warning ("EPS cannot have its bounding box extend beyond its content, so if your drawing is smaller than the page, --export-area-page will clip it to drawing.");
}
- (*i)->set_param_bool ("areaPage", TRUE);
- } else {
- (*i)->set_param_bool ("areaPage", FALSE);
+ (*i)->set_param_optiongroup ("area", "page");
}
if (!sp_export_area_drawing && !sp_export_area_page && !sp_export_id) {
// neither is set, set page as default for ps/pdf and drawing for eps
if (sp_export_eps) {
try {
- (*i)->set_param_bool("areaDrawing", TRUE);
+ (*i)->set_param_optiongroup("area", "drawing");
} catch (...) {}
}
}
@@ -1569,19 +1737,83 @@ static void do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime
(*i)->set_param_int("resolution", (int) dpi);
}
- (*i)->save(doc, uri);
+ // if no bleed/margin is given, set to 0 (otherwise it takes the value last used from the UI)
+ float margin = 0.;
+ if (sp_export_margin) {
+ margin = g_ascii_strtod(sp_export_margin, NULL);
+ }
+ (*i)->set_param_float("bleed", margin);
+
+ // handle --export-pdf-version
+ if (g_strcmp0(mime, "application/pdf") == 0) {
+ bool set_export_pdf_version_fail=true;
+ const gchar *pdfver_param_name="PDFversion";
+ if(sp_export_pdf_version) {
+ // combine "PDF " and the given command line
+ std::string version_gui_string=std::string("PDF ")+sp_export_pdf_version;
+ try{
+ // first, check if the given pdf version is selectable in the ComboBox
+ if((*i)->get_param_enum_contains("PDFversion", version_gui_string.c_str())) {
+ (*i)->set_param_enum(pdfver_param_name, version_gui_string.c_str());
+ set_export_pdf_version_fail=false;
+ } else {
+ g_warning("Desired PDF export version \"%s\" not supported! Hint: input one of the versions found in the pdf export dialog e.g. \"1.4\".",
+ sp_export_pdf_version);
+ }
+ } catch (...) {
+ // can be thrown along the way:
+ // throw Extension::param_not_exist();
+ // throw Extension::param_not_enum_param();
+ g_warning("Parameter or Enum \"%s\" might not exist",pdfver_param_name);
+ }
+ }
+
+ // set default pdf export version to 1.4, also if something went wrong
+ if(set_export_pdf_version_fail) {
+ (*i)->set_param_enum(pdfver_param_name, "PDF 1.4");
+ }
+ }
+
+ if(!uri || uri[0] == '\0') {
+ g_warning ("No export filename given. Nothing exported.");
+ return 0;
+ }
+
+ //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;
+ }
+
+ if ( g_strcmp0(mime, "image/x-postscript") == 0
+ || g_strcmp0(mime, "image/x-e-postscript") == 0 ) {
+ if ( sp_export_ps_level < 2 || sp_export_ps_level > 3 ) {
+ g_warning("Only supported PostScript levels are 2 and 3."
+ " Defaulting to 2.");
+ sp_export_ps_level = 2;
+ }
+
+ (*i)->set_param_enum("PSlevel", (sp_export_ps_level == 3)
+ ? "PostScript level 3" : "PostScript level 2");
+ }
+
+ try {
+ (*i)->save(doc, uri);
+ } catch(...) {
+ g_warning("Failed to save pdf to: %s", uri);
+ }
+ return 0;
}
-#ifdef WIN32
/**
- * Export a document to EMF
+ * 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")
+ * \param mime MIME type to export as (should be "image/x-emf" or "image/x-wmf")
*/
-static void do_export_emf(SPDocument* doc, gchar const* uri, char const* mime)
+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);
@@ -1593,12 +1825,53 @@ static void do_export_emf(SPDocument* doc, gchar const* uri, char const* mime)
if (i == o.end())
{
g_warning ("Could not find an extension to export to MIME type %s.", mime);
- return;
+ 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;
+}
+
+/**
+ * Export a document to EMF
+ *
+ * \param doc Document to export.
+ * \param uri URI to export to.
+ * \param mime MIME type to export as (should be "image/x-emf")
+ */
+
+static int do_export_emf(SPDocument* doc, gchar const* uri, char const* mime)
+{
+ if(!uri || uri[0] == '\0') {
+ g_warning("No filename provided for emf export.");
+ return 0;
+ }
+ return do_export_win_metafile_common(doc, uri, mime);
+}
+
+/**
+ * Export a document to WMF
+ *
+ * \param doc Document to export.
+ * \param uri URI to export to.
+ * \param mime MIME type to export as (should be "image/x-wmf")
+ */
+
+static int do_export_wmf(SPDocument* doc, gchar const* uri, char const* mime)
+{
+ if(!uri || uri[0] == '\0') {
+ g_warning("No filename provided for wmf export.");
+ return 0;
+ }
+ return do_export_win_metafile_common(doc, uri, mime);
}
-#endif //WIN32
#ifdef WIN32
bool replaceArgs( int& argc, char**& argv )