summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorsu_v <suv-sf@users.sourceforge.net>2012-12-16 05:41:25 +0000
committer~suv <suv-sf@users.sourceforge.net>2012-12-16 05:41:25 +0000
commit7ec903c9898f872dbd9426ed7a62e1969fdb7be7 (patch)
treea306139e829118a83516af02279c9eafd3440eaa /src/main.cpp
parentHershey Text: whitespace; py: docstring, modeline; inx: fix attribute value (diff)
parentTranslations.Spanish translation update by Lucas Vieites. (diff)
downloadinkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.tar.gz
inkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.zip
merge from trunk (r11955)
(bzr r11687.1.3)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp111
1 files changed, 69 insertions, 42 deletions
diff --git a/src/main.cpp b/src/main.cpp
index e3862589d..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);
@@ -390,7 +390,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 +625,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 +733,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 +751,7 @@ void fixupSingleFilename( gchar **orig, gchar **spare )
-GSList *fixupFilenameEncoding( GSList* fl )
+static GSList *fixupFilenameEncoding( GSList* fl )
{
GSList *newFl = NULL;
while ( fl ) {
@@ -788,7 +790,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 +1004,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 +1032,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 +1046,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 +1081,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 +1102,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 +1115,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 +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;
@@ -1323,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));
@@ -1370,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;
}
}
@@ -1383,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)) {
@@ -1397,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;
}
@@ -1406,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);
}
@@ -1428,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();
}
@@ -1438,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();
}
@@ -1501,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
- 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 +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);
@@ -1537,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 {
@@ -1557,25 +1573,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 +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
@@ -1621,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);
@@ -1633,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