summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorsu_v <suv-sf@users.sourceforge.net>2012-12-04 09:51:15 +0000
committer~suv <suv-sf@users.sourceforge.net>2012-12-04 09:51:15 +0000
commit2c6e21d9fd3945a73b3ed5d04a87fb16a90f7a8e (patch)
tree52a0994d8a30aaa8f867073d1cd9ce575f490de8 /src/main.cpp
parentchanges_2012-11_28.patch (diff)
parentwix installer: create msi filename from version sing in src/inkscape.rc, add ... (diff)
downloadinkscape-2c6e21d9fd3945a73b3ed5d04a87fb16a90f7a8e.tar.gz
inkscape-2c6e21d9fd3945a73b3ed5d04a87fb16a90f7a8e.zip
merge from trunk (r11929)
[win32] Please update to latest devlibs for Windows (r41) (bzr r11668.1.44)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp87
1 files changed, 58 insertions, 29 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 844aded56..20330edbb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -169,10 +169,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);
@@ -1032,6 +1032,9 @@ static 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();
}
@@ -1043,7 +1046,7 @@ static 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) {
@@ -1078,17 +1081,17 @@ static 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) {
@@ -1099,6 +1102,8 @@ static 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);
@@ -1294,7 +1299,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;
@@ -1325,7 +1330,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));
@@ -1372,11 +1377,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;
}
}
@@ -1385,7 +1390,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)) {
@@ -1399,7 +1404,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;
}
@@ -1408,7 +1413,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);
}
@@ -1430,7 +1435,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();
}
@@ -1440,7 +1445,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();
}
@@ -1503,19 +1508,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
+
+ 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("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);
+ 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);
- g_print("Bitmap saved as: %s\n", filename.c_str());
+ 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);
+ 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;
}
@@ -1527,7 +1541,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);
@@ -1539,14 +1553,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 {
@@ -1607,7 +1621,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
@@ -1619,7 +1640,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);
@@ -1631,10 +1652,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