diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
| commit | a168040d5a452544328a1e6ad35aaac351f94d44 (patch) | |
| tree | fae1ba829f543a473da281bd5fa6e4deabbf6912 /src/main.cpp | |
| parent | Removed function pointers from SPObject and subclasses. (diff) | |
| parent | Dutch translation update (diff) | |
| download | inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip | |
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 115 |
1 files changed, 72 insertions, 43 deletions
diff --git a/src/main.cpp b/src/main.cpp index e3862589d..58ab19616 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,7 +47,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> @@ -103,6 +102,9 @@ #include "extension/init.h" #include <glibmm/i18n.h> +#include <glibmm/main.h> +#include <glibmm/miscutils.h> + #include <gtkmm/main.h> #ifndef HAVE_BIND_TEXTDOMAIN_CODESET @@ -169,10 +171,10 @@ 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); +static int sp_do_export_png(SPDocument *doc); +static int 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); +static int do_export_emf(SPDocument* doc, gchar const* uri, char const *mime); #endif //WIN32 static void do_query_dimension (SPDocument *doc, bool extent, Geom::Dim2 const axis, const gchar *id); static void do_query_all (SPDocument *doc); @@ -390,7 +392,7 @@ struct poptOption options[] = { {"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, @@ -625,6 +627,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 @@ -731,7 +735,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; @@ -749,7 +753,7 @@ void fixupSingleFilename( gchar **orig, gchar **spare ) -GSList *fixupFilenameEncoding( GSList* fl ) +static GSList *fixupFilenameEncoding( GSList* fl ) { GSList *newFl = NULL; while ( fl ) { @@ -788,7 +792,7 @@ 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); @@ -1002,7 +1006,7 @@ sp_main_gui(int argc, char const **argv) /** * Process file list */ -int sp_process_file_list(GSList *fl) +static int sp_process_file_list(GSList *fl) { int retVal = 0; while (fl) { @@ -1030,6 +1034,9 @@ int sp_process_file_list(GSList *fl) 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(); } @@ -1041,7 +1048,7 @@ int 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) { @@ -1076,17 +1083,17 @@ int 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"); } #endif //WIN32 if (sp_query_all) { @@ -1097,6 +1104,8 @@ int 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); @@ -1108,7 +1117,7 @@ int sp_process_file_list(GSList *fl) * 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; @@ -1292,7 +1301,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; @@ -1323,7 +1332,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)); @@ -1370,11 +1379,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; } } @@ -1383,7 +1392,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)) { @@ -1397,7 +1406,7 @@ static void sp_do_export_png(SPDocument *doc) if (filename.empty()) { if (!sp_export_png) { g_warning ("No export filename given and no filename hint. Nothing exported."); - return; + return 1; } filename = sp_export_png; } @@ -1406,7 +1415,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); } @@ -1428,7 +1437,7 @@ 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(); } @@ -1438,7 +1447,7 @@ 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(); } @@ -1501,19 +1510,28 @@ 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); + g_print("Bitmap saved as: %s\n", filename.c_str()); + + 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); + } } g_slist_free (items); + return retcode; } @@ -1525,7 +1543,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); @@ -1537,14 +1555,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 { @@ -1557,25 +1575,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 (...) {} } } @@ -1609,7 +1623,14 @@ static void do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime (*i)->set_param_int("resolution", (int) dpi); } + //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; } #ifdef WIN32 @@ -1621,7 +1642,7 @@ static void do_export_ps_pdf(SPDocument* doc, gchar const* uri, char const* mime * \param mime MIME type to export as (should be "image/x-emf") */ -static void do_export_emf(SPDocument* doc, gchar const* uri, char const* mime) +static int do_export_emf(SPDocument* doc, gchar const* uri, char const* mime) { Inkscape::Extension::DB::OutputList o; Inkscape::Extension::db.get_output_list(o); @@ -1633,10 +1654,18 @@ 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; } #endif //WIN32 |
