1 #define __MAIN_C__
3 /** \file
4 * Inkscape - an ambitious vector drawing program
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Frank Felfe <innerspace@iname.com>
9 * Davide Puricelli <evo@debian.org>
10 * Mitsuru Oka <oka326@parkcity.ne.jp>
11 * Masatake YAMATO <jet@gyve.org>
12 * F.J.Franklin <F.J.Franklin@sheffield.ac.uk>
13 * Michael Meeks <michael@helixcode.com>
14 * Chema Celorio <chema@celorio.com>
15 * Pawel Palucha
16 * Bryce Harrington <bryce@bryceharrington.com>
17 * ... and various people who have worked with various projects
18 *
19 * Copyright (C) 1999-2004 authors
20 * Copyright (C) 2001-2002 Ximian, Inc.
21 *
22 * Released under GNU GPL, read the file 'COPYING' for more information
23 */
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29 #include "path-prefix.h"
31 #include <gtk/gtkmessagedialog.h>
33 #ifdef HAVE_IEEEFP_H
34 #include <ieeefp.h>
35 #endif
36 #include <string.h>
37 #include <locale.h>
39 #include <popt.h>
40 #ifndef POPT_TABLEEND
41 #define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL }
42 #endif /* Not def: POPT_TABLEEND */
44 #include <libxml/tree.h>
45 #include <glib-object.h>
46 #include <gtk/gtkmain.h>
47 #include <gtk/gtksignal.h>
48 #include <gtk/gtkwindow.h>
49 #include <gtk/gtkbox.h>
51 #include "gc-core.h"
53 #include "macros.h"
54 #include "file.h"
55 #include "document.h"
56 #include "sp-object.h"
57 #include "interface.h"
58 #include "print.h"
59 #include "color.h"
60 #include "sp-item.h"
61 #include "sp-root.h"
62 #include "unit-constants.h"
64 #include "svg/svg.h"
65 #include "svg/svg-color.h"
66 #include "svg/stringstream.h"
68 #include "inkscape-private.h"
69 #include "inkscape-stock.h"
70 #include "inkscape_version.h"
72 #include "sp-namedview.h"
73 #include "sp-guide.h"
74 #include "sp-object-repr.h"
75 #include "xml/repr.h"
77 #include "io/sys.h"
79 #include "debug/logger.h"
80 #include "debug/log-display-config.h"
82 #include "helper/png-write.h"
84 #include <extension/extension.h>
85 #include <extension/system.h>
86 #include <extension/db.h>
87 #include <extension/output.h>
89 #ifdef WIN32
90 //#define REPLACEARGS_ANSI
91 //#define REPLACEARGS_DEBUG
93 #include "registrytool.h"
95 #include "extension/internal/win32.h"
96 using Inkscape::Extension::Internal::PrintWin32;
98 #endif // WIN32
100 #include "extension/init.h"
102 #include <glibmm/i18n.h>
103 #include <gtkmm/main.h>
105 #ifndef HAVE_BIND_TEXTDOMAIN_CODESET
106 #define bind_textdomain_codeset(p,c)
107 #endif
109 #include "application/application.h"
111 #include "main-cmdlineact.h"
113 enum {
114 SP_ARG_NONE,
115 SP_ARG_NOGUI,
116 SP_ARG_GUI,
117 SP_ARG_FILE,
118 SP_ARG_PRINT,
119 SP_ARG_EXPORT_PNG,
120 SP_ARG_EXPORT_DPI,
121 SP_ARG_EXPORT_AREA,
122 SP_ARG_EXPORT_AREA_DRAWING,
123 SP_ARG_EXPORT_AREA_CANVAS,
124 SP_ARG_EXPORT_AREA_SNAP,
125 SP_ARG_EXPORT_WIDTH,
126 SP_ARG_EXPORT_HEIGHT,
127 SP_ARG_EXPORT_ID,
128 SP_ARG_EXPORT_ID_ONLY,
129 SP_ARG_EXPORT_USE_HINTS,
130 SP_ARG_EXPORT_BACKGROUND,
131 SP_ARG_EXPORT_BACKGROUND_OPACITY,
132 SP_ARG_EXPORT_SVG,
133 SP_ARG_EXPORT_PS,
134 SP_ARG_EXPORT_EPS,
135 SP_ARG_EXPORT_PDF,
136 SP_ARG_EXPORT_TEXT_TO_PATH,
137 SP_ARG_EXPORT_FONT,
138 SP_ARG_EXPORT_BBOX_PAGE,
139 SP_ARG_EXTENSIONDIR,
140 SP_ARG_FIT_PAGE_TO_DRAWING,
141 SP_ARG_QUERY_X,
142 SP_ARG_QUERY_Y,
143 SP_ARG_QUERY_WIDTH,
144 SP_ARG_QUERY_HEIGHT,
145 SP_ARG_QUERY_ID,
146 SP_ARG_VERSION,
147 SP_ARG_VACUUM_DEFS,
148 SP_ARG_VERB_LIST,
149 SP_ARG_VERB,
150 SP_ARG_SELECT,
151 SP_ARG_LAST
152 };
154 int sp_main_gui(int argc, char const **argv);
155 int sp_main_console(int argc, char const **argv);
156 static void sp_do_export_png(SPDocument *doc);
157 static void do_export_ps(SPDocument* doc, gchar const* uri, char const *mime);
158 static void do_export_pdf(SPDocument* doc, gchar const* uri, char const *mime);
159 static void do_query_dimension (SPDocument *doc, bool extent, NR::Dim2 const axis, const gchar *id);
162 static gchar *sp_global_printer = NULL;
163 static gchar *sp_export_png = NULL;
164 static gchar *sp_export_dpi = NULL;
165 static gchar *sp_export_area = NULL;
166 static gboolean sp_export_area_drawing = FALSE;
167 static gboolean sp_export_area_canvas = FALSE;
168 static gchar *sp_export_width = NULL;
169 static gchar *sp_export_height = NULL;
170 static gchar *sp_export_id = NULL;
171 static gchar *sp_export_background = NULL;
172 static gchar *sp_export_background_opacity = NULL;
173 static gboolean sp_export_area_snap = FALSE;
174 static gboolean sp_export_use_hints = FALSE;
175 static gboolean sp_export_id_only = FALSE;
176 static gchar *sp_export_svg = NULL;
177 static gchar *sp_export_ps = NULL;
178 static gchar *sp_export_eps = NULL;
179 static gchar *sp_export_pdf = NULL;
180 static gboolean sp_export_text_to_path = FALSE;
181 static gboolean sp_export_font = FALSE;
182 static gboolean sp_export_bbox_page = FALSE;
183 static gboolean sp_query_x = FALSE;
184 static gboolean sp_query_y = FALSE;
185 static gboolean sp_query_width = FALSE;
186 static gboolean sp_query_height = FALSE;
187 static gchar *sp_query_id = NULL;
188 static int sp_new_gui = FALSE;
189 static gboolean sp_vacuum_defs = FALSE;
191 static gchar *sp_export_png_utf8 = NULL;
192 static gchar *sp_export_svg_utf8 = NULL;
193 static gchar *sp_global_printer_utf8 = NULL;
195 #ifdef WIN32
196 static bool replaceArgs( int& argc, char**& argv );
197 #endif
198 static GSList *sp_process_args(poptContext ctx);
199 struct poptOption options[] = {
200 {"version", 'V',
201 POPT_ARG_NONE, NULL, SP_ARG_VERSION,
202 N_("Print the Inkscape version number"),
203 NULL},
205 {"without-gui", 'z',
206 POPT_ARG_NONE, NULL, SP_ARG_NOGUI,
207 N_("Do not use X server (only process files from console)"),
208 NULL},
210 {"with-gui", 'g',
211 POPT_ARG_NONE, NULL, SP_ARG_GUI,
212 N_("Try to use X server (even if $DISPLAY is not set)"),
213 NULL},
215 {"file", 'f',
216 POPT_ARG_STRING, NULL, SP_ARG_FILE,
217 N_("Open specified document(s) (option string may be excluded)"),
218 N_("FILENAME")},
220 {"print", 'p',
221 POPT_ARG_STRING, &sp_global_printer, SP_ARG_PRINT,
222 N_("Print document(s) to specified output file (use '| program' for pipe)"),
223 N_("FILENAME")},
225 {"export-png", 'e',
226 POPT_ARG_STRING, &sp_export_png, SP_ARG_EXPORT_PNG,
227 N_("Export document to a PNG file"),
228 N_("FILENAME")},
230 {"export-dpi", 'd',
231 POPT_ARG_STRING, &sp_export_dpi, SP_ARG_EXPORT_DPI,
232 N_("The resolution used for exporting SVG into bitmap (default 90)"),
233 N_("DPI")},
235 {"export-area", 'a',
236 POPT_ARG_STRING, &sp_export_area, SP_ARG_EXPORT_AREA,
237 N_("Exported area in SVG user units (default is the canvas; 0,0 is lower-left corner)"),
238 N_("x0:y0:x1:y1")},
240 {"export-area-drawing", 'D',
241 POPT_ARG_NONE, &sp_export_area_drawing, SP_ARG_EXPORT_AREA_DRAWING,
242 N_("Exported area is the entire drawing (not canvas)"),
243 NULL},
245 {"export-area-canvas", 'C',
246 POPT_ARG_NONE, &sp_export_area_canvas, SP_ARG_EXPORT_AREA_CANVAS,
247 N_("Exported area is the entire canvas"),
248 NULL},
250 {"export-area-snap", 0,
251 POPT_ARG_NONE, &sp_export_area_snap, SP_ARG_EXPORT_AREA_SNAP,
252 N_("Snap the bitmap export area outwards to the nearest integer values (in SVG user units)"),
253 NULL},
255 {"export-width", 'w',
256 POPT_ARG_STRING, &sp_export_width, SP_ARG_EXPORT_WIDTH,
257 N_("The width of exported bitmap in pixels (overrides export-dpi)"),
258 N_("WIDTH")},
260 {"export-height", 'h',
261 POPT_ARG_STRING, &sp_export_height, SP_ARG_EXPORT_HEIGHT,
262 N_("The height of exported bitmap in pixels (overrides export-dpi)"),
263 N_("HEIGHT")},
265 {"export-id", 'i',
266 POPT_ARG_STRING, &sp_export_id, SP_ARG_EXPORT_ID,
267 N_("The ID of the object to export"),
268 N_("ID")},
270 {"export-id-only", 'j',
271 POPT_ARG_NONE, &sp_export_id_only, SP_ARG_EXPORT_ID_ONLY,
272 // TRANSLATORS: this means: "Only export the object whose id is given in --export-id".
273 // See "man inkscape" for details.
274 N_("Export just the object with export-id, hide all others (only with export-id)"),
275 NULL},
277 {"export-use-hints", 't',
278 POPT_ARG_NONE, &sp_export_use_hints, SP_ARG_EXPORT_USE_HINTS,
279 N_("Use stored filename and DPI hints when exporting (only with export-id)"),
280 NULL},
282 {"export-background", 'b',
283 POPT_ARG_STRING, &sp_export_background, SP_ARG_EXPORT_BACKGROUND,
284 N_("Background color of exported bitmap (any SVG-supported color string)"),
285 N_("COLOR")},
287 {"export-background-opacity", 'y',
288 POPT_ARG_STRING, &sp_export_background_opacity, SP_ARG_EXPORT_BACKGROUND_OPACITY,
289 N_("Background opacity of exported bitmap (either 0.0 to 1.0, or 1 to 255)"),
290 N_("VALUE")},
292 {"export-plain-svg", 'l',
293 POPT_ARG_STRING, &sp_export_svg, SP_ARG_EXPORT_SVG,
294 N_("Export document to plain SVG file (no sodipodi or inkscape namespaces)"),
295 N_("FILENAME")},
297 {"export-ps", 'P',
298 POPT_ARG_STRING, &sp_export_ps, SP_ARG_EXPORT_PS,
299 N_("Export document to a PS file"),
300 N_("FILENAME")},
302 {"export-eps", 'E',
303 POPT_ARG_STRING, &sp_export_eps, SP_ARG_EXPORT_EPS,
304 N_("Export document to an EPS file"),
305 N_("FILENAME")},
307 {"export-pdf", 'A',
308 POPT_ARG_STRING, &sp_export_pdf, SP_ARG_EXPORT_PDF,
309 N_("Export document to a PDF file"),
310 N_("FILENAME")},
312 {"export-text-to-path", 'T',
313 POPT_ARG_NONE, &sp_export_text_to_path, SP_ARG_EXPORT_TEXT_TO_PATH,
314 N_("Convert text object to paths on export (EPS)"),
315 NULL},
317 {"export-embed-fonts", 'F',
318 POPT_ARG_NONE, &sp_export_font, SP_ARG_EXPORT_FONT,
319 N_("Embed fonts on export (Type 1 only) (EPS)"),
320 NULL},
322 {"export-bbox-page", 'B',
323 POPT_ARG_NONE, &sp_export_bbox_page, SP_ARG_EXPORT_BBOX_PAGE,
324 N_("Export files with the bounding box set to the page size (EPS)"),
325 NULL},
327 {"query-x", 'X',
328 POPT_ARG_NONE, &sp_query_x, SP_ARG_QUERY_X,
329 // TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
330 N_("Query the X coordinate of the drawing or, if specified, of the object with --query-id"),
331 NULL},
333 {"query-y", 'Y',
334 POPT_ARG_NONE, &sp_query_y, SP_ARG_QUERY_Y,
335 // TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
336 N_("Query the Y coordinate of the drawing or, if specified, of the object with --query-id"),
337 NULL},
339 {"query-width", 'W',
340 POPT_ARG_NONE, &sp_query_width, SP_ARG_QUERY_WIDTH,
341 // TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
342 N_("Query the width of the drawing or, if specified, of the object with --query-id"),
343 NULL},
345 {"query-height", 'H',
346 POPT_ARG_NONE, &sp_query_height, SP_ARG_QUERY_HEIGHT,
347 // TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
348 N_("Query the height of the drawing or, if specified, of the object with --query-id"),
349 NULL},
351 {"query-id", 'I',
352 POPT_ARG_STRING, &sp_query_id, SP_ARG_QUERY_ID,
353 N_("The ID of the object whose dimensions are queried"),
354 N_("ID")},
356 {"extension-directory", 'x',
357 POPT_ARG_NONE, NULL, SP_ARG_EXTENSIONDIR,
358 // TRANSLATORS: this option makes Inkscape print the name (path) of the extension directory
359 N_("Print out the extension directory and exit"),
360 NULL},
362 {"vacuum-defs", 0,
363 POPT_ARG_NONE, &sp_vacuum_defs, SP_ARG_VACUUM_DEFS,
364 N_("Remove unused definitions from the defs section(s) of the document"),
365 NULL},
367 {"verb-list", 0,
368 POPT_ARG_NONE, NULL, SP_ARG_VERB_LIST,
369 N_("List the IDs of all the verbs in Inkscape"),
370 NULL},
372 {"verb", 0,
373 POPT_ARG_STRING, NULL, SP_ARG_VERB,
374 N_("Verb to call when Inkscape opens."),
375 N_("VERB-ID")},
377 {"select", 0,
378 POPT_ARG_STRING, NULL, SP_ARG_SELECT,
379 N_("Object ID to select when Inkscape opens."),
380 N_("OBJECT-ID")},
382 POPT_AUTOHELP POPT_TABLEEND
383 };
385 static bool needToRecodeParams = true;
386 gchar* blankParam = "";
388 int
389 main(int argc, char **argv)
390 {
391 #ifdef HAVE_FPSETMASK
392 /* This is inherited from Sodipodi code, where it was in #ifdef __FreeBSD__. It's probably
393 safe to remove: the default mask is already 0 in C99, and in current FreeBSD according to
394 the fenv man page on www.freebsd.org, and in glibc according to (libc)FP Exceptions. */
395 fpsetmask(fpgetmask() & ~(FP_X_DZ | FP_X_INV));
396 #endif
398 #ifdef ENABLE_NLS
399 #ifdef WIN32
400 RegistryTool rt;
401 rt.setPathInfo();
402 gchar *pathBuf = g_strconcat(g_path_get_dirname(argv[0]), "\\", PACKAGE_LOCALE_DIR, NULL);
403 bindtextdomain(GETTEXT_PACKAGE, pathBuf);
404 g_free(pathBuf);
405 #else
406 #ifdef ENABLE_BINRELOC
407 bindtextdomain(GETTEXT_PACKAGE, BR_LOCALEDIR(""));
408 #else
409 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
410 #endif
411 #endif
412 // Allow the user to override the locale directory by setting
413 // the environment variable INKSCAPE_LOCALEDIR.
414 char *inkscape_localedir = getenv("INKSCAPE_LOCALEDIR");
415 if (inkscape_localedir != NULL) {
416 bindtextdomain(GETTEXT_PACKAGE, inkscape_localedir);
417 }
418 #endif
420 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
422 #ifdef ENABLE_NLS
423 textdomain(GETTEXT_PACKAGE);
424 #endif
426 LIBXML_TEST_VERSION
428 Inkscape::GC::init();
430 Inkscape::Debug::Logger::init();
432 gboolean use_gui;
433 #ifndef WIN32
434 use_gui = (getenv("DISPLAY") != NULL);
435 #else
436 /*
437 Set the current directory to the directory of the
438 executable. This seems redundant, but is needed for
439 when inkscape.exe is executed from another directory.
440 We use relative paths on win32.
441 HKCR\svgfile\shell\open\command is a good example
442 */
443 /// \todo FIXME BROKEN - non-UTF-8 sneaks in here.
444 char *homedir = g_path_get_dirname(argv[0]);
445 SetCurrentDirectory(homedir);
446 g_free(homedir);
448 use_gui = TRUE;
449 #endif
450 /* Test whether with/without GUI is forced */
451 for (int i = 1; i < argc; i++) {
452 if (!strcmp(argv[i], "-z")
453 || !strcmp(argv[i], "--without-gui")
454 || !strcmp(argv[i], "-p")
455 || !strncmp(argv[i], "--print", 7)
456 || !strcmp(argv[i], "-e")
457 || !strncmp(argv[i], "--export-png", 12)
458 || !strcmp(argv[i], "-l")
459 || !strncmp(argv[i], "--export-plain-svg", 12)
460 || !strcmp(argv[i], "-i")
461 || !strncmp(argv[i], "--export-area-drawing", 21)
462 || !strcmp(argv[i], "-D")
463 || !strncmp(argv[i], "--export-area-canvas", 20)
464 || !strcmp(argv[i], "-C")
465 || !strncmp(argv[i], "--export-id", 12)
466 || !strcmp(argv[i], "-P")
467 || !strncmp(argv[i], "--export-ps", 11)
468 || !strcmp(argv[i], "-E")
469 || !strncmp(argv[i], "--export-eps", 12)
470 || !strcmp(argv[i], "-A")
471 || !strncmp(argv[i], "--export-pdf", 12)
472 || !strcmp(argv[i], "-W")
473 || !strncmp(argv[i], "--query-width", 13)
474 || !strcmp(argv[i], "-H")
475 || !strncmp(argv[i], "--query-height", 14)
476 || !strcmp(argv[i], "-X")
477 || !strncmp(argv[i], "--query-x", 13)
478 || !strcmp(argv[i], "-Y")
479 || !strncmp(argv[i], "--query-y", 14)
480 || !strcmp(argv[i], "--vacuum-defs")
481 )
482 {
483 /* main_console handles any exports -- not the gui */
484 use_gui = FALSE;
485 break;
486 } else if (!strcmp(argv[i], "-g") || !strcmp(argv[i], "--with-gui")) {
487 use_gui = TRUE;
488 break;
489 }
490 }
492 #ifdef WIN32
493 #ifndef REPLACEARGS_ANSI
494 if ( PrintWin32::is_os_wide() )
495 #endif // REPLACEARGS_ANSI
496 {
497 // If the call fails, we'll need to convert charsets
498 needToRecodeParams = !replaceArgs( argc, argv );
499 }
500 #endif // WIN32
502 /// \todo Should this be a static object (see inkscape.cpp)?
503 Inkscape::NSApplication::Application app(argc, argv, use_gui, sp_new_gui);
505 return app.run();
506 }
508 void fixupSingleFilename( gchar **orig, gchar **spare )
509 {
510 if ( orig && *orig && **orig ) {
511 GError *error = NULL;
512 gchar *newFileName = Inkscape::IO::locale_to_utf8_fallback(*orig, -1, NULL, NULL, &error);
513 if ( newFileName )
514 {
515 *orig = newFileName;
516 if ( spare ) {
517 *spare = newFileName;
518 }
519 // g_message("Set a replacement fixup");
520 }
521 }
522 }
524 GSList *fixupFilenameEncoding( GSList* fl )
525 {
526 GSList *newFl = NULL;
527 while ( fl ) {
528 gchar *fn = static_cast<gchar*>(fl->data);
529 fl = g_slist_remove( fl, fl->data );
530 gchar *newFileName = Inkscape::IO::locale_to_utf8_fallback(fn, -1, NULL, NULL, NULL);
531 if ( newFileName ) {
533 if ( 0 )
534 {
535 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
536 gchar *safeNewFn = Inkscape::IO::sanitizeString(newFileName);
537 GtkWidget *w = gtk_message_dialog_new( NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
538 "Note: Converted '%s' to '%s'", safeFn, safeNewFn );
539 gtk_dialog_run (GTK_DIALOG (w));
540 gtk_widget_destroy (w);
541 g_free(safeNewFn);
542 g_free(safeFn);
543 }
545 g_free( fn );
546 fn = newFileName;
547 newFileName = 0;
548 }
549 else
550 if ( 0 )
551 {
552 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
553 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Error: Unable to convert '%s'", safeFn );
554 gtk_dialog_run (GTK_DIALOG (w));
555 gtk_widget_destroy (w);
556 g_free(safeFn);
557 }
558 newFl = g_slist_append( newFl, fn );
559 }
560 return newFl;
561 }
563 int sp_common_main( int argc, char const **argv, GSList **flDest )
564 {
565 /// \todo fixme: Move these to some centralized location (Lauris)
566 sp_object_type_register("sodipodi:namedview", SP_TYPE_NAMEDVIEW);
567 sp_object_type_register("sodipodi:guide", SP_TYPE_GUIDE);
570 // temporarily switch gettext encoding to locale, so that help messages can be output properly
571 gchar const *charset;
572 g_get_charset(&charset);
574 bind_textdomain_codeset(GETTEXT_PACKAGE, charset);
576 poptContext ctx = poptGetContext(NULL, argc, argv, options, 0);
577 poptSetOtherOptionHelp(ctx, _("[OPTIONS...] [FILE...]\n\nAvailable options:"));
578 g_return_val_if_fail(ctx != NULL, 1);
580 /* Collect own arguments */
581 GSList *fl = sp_process_args(ctx);
582 poptFreeContext(ctx);
584 // now switch gettext back to UTF-8 (for GUI)
585 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
587 // Now let's see if the file list still holds up
588 if ( needToRecodeParams )
589 {
590 fl = fixupFilenameEncoding( fl );
591 }
593 // Check the globals for filename-fixup
594 if ( needToRecodeParams )
595 {
596 fixupSingleFilename( &sp_export_png, &sp_export_png_utf8 );
597 fixupSingleFilename( &sp_export_svg, &sp_export_svg_utf8 );
598 fixupSingleFilename( &sp_global_printer, &sp_global_printer_utf8 );
599 }
600 else
601 {
602 if ( sp_export_png )
603 sp_export_png_utf8 = g_strdup( sp_export_png );
604 if ( sp_export_svg )
605 sp_export_svg_utf8 = g_strdup( sp_export_svg );
606 if ( sp_global_printer )
607 sp_global_printer_utf8 = g_strdup( sp_global_printer );
608 }
610 // Return the list if wanted, else free it up.
611 if ( flDest ) {
612 *flDest = fl;
613 fl = 0;
614 } else {
615 while ( fl ) {
616 g_free( fl->data );
617 fl = g_slist_remove( fl, fl->data );
618 }
619 }
620 return 0;
621 }
623 int
624 sp_main_gui(int argc, char const **argv)
625 {
626 Gtk::Main main_instance (&argc, const_cast<char ***>(&argv));
628 GSList *fl = NULL;
629 int retVal = sp_common_main( argc, argv, &fl );
630 g_return_val_if_fail(retVal == 0, 1);
632 inkscape_gtk_stock_init();
634 Inkscape::Debug::log_display_config();
636 /* Set default icon */
637 gchar *filename = (gchar *) g_build_filename (INKSCAPE_APPICONDIR, "inkscape.png", NULL);
638 if (Inkscape::IO::file_test(filename, (GFileTest)(G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))) {
639 gtk_window_set_default_icon_from_file(filename, NULL);
640 }
641 g_free (filename);
642 filename = 0;
644 gboolean create_new = TRUE;
646 /// \todo FIXME BROKEN - non-UTF-8 sneaks in here.
647 inkscape_application_init(argv[0], true);
649 while (fl) {
650 if (sp_file_open((gchar *)fl->data,NULL)) {
651 create_new=FALSE;
652 }
653 fl = g_slist_remove(fl, fl->data);
654 }
655 if (create_new) {
656 sp_file_new_default();
657 }
659 Glib::signal_idle().connect(sigc::ptr_fun(&Inkscape::CmdLineAction::idle));
660 main_instance.run();
662 #ifdef WIN32
663 //We might not need anything here
664 //sp_win32_finish(); <-- this is a NOP func
665 #endif
667 return 0;
668 }
670 int
671 sp_main_console(int argc, char const **argv)
672 {
673 /* We are started in text mode */
675 /* Do this g_type_init(), so that we can use Xft/Freetype2 (Pango)
676 * in a non-Gtk environment. Used in libnrtype's
677 * FontInstance.cpp and FontFactory.cpp.
678 * http://mail.gnome.org/archives/gtk-list/2003-December/msg00063.html
679 */
680 g_type_init();
681 char **argv2 = const_cast<char **>(argv);
682 gtk_init_check( &argc, &argv2 );
683 //setlocale(LC_ALL, "");
685 GSList *fl = NULL;
686 int retVal = sp_common_main( argc, argv, &fl );
687 g_return_val_if_fail(retVal == 0, 1);
689 if (fl == NULL) {
690 g_print("Nothing to do!\n");
691 exit(0);
692 }
694 inkscape_application_init(argv[0], false);
696 while (fl) {
697 SPDocument *doc;
699 doc = Inkscape::Extension::open(NULL, (gchar *)fl->data);
700 if (doc == NULL) {
701 doc = Inkscape::Extension::open(Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), (gchar *)fl->data);
702 }
703 if (doc == NULL) {
704 g_warning("Specified document %s cannot be opened (is it valid SVG file?)", (gchar *) fl->data);
705 } else {
706 if (sp_vacuum_defs) {
707 vacuum_document(doc);
708 }
709 if (sp_vacuum_defs && !sp_export_svg) {
710 // save under the name given in the command line
711 sp_repr_save_file(doc->rdoc, (gchar *)fl->data, SP_SVG_NS_URI);
712 }
713 if (sp_global_printer) {
714 sp_print_document_to_file(doc, sp_global_printer);
715 }
716 if (sp_export_png || sp_export_id || sp_export_area_drawing) {
717 sp_do_export_png(doc);
718 }
719 if (sp_export_svg) {
720 Inkscape::XML::Document *rdoc;
721 Inkscape::XML::Node *repr;
722 rdoc = sp_repr_document_new("svg:svg");
723 repr = rdoc->root();
724 repr = sp_document_root(doc)->updateRepr(repr, SP_OBJECT_WRITE_BUILD);
725 sp_repr_save_file(repr->document(), sp_export_svg, SP_SVG_NS_URI);
726 }
727 if (sp_export_ps) {
728 do_export_ps(doc, sp_export_ps, "image/x-postscript");
729 }
730 if (sp_export_eps) {
731 do_export_ps(doc, sp_export_eps, "image/x-e-postscript");
732 }
733 if (sp_export_pdf) {
734 do_export_pdf(doc, sp_export_pdf, "application/pdf");
735 }
736 if (sp_query_width || sp_query_height) {
737 do_query_dimension (doc, true, sp_query_width? NR::X : NR::Y, sp_query_id);
738 } else if (sp_query_x || sp_query_y) {
739 do_query_dimension (doc, false, sp_query_x? NR::X : NR::Y, sp_query_id);
740 }
741 }
743 fl = g_slist_remove(fl, fl->data);
744 }
746 inkscape_unref();
748 return 0;
749 }
751 static void
752 do_query_dimension (SPDocument *doc, bool extent, NR::Dim2 const axis, const gchar *id)
753 {
754 SPObject *o = NULL;
756 if (id) {
757 o = doc->getObjectById(id);
758 if (o) {
759 if (!SP_IS_ITEM (o)) {
760 g_warning("Object with id=\"%s\" is not a visible item. Cannot query dimensions.", id);
761 return;
762 }
763 } else {
764 g_warning("Object with id=\"%s\" is not found. Cannot query dimensions.", id);
765 return;
766 }
767 } else {
768 o = SP_DOCUMENT_ROOT(doc);
769 }
771 if (o) {
772 sp_document_ensure_up_to_date (doc);
773 SPItem *item = ((SPItem *) o);
775 // "true" SVG bbox for scripting
776 NR::Maybe<NR::Rect> area = item->getBounds(sp_item_i2doc_affine(item));
777 if (area) {
778 Inkscape::SVGOStringStream os;
779 if (extent) {
780 os << area->extent(axis);
781 } else {
782 os << area->min()[axis];
783 }
784 g_print ("%s", os.str().c_str());
785 } else {
786 g_print("0");
787 }
788 }
789 }
792 static void
793 sp_do_export_png(SPDocument *doc)
794 {
795 const gchar *filename = NULL;
796 gdouble dpi = 0.0;
798 if (sp_export_use_hints && (!sp_export_id && !sp_export_area_drawing)) {
799 g_warning ("--export-use-hints can only be used with --export-id or --export-area-drawing; ignored.");
800 }
802 GSList *items = NULL;
804 NRRect area;
805 if (sp_export_id || sp_export_area_drawing) {
807 SPObject *o = NULL;
808 SPObject *o_area = NULL;
809 if (sp_export_id && sp_export_area_drawing) {
810 o = doc->getObjectById(sp_export_id);
811 o_area = SP_DOCUMENT_ROOT (doc);
812 } else if (sp_export_id) {
813 o = doc->getObjectById(sp_export_id);
814 o_area = o;
815 } else if (sp_export_area_drawing) {
816 o = SP_DOCUMENT_ROOT (doc);
817 o_area = o;
818 }
820 if (o) {
821 if (!SP_IS_ITEM (o)) {
822 g_warning("Object with id=\"%s\" is not a visible item. Nothing exported.", sp_export_id);
823 return;
824 }
826 items = g_slist_prepend (items, SP_ITEM(o));
828 if (sp_export_id_only) {
829 g_print("Exporting only object with id=\"%s\"; all other objects hidden\n", sp_export_id);
830 }
832 if (sp_export_use_hints) {
834 // retrieve export filename hint
835 const gchar *fn_hint = SP_OBJECT_REPR(o)->attribute("inkscape:export-filename");
836 if (fn_hint) {
837 if (sp_export_png) {
838 g_warning ("Using export filename from the command line (--export-png). Filename hint %s is ignored.", fn_hint);
839 filename = sp_export_png;
840 } else {
841 filename = fn_hint;
842 }
843 } else {
844 g_warning ("Export filename hint not found for the object.");
845 filename = sp_export_png;
846 }
848 // retrieve export dpi hints
849 const gchar *dpi_hint = SP_OBJECT_REPR(o)->attribute("inkscape:export-xdpi"); // only xdpi, ydpi is always the same now
850 if (dpi_hint) {
851 if (sp_export_dpi || sp_export_width || sp_export_height) {
852 g_warning ("Using bitmap dimensions from the command line (--export-dpi, --export-width, or --export-height). DPI hint %s is ignored.", dpi_hint);
853 } else {
854 dpi = atof(dpi_hint);
855 }
856 } else {
857 g_warning ("Export DPI hint not found for the object.");
858 }
860 }
862 // write object bbox to area
863 sp_document_ensure_up_to_date (doc);
864 sp_item_invoke_bbox((SPItem *) o_area, &area, sp_item_i2r_affine((SPItem *) o_area), TRUE);
865 } else {
866 g_warning("Object with id=\"%s\" was not found in the document. Nothing exported.", sp_export_id);
867 return;
868 }
869 }
871 if (sp_export_area) {
872 /* Try to parse area (given in SVG pixels) */
873 if (!sscanf(sp_export_area, "%lg:%lg:%lg:%lg", &area.x0, &area.y0, &area.x1, &area.y1) == 4) {
874 g_warning("Cannot parse export area '%s'; use 'x0:y0:x1:y1'. Nothing exported.", sp_export_area);
875 return;
876 }
877 if ((area.x0 >= area.x1) || (area.y0 >= area.y1)) {
878 g_warning("Export area '%s' has negative width or height. Nothing exported.", sp_export_area);
879 return;
880 }
881 } else if (sp_export_area_canvas || !(sp_export_id || sp_export_area_drawing)) {
882 /* Export the whole canvas */
883 sp_document_ensure_up_to_date (doc);
884 area.x0 = SP_ROOT(doc->root)->x.computed;
885 area.y0 = SP_ROOT(doc->root)->y.computed;
886 area.x1 = area.x0 + sp_document_width (doc);
887 area.y1 = area.y0 + sp_document_height (doc);
888 }
890 // set filename and dpi from options, if not yet set from the hints
891 if (!filename) {
892 if (!sp_export_png) {
893 g_warning ("No export filename given and no filename hint. Nothing exported.");
894 return;
895 }
896 filename = sp_export_png;
897 }
899 if (sp_export_dpi && dpi == 0.0) {
900 dpi = atof(sp_export_dpi);
901 if ((dpi < 0.1) || (dpi > 10000.0)) {
902 g_warning("DPI value %s out of range [0.1 - 10000.0]. Nothing exported.", sp_export_dpi);
903 return;
904 }
905 g_print("DPI: %g\n", dpi);
906 }
908 if (sp_export_area_snap) {
909 area.x0 = std::floor (area.x0);
910 area.y0 = std::floor (area.y0);
911 area.x1 = std::ceil (area.x1);
912 area.y1 = std::ceil (area.y1);
913 }
915 // default dpi
916 if (dpi == 0.0)
917 dpi = PX_PER_IN;
919 gint width = 0;
920 gint height = 0;
922 if (sp_export_width) {
923 width = atoi(sp_export_width);
924 if ((width < 1) || (width > 65536)) {
925 g_warning("Export width %d out of range (1 - 65536). Nothing exported.", width);
926 return;
927 }
928 dpi = (gdouble) width * PX_PER_IN / (area.x1 - area.x0);
929 }
931 if (sp_export_height) {
932 height = atoi(sp_export_height);
933 if ((height < 1) || (height > 65536)) {
934 g_warning("Export height %d out of range (1 - 65536). Nothing exported.", width);
935 return;
936 }
937 dpi = (gdouble) height * PX_PER_IN / (area.y1 - area.y0);
938 }
940 if (!sp_export_width) {
941 width = (gint) ((area.x1 - area.x0) * dpi / PX_PER_IN + 0.5);
942 }
944 if (!sp_export_height) {
945 height = (gint) ((area.y1 - area.y0) * dpi / PX_PER_IN + 0.5);
946 }
948 guint32 bgcolor = 0x00000000;
949 if (sp_export_background) {
950 // override the page color
951 bgcolor = sp_svg_read_color(sp_export_background, 0xffffff00);
952 bgcolor |= 0xff; // default is no opacity
953 } else {
954 // read from namedview
955 Inkscape::XML::Node *nv = sp_repr_lookup_name (doc->rroot, "sodipodi:namedview");
956 if (nv && nv->attribute("pagecolor"))
957 bgcolor = sp_svg_read_color(nv->attribute("pagecolor"), 0xffffff00);
958 if (nv && nv->attribute("inkscape:pageopacity"))
959 bgcolor |= SP_COLOR_F_TO_U(sp_repr_get_double_attribute (nv, "inkscape:pageopacity", 1.0));
960 }
962 if (sp_export_background_opacity) {
963 // override opacity
964 gfloat value;
965 if (sp_svg_number_read_f (sp_export_background_opacity, &value)) {
966 if (value > 1.0) {
967 value = CLAMP (value, 1.0f, 255.0f);
968 bgcolor &= (guint32) 0xffffff00;
969 bgcolor |= (guint32) floor(value);
970 } else {
971 value = CLAMP (value, 0.0f, 1.0f);
972 bgcolor &= (guint32) 0xffffff00;
973 bgcolor |= SP_COLOR_F_TO_U(value);
974 }
975 }
976 }
978 g_print("Background RRGGBBAA: %08x\n", bgcolor);
980 g_print("Area %g:%g:%g:%g exported to %d x %d pixels (%g dpi)\n", area.x0, area.y0, area.x1, area.y1, width, height, dpi);
982 g_print("Bitmap saved as: %s\n", filename);
984 if ((width >= 1) && (height >= 1) && (width < 65536) && (height < 65536)) {
985 sp_export_png_file(doc, filename, area.x0, area.y0, area.x1, area.y1, width, height, dpi, dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL);
986 } else {
987 g_warning("Calculated bitmap dimensions %d %d are out of range (1 - 65535). Nothing exported.", width, height);
988 }
990 g_slist_free (items);
991 }
994 /**
995 * Perform an export of either PS or EPS.
996 *
997 * \param doc Document to export.
998 * \param uri URI to export to.
999 * \param mime MIME type to export as.
1000 */
1002 static void do_export_ps(SPDocument* doc, gchar const* uri, char const* mime)
1003 {
1004 Inkscape::Extension::DB::OutputList o;
1005 Inkscape::Extension::db.get_output_list(o);
1006 Inkscape::Extension::DB::OutputList::const_iterator i = o.begin();
1007 while (i != o.end() && strcmp( (*i)->get_mimetype(), mime ) != 0) {
1008 i++;
1009 }
1011 if (i == o.end())
1012 {
1013 g_warning ("Could not find an extension to export this file.");
1014 return;
1015 }
1017 bool old_text_to_path = false;
1018 bool old_font_embedded = false;
1019 bool old_bbox_page = false;
1021 try {
1022 old_text_to_path = (*i)->get_param_bool("textToPath");
1023 (*i)->set_param_bool("textToPath", sp_export_text_to_path);
1024 }
1025 catch (...) {
1026 g_warning ("Could not set export-text-to-path option for this export.");
1027 }
1029 try {
1030 old_font_embedded = (*i)->get_param_bool("fontEmbedded");
1031 (*i)->set_param_bool("fontEmbedded", sp_export_font);
1032 }
1033 catch (...) {
1034 g_warning ("Could not set export-font option for this export.");
1035 }
1037 try {
1038 old_bbox_page = (*i)->get_param_bool("pageBoundingBox");
1039 (*i)->set_param_bool("pageBoundingBox", sp_export_bbox_page);
1040 }
1041 catch (...) {
1042 g_warning ("Could not set export-bbox-page option for this export.");
1043 }
1045 (*i)->save(doc, uri);
1047 try {
1048 (*i)->set_param_bool("textToPath", old_text_to_path);
1049 (*i)->set_param_bool("fontEmbedded", old_font_embedded);
1050 (*i)->set_param_bool("pageBoundingBox", old_bbox_page);
1051 }
1052 catch (...) {
1054 }
1055 }
1057 /**
1058 * Perform a PDF export
1059 *
1060 * \param doc Document to export.
1061 * \param uri URI to export to.
1062 * \param mime MIME type to export as.
1063 */
1065 static void do_export_pdf(SPDocument* doc, gchar const* uri, char const* mime)
1066 {
1067 Inkscape::Extension::DB::OutputList o;
1068 Inkscape::Extension::db.get_output_list(o);
1069 Inkscape::Extension::DB::OutputList::const_iterator i = o.begin();
1070 while (i != o.end() && strcmp( (*i)->get_mimetype(), mime ) != 0) {
1071 i++;
1072 }
1074 if (i == o.end())
1075 {
1076 g_warning ("Could not find an extension to export this file.");
1077 return;
1078 }
1080 (*i)->save(doc, uri);
1081 }
1083 #ifdef WIN32
1084 bool replaceArgs( int& argc, char**& argv )
1085 {
1086 bool worked = false;
1088 #ifdef REPLACEARGS_DEBUG
1089 MessageBoxA( NULL, "GetCommandLineW() getting called", "GetCommandLineW", MB_OK | MB_ICONINFORMATION );
1090 #endif // REPLACEARGS_DEBUG
1092 wchar_t* line = GetCommandLineW();
1093 if ( line )
1094 {
1095 #ifdef REPLACEARGS_DEBUG
1096 {
1097 gchar* utf8Line = g_utf16_to_utf8( (gunichar2*)line, -1, NULL, NULL, NULL );
1098 if ( utf8Line )
1099 {
1100 gchar *safe = Inkscape::IO::sanitizeString(utf8Line);
1101 {
1102 char tmp[strlen(safe) + 32];
1103 snprintf( tmp, sizeof(tmp), "GetCommandLineW() = '%s'", safe );
1104 MessageBoxA( NULL, tmp, "GetCommandLineW", MB_OK | MB_ICONINFORMATION );
1105 }
1106 }
1107 }
1108 #endif // REPLACEARGS_DEBUG
1110 int numArgs = 0;
1111 wchar_t** parsed = CommandLineToArgvW( line, &numArgs );
1113 #ifdef REPLACEARGS_ANSI
1114 // test code for trying things on Win95/98/ME
1115 if ( !parsed )
1116 {
1117 #ifdef REPLACEARGS_DEBUG
1118 MessageBoxA( NULL, "Unable to process command-line. Faking it", "CommandLineToArgvW", MB_OK | MB_ICONINFORMATION );
1119 #endif // REPLACEARGS_DEBUG
1120 int lineLen = wcslen(line) + 1;
1121 wchar_t* lineDup = new wchar_t[lineLen];
1122 wcsncpy( lineDup, line, lineLen );
1124 int pos = 0;
1125 bool inQuotes = false;
1126 bool inWhitespace = true;
1127 std::vector<int> places;
1128 while ( lineDup[pos] )
1129 {
1130 if ( inQuotes )
1131 {
1132 if ( lineDup[pos] == L'"' )
1133 {
1134 inQuotes = false;
1135 }
1136 }
1137 else if ( lineDup[pos] == L'"' )
1138 {
1139 inQuotes = true;
1140 inWhitespace = false;
1141 places.push_back(pos);
1142 }
1143 else if ( lineDup[pos] == L' ' || lineDup[pos] == L'\t' )
1144 {
1145 if ( !inWhitespace )
1146 {
1147 inWhitespace = true;
1148 lineDup[pos] = 0;
1149 }
1150 }
1151 else if ( inWhitespace && (lineDup[pos] != L' ' && lineDup[pos] != L'\t') )
1152 {
1153 inWhitespace = false;
1154 places.push_back(pos);
1155 }
1156 else
1157 {
1158 // consume
1159 }
1160 pos++;
1161 }
1162 #ifdef REPLACEARGS_DEBUG
1163 {
1164 char tmp[256];
1165 snprintf( tmp, sizeof(tmp), "Counted %d args", places.size() );
1166 MessageBoxA( NULL, tmp, "CommandLineToArgvW", MB_OK | MB_ICONINFORMATION );
1167 }
1168 #endif // REPLACEARGS_DEBUG
1170 wchar_t** block = new wchar_t*[places.size()];
1171 int i = 0;
1172 for ( std::vector<int>::iterator it = places.begin(); it != places.end(); it++ )
1173 {
1174 block[i++] = &lineDup[*it];
1175 }
1176 parsed = block;
1177 numArgs = places.size();
1178 }
1179 #endif // REPLACEARGS_ANSI
1181 if ( parsed )
1182 {
1183 std::vector<wchar_t*>expandedArgs;
1184 if ( numArgs > 0 )
1185 {
1186 expandedArgs.push_back( parsed[0] );
1187 }
1189 for ( int i1 = 1; i1 < numArgs; i1++ )
1190 {
1191 bool wildcarded = (wcschr(parsed[i1], L'?') != NULL) || (wcschr(parsed[i1], L'*') != NULL);
1192 wildcarded &= parsed[i1][0] != L'"';
1193 wildcarded &= parsed[i1][0] != L'-';
1194 if ( wildcarded )
1195 {
1196 #ifdef REPLACEARGS_ANSI
1197 WIN32_FIND_DATAA data = {0};
1198 #else
1199 WIN32_FIND_DATAW data = {0};
1200 #endif // REPLACEARGS_ANSI
1202 int baseLen = wcslen(parsed[i1]) + 2;
1203 wchar_t* base = new wchar_t[baseLen];
1204 wcsncpy( base, parsed[i1], baseLen );
1205 wchar_t* last = wcsrchr( base, L'\\' );
1206 if ( last )
1207 {
1208 last[1] = 0;
1209 }
1210 else
1211 {
1212 base[0] = 0;
1213 }
1214 baseLen = wcslen( base );
1216 #ifdef REPLACEARGS_ANSI
1217 char target[MAX_PATH];
1218 if ( WideCharToMultiByte( CP_ACP, 0, parsed[i1], -1, target, sizeof(target), NULL, NULL) )
1219 {
1220 HANDLE hf = FindFirstFileA( target, &data );
1221 #else
1222 HANDLE hf = FindFirstFileW( parsed[i1], &data );
1223 #endif // REPLACEARGS_ANSI
1224 if ( hf != INVALID_HANDLE_VALUE )
1225 {
1226 BOOL found = TRUE;
1227 do
1228 {
1229 #ifdef REPLACEARGS_ANSI
1230 int howMany = MultiByteToWideChar( CP_ACP, 0, data.cFileName, -1, NULL, 0 );
1231 if ( howMany > 0 )
1232 {
1233 howMany += baseLen;
1234 wchar_t* tmp = new wchar_t[howMany + 1];
1235 wcsncpy( tmp, base, howMany + 1 );
1236 MultiByteToWideChar( CP_ACP, 0, data.cFileName, -1, tmp + baseLen, howMany + 1 - baseLen );
1237 expandedArgs.push_back( tmp );
1238 found = FindNextFileA( hf, &data );
1239 }
1240 #else
1241 int howMany = wcslen(data.cFileName) + baseLen;
1242 wchar_t* tmp = new wchar_t[howMany + 1];
1243 wcsncpy( tmp, base, howMany + 1 );
1244 wcsncat( tmp, data.cFileName, howMany + 1 );
1245 expandedArgs.push_back( tmp );
1246 found = FindNextFileW( hf, &data );
1247 #endif // REPLACEARGS_ANSI
1248 } while ( found );
1250 FindClose( hf );
1251 }
1252 else
1253 {
1254 expandedArgs.push_back( parsed[i1] );
1255 }
1256 #ifdef REPLACEARGS_ANSI
1257 }
1258 #endif // REPLACEARGS_ANSI
1260 delete[] base;
1261 }
1262 else
1263 {
1264 expandedArgs.push_back( parsed[i1] );
1265 }
1266 }
1268 {
1269 wchar_t** block = new wchar_t*[expandedArgs.size()];
1270 int iz = 0;
1271 for ( std::vector<wchar_t*>::iterator it = expandedArgs.begin(); it != expandedArgs.end(); it++ )
1272 {
1273 block[iz++] = *it;
1274 }
1275 parsed = block;
1276 numArgs = expandedArgs.size();
1277 }
1279 std::vector<gchar*> newArgs;
1280 for ( int i = 0; i < numArgs; i++ )
1281 {
1282 gchar* replacement = g_utf16_to_utf8( (gunichar2*)parsed[i], -1, NULL, NULL, NULL );
1283 if ( replacement )
1284 {
1285 #ifdef REPLACEARGS_DEBUG
1286 gchar *safe2 = Inkscape::IO::sanitizeString(replacement);
1288 if ( safe2 )
1289 {
1290 {
1291 char tmp[1024];
1292 snprintf( tmp, sizeof(tmp), " [%2d] = '%s'", i, safe2 );
1293 MessageBoxA( NULL, tmp, "GetCommandLineW", MB_OK | MB_ICONINFORMATION );
1294 }
1295 g_free( safe2 );
1296 }
1297 #endif // REPLACEARGS_DEBUG
1299 newArgs.push_back( replacement );
1300 }
1301 else
1302 {
1303 newArgs.push_back( blankParam );
1304 }
1305 }
1307 // Now push our munged params to be the new argv and argc
1308 {
1309 char** block = new char*[newArgs.size()];
1310 int iz = 0;
1311 for ( std::vector<char*>::iterator it = newArgs.begin(); it != newArgs.end(); it++ )
1312 {
1313 block[iz++] = *it;
1314 }
1315 argv = block;
1316 argc = newArgs.size();
1317 worked = true;
1318 }
1319 }
1320 #ifdef REPLACEARGS_DEBUG
1321 else
1322 {
1323 MessageBoxA( NULL, "Unable to process command-line", "CommandLineToArgvW", MB_OK | MB_ICONINFORMATION );
1324 }
1325 #endif // REPLACEARGS_DEBUG
1326 }
1327 #ifdef REPLACEARGS_DEBUG
1328 else
1329 {
1330 {
1331 MessageBoxA( NULL, "Unable to fetch result from GetCommandLineW()", "GetCommandLineW", MB_OK | MB_ICONINFORMATION );
1332 }
1334 char* line2 = GetCommandLineA();
1335 if ( line2 )
1336 {
1337 gchar *safe = Inkscape::IO::sanitizeString(line2);
1338 {
1339 {
1340 char tmp[strlen(safe) + 32];
1341 snprintf( tmp, sizeof(tmp), "GetCommandLineA() = '%s'", safe );
1342 MessageBoxA( NULL, tmp, "GetCommandLineA", MB_OK | MB_ICONINFORMATION );
1343 }
1344 }
1345 }
1346 else
1347 {
1348 MessageBoxA( NULL, "Unable to fetch result from GetCommandLineA()", "GetCommandLineA", MB_OK | MB_ICONINFORMATION );
1349 }
1350 }
1351 #endif // REPLACEARGS_DEBUG
1353 return worked;
1354 }
1355 #endif // WIN32
1357 static GSList *
1358 sp_process_args(poptContext ctx)
1359 {
1360 GSList *fl = NULL;
1362 gint a;
1363 while ((a = poptGetNextOpt(ctx)) >= 0) {
1364 switch (a) {
1365 case SP_ARG_FILE: {
1366 gchar const *fn = poptGetOptArg(ctx);
1367 if (fn != NULL) {
1368 fl = g_slist_append(fl, g_strdup(fn));
1369 }
1370 break;
1371 }
1372 case SP_ARG_VERSION: {
1373 printf("Inkscape %s (%s)\n", INKSCAPE_VERSION, __DATE__);
1374 exit(0);
1375 break;
1376 }
1377 case SP_ARG_EXTENSIONDIR: {
1378 printf("%s\n", INKSCAPE_EXTENSIONDIR);
1379 exit(0);
1380 break;
1381 }
1382 case SP_ARG_VERB_LIST: {
1383 // This really shouldn't go here, we should init the app.
1384 // But, since we're just exiting in this path, there is
1385 // no harm, and this is really a better place to put
1386 // everything else.
1387 Inkscape::Extension::init();
1388 Inkscape::Verb::list();
1389 exit(0);
1390 break;
1391 }
1392 case SP_ARG_VERB:
1393 case SP_ARG_SELECT: {
1394 gchar const *arg = poptGetOptArg(ctx);
1395 if (arg != NULL) {
1396 // printf("Adding in: %s\n", arg);
1397 new Inkscape::CmdLineAction((a == SP_ARG_VERB), arg);
1398 }
1399 break;
1400 }
1401 default: {
1402 break;
1403 }
1404 }
1405 }
1407 gchar const ** const args = poptGetArgs(ctx);
1408 if (args != NULL) {
1409 for (unsigned i = 0; args[i] != NULL; i++) {
1410 fl = g_slist_append(fl, g_strdup(args[i]));
1411 }
1412 }
1414 return fl;
1415 }
1418 /*
1419 Local Variables:
1420 mode:c++
1421 c-file-style:"stroustrup"
1422 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1423 indent-tabs-mode:nil
1424 fill-column:99
1425 End:
1426 */
1427 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :