diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dialogs/export.cpp | 28 | ||||
| -rw-r--r-- | src/helper/png-write.cpp | 21 | ||||
| -rw-r--r-- | src/main.cpp | 58 |
3 files changed, 72 insertions, 35 deletions
diff --git a/src/dialogs/export.cpp b/src/dialogs/export.cpp index ee7852924..2e41850ed 100644 --- a/src/dialogs/export.cpp +++ b/src/dialogs/export.cpp @@ -1067,6 +1067,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) if (!SP_ACTIVE_DESKTOP) return; SPNamedView *nv = sp_desktop_namedview(SP_ACTIVE_DESKTOP); + SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP); GtkWidget *be = (GtkWidget *)gtk_object_get_data(base, "batch_checkbox"); GtkWidget *he = (GtkWidget *)gtk_object_get_data(base, "hide_checkbox"); @@ -1088,10 +1089,24 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) i != NULL; i = i->next) { SPItem *item = (SPItem *) i->data; + // retrieve export filename hint - const gchar *fn = SP_OBJECT_REPR(item)->attribute("inkscape:export-filename"); - if (!fn) { - fn = create_filepath_from_id (SP_OBJECT_ID(item), NULL); + const gchar *filename = SP_OBJECT_REPR(item)->attribute("inkscape:export-filename"); + gchar *path = 0; + if (!filename) { + path = create_filepath_from_id (SP_OBJECT_ID(item), NULL); + } else { + //Make relative paths go from the document location, if possible: + if (!g_path_is_absolute(filename) && doc->uri) { + gchar *dirname = g_path_get_dirname(doc->uri); + if (dirname) { + path = g_build_filename(dirname, filename, NULL); + g_free(dirname); + } + } + if (!path) { + path = g_strdup(filename); + } } // retrieve export dpi hints @@ -1112,14 +1127,14 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) if (width > 1 && height > 1) { /* Do export */ - if (!sp_export_png_file (sp_desktop_document (SP_ACTIVE_DESKTOP), fn, + if (!sp_export_png_file (doc, path, *area, width, height, dpi, dpi, nv->pagecolor, NULL, NULL, TRUE, // overwrite without asking hide ? (GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList() : NULL )) { gchar * error; - gchar * safeFile = Inkscape::IO::sanitizeString(fn); + gchar * safeFile = Inkscape::IO::sanitizeString(path); error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); sp_ui_error_dialog(error); g_free(safeFile); @@ -1128,6 +1143,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) } } n++; + g_free(path); sp_export_progress_callback((float)n/num, base); } @@ -1178,9 +1194,9 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) gtk_entry_set_text(GTK_ENTRY(fe), filename_ext); gchar *fn = g_path_get_basename (filename_ext); - gchar *progress_text = g_strdup_printf (_("Exporting %s (%lu x %lu)"), fn, width, height); g_free (fn); + GtkWidget *prog_dlg = create_progress_dialog (base, progress_text); g_free (progress_text); diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 3ac900680..b1c135db0 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -414,20 +414,7 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, g_return_val_if_fail(height >= 1, false); g_return_val_if_fail(!area.hasZeroArea(), false); - //Make relative paths absolute, if possible: - gchar *path = 0; - if (!g_path_is_absolute(filename) && doc->uri) { - gchar *dirname = g_path_get_dirname(doc->uri); - if (dirname) { - path = g_build_filename(dirname, filename, NULL); - g_free(dirname); - } - } - if (!path) { - path = g_strdup(filename); - } - - if (!force_overwrite && !sp_ui_overwrite_file(path)) { + if (!force_overwrite && !sp_ui_overwrite_file(filename)) { /* Remark: We return true so as not to invoke an error dialog in case export is cancelled by the user; currently this is safe because the callers only act when false is returned. If this changes in the future we need better distinction of return types (e.g., use int) @@ -493,12 +480,12 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, if ((width < 256) || ((width * height) < 32768)) { ebp.px = nr_pixelstore_64K_new(FALSE, 0); ebp.sheight = 65536 / (4 * width); - write_status = sp_png_write_rgba_striped(doc, path, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); + write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); nr_pixelstore_64K_free(ebp.px); } else { ebp.sheight = 64; ebp.px = g_try_new(guchar, 4 * ebp.sheight * width); - write_status = sp_png_write_rgba_striped(doc, path, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); + write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); g_free(ebp.px); } @@ -508,8 +495,6 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, /* Free arena */ nr_object_unref((NRObject *) arena); - g_free(path); - return write_status; } diff --git a/src/main.cpp b/src/main.cpp index 12732ef2c..f96d99e11 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,6 +91,7 @@ #include <extension/system.h> #include <extension/db.h> #include <extension/output.h> +#include <extension/input.h> #ifdef WIN32 //#define REPLACEARGS_ANSI @@ -628,13 +629,13 @@ main(int argc, char **argv) || !strcmp(argv[i], "-e") || !strncmp(argv[i], "--export-png", 12) || !strcmp(argv[i], "-l") - || !strncmp(argv[i], "--export-plain-svg", 12) + || !strncmp(argv[i], "--export-plain-svg", 18) || !strcmp(argv[i], "-i") || !strncmp(argv[i], "--export-area-drawing", 21) || !strcmp(argv[i], "-D") - || !strncmp(argv[i], "--export-area-page", 20) + || !strncmp(argv[i], "--export-area-page", 18) || !strcmp(argv[i], "-C") - || !strncmp(argv[i], "--export-id", 12) + || !strncmp(argv[i], "--export-id", 11) || !strcmp(argv[i], "-P") || !strncmp(argv[i], "--export-ps", 11) || !strcmp(argv[i], "-E") @@ -652,11 +653,11 @@ main(int argc, char **argv) || !strcmp(argv[i], "-S") || !strncmp(argv[i], "--query-all", 11) || !strcmp(argv[i], "-X") - || !strncmp(argv[i], "--query-x", 13) + || !strncmp(argv[i], "--query-x", 9) || !strcmp(argv[i], "-Y") - || !strncmp(argv[i], "--query-y", 14) + || !strncmp(argv[i], "--query-y", 9) || !strcmp(argv[i], "--vacuum-defs") - || !strncmp(argv[i], "--shell", 7) + || !strcmp(argv[i], "--shell") ) { /* main_console handles any exports -- not the gui */ @@ -962,12 +963,27 @@ void sp_process_file_list(GSList *fl) { while (fl) { const gchar *filename = (gchar *)fl->data; - SPDocument *doc = Inkscape::Extension::open(NULL, filename); + + SPDocument *doc = NULL; + try { + doc = Inkscape::Extension::open(NULL, filename); + } catch (Inkscape::Extension::Input::no_extension_found &e) { + doc = NULL; + } catch (Inkscape::Extension::Input::open_failed &e) { + doc = NULL; + } + if (doc == NULL) { - doc = Inkscape::Extension::open(Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), filename); + try { + doc = Inkscape::Extension::open(Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), filename); + } catch (Inkscape::Extension::Input::no_extension_found &e) { + doc = NULL; + } catch (Inkscape::Extension::Input::open_failed &e) { + doc = NULL; + } } if (doc == NULL) { - g_warning("Specified document %s cannot be opened (is it a valid SVG file?)", filename); + g_warning("Specified document %s cannot be opened (does not exist or not a valid SVG file)", filename); } else { if (sp_vacuum_defs) { vacuum_document(doc); @@ -979,7 +995,7 @@ void sp_process_file_list(GSList *fl) if (sp_global_printer) { sp_print_document_to_file(doc, sp_global_printer); } - if (sp_export_png) { + if (sp_export_png || (sp_export_id && sp_export_use_hints)) { sp_do_export_png(doc); } if (sp_export_svg) { @@ -1208,6 +1224,7 @@ static void sp_do_export_png(SPDocument *doc) { const gchar *filename = NULL; + bool filename_from_hint = false; gdouble dpi = 0.0; if (sp_export_use_hints && (!sp_export_id && !sp_export_area_drawing)) { @@ -1254,6 +1271,7 @@ sp_do_export_png(SPDocument *doc) filename = sp_export_png; } else { filename = fn_hint; + filename_from_hint = true; } } else { g_warning ("Export filename hint not found for the object."); @@ -1393,6 +1411,23 @@ sp_do_export_png(SPDocument *doc) } } + gchar *path = 0; + if (filename_from_hint) { + //Make relative paths go from the document location, if possible: + if (!g_path_is_absolute(filename) && doc->uri) { + gchar *dirname = g_path_get_dirname(doc->uri); + if (dirname) { + path = g_build_filename(dirname, filename, NULL); + g_free(dirname); + } + } + if (!path) { + path = g_strdup(filename); + } + } else { + path = g_strdup(filename); + } + g_print("Background RRGGBBAA: %08x\n", bgcolor); 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); @@ -1400,11 +1435,12 @@ sp_do_export_png(SPDocument *doc) g_print("Bitmap saved as: %s\n", filename); if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) { - sp_export_png_file(doc, filename, area, width, height, dpi, dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL); + sp_export_png_file(doc, path, 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_free (path); g_slist_free (items); } |
