main.cpp revision 4cb9ed4c3d183554e888e636844f8e3c2e666c40
#define __MAIN_C__
/** \file
* Inkscape - an ambitious vector drawing program
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* Davide Puricelli <evo@debian.org>
* Mitsuru Oka <oka326@parkcity.ne.jp>
* Masatake YAMATO <jet@gyve.org>
* F.J.Franklin <F.J.Franklin@sheffield.ac.uk>
* Michael Meeks <michael@helixcode.com>
* Chema Celorio <chema@celorio.com>
* Pawel Palucha
* Bryce Harrington <bryce@bryceharrington.com>
* ... and various people who have worked with various projects
*
* Copyright (C) 1999-2004 authors
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "path-prefix.h"
// This has to be included prior to anything that includes setjmp.h, it croaks otherwise
#include <png.h>
#include <gtk/gtkmessagedialog.h>
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#include <cstring>
#include <string>
#include <locale.h>
#include <stdlib.h>
#include <popt.h>
#ifndef POPT_TABLEEND
#endif /* Not def: POPT_TABLEEND */
#include <glib-object.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkwindow.h>
#include "gc-core.h"
#include "macros.h"
#include "file.h"
#include "document.h"
#include "sp-object.h"
#include "interface.h"
#include "print.h"
#include "color.h"
#include "sp-item.h"
#include "sp-root.h"
#include "unit-constants.h"
#include "svg/svg-color.h"
#include "svg/stringstream.h"
#include "inkscape-private.h"
#include "inkscape-version.h"
#include "sp-namedview.h"
#include "sp-guide.h"
#include "sp-object-repr.h"
#include "debug/log-display-config.h"
#include "helper/png-write.h"
#include <extension/extension.h>
#ifdef WIN32
//#define REPLACEARGS_ANSI
//#define REPLACEARGS_DEBUG
#include "registrytool.h"
#endif // WIN32
#ifndef HAVE_BIND_TEXTDOMAIN_CODESET
#define bind_textdomain_codeset(p,c)
#endif
#include "application/application.h"
#include "main-cmdlineact.h"
#include <errno.h>
enum {
#ifdef WIN32
#endif //WIN32
};
#ifdef WIN32
#endif //WIN32
static void do_query_dimension (SPDocument *doc, bool extent, Geom::Dim2 const axis, const gchar *id);
static void do_query_all_recurse (SPObject *o);
#ifdef WIN32
#endif //WIN32
static int sp_new_gui = FALSE;
/**
* Reset variables to default values.
*/
static void resetCommandlineGlobals() {
sp_export_id = NULL;
sp_export_ps = NULL;
#ifdef WIN32
#endif //WIN32
sp_query_x = FALSE;
sp_query_y = FALSE;
sp_query_id = NULL;
}
#ifdef WIN32
#endif
struct poptOption options[] = {
{"version", 'V',
N_("Print the Inkscape version number"),
NULL},
{"without-gui", 'z',
N_("Do not use X server (only process files from console)"),
NULL},
{"with-gui", 'g',
N_("Try to use X server (even if $DISPLAY is not set)"),
NULL},
{"file", 'f',
N_("Open specified document(s) (option string may be excluded)"),
N_("FILENAME")},
{"print", 'p',
N_("Print document(s) to specified output file (use '| program' for pipe)"),
N_("FILENAME")},
{"export-png", 'e',
N_("Export document to a PNG file"),
N_("FILENAME")},
{"export-dpi", 'd',
N_("The resolution used for exporting SVG into bitmap (default 90)"),
N_("DPI")},
{"export-area", 'a',
N_("Exported area in SVG user units (default is the canvas; 0,0 is lower-left corner)"),
N_("x0:y0:x1:y1")},
{"export-area-drawing", 'D',
N_("Exported area is the entire drawing (not canvas)"),
NULL},
{"export-area-canvas", 'C',
N_("Exported area is the entire canvas"),
NULL},
{"export-area-snap", 0,
N_("Snap the bitmap export area outwards to the nearest integer values (in SVG user units)"),
NULL},
{"export-width", 'w',
N_("The width of exported bitmap in pixels (overrides export-dpi)"),
N_("WIDTH")},
{"export-height", 'h',
N_("The height of exported bitmap in pixels (overrides export-dpi)"),
N_("HEIGHT")},
{"export-id", 'i',
N_("The ID of the object to export"),
N_("ID")},
{"export-id-only", 'j',
// TRANSLATORS: this means: "Only export the object whose id is given in --export-id".
// See "man inkscape" for details.
N_("Export just the object with export-id, hide all others (only with export-id)"),
NULL},
{"export-use-hints", 't',
N_("Use stored filename and DPI hints when exporting (only with export-id)"),
NULL},
{"export-background", 'b',
N_("Background color of exported bitmap (any SVG-supported color string)"),
N_("COLOR")},
{"export-background-opacity", 'y',
N_("Background opacity of exported bitmap (either 0.0 to 1.0, or 1 to 255)"),
N_("VALUE")},
{"export-plain-svg", 'l',
N_("Export document to plain SVG file (no sodipodi or inkscape namespaces)"),
N_("FILENAME")},
{"export-ps", 'P',
N_("Export document to a PS file"),
N_("FILENAME")},
{"export-eps", 'E',
N_("Export document to an EPS file"),
N_("FILENAME")},
{"export-pdf", 'A',
N_("Export document to a PDF file"),
N_("FILENAME")},
#ifdef WIN32
{"export-emf", 'M',
N_("Export document to an Enhanced Metafile (EMF) File"),
N_("FILENAME")},
#endif //WIN32
{"export-text-to-path", 'T',
N_("Convert text object to paths on export (PS, EPS, PDF)"),
NULL},
{"export-ignore-filters", 0,
N_("Render filtered objects without filters, instead of rasterizing (PS, EPS, PDF)"),
NULL},
{"query-x", 'X',
// TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
N_("Query the X coordinate of the drawing or, if specified, of the object with --query-id"),
NULL},
{"query-y", 'Y',
// TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
N_("Query the Y coordinate of the drawing or, if specified, of the object with --query-id"),
NULL},
{"query-width", 'W',
// TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
N_("Query the width of the drawing or, if specified, of the object with --query-id"),
NULL},
{"query-height", 'H',
// TRANSLATORS: "--query-id" is an Inkscape command line option; see "inkscape --help"
N_("Query the height of the drawing or, if specified, of the object with --query-id"),
NULL},
{"query-all", 'S',
N_("List id,x,y,w,h for all objects"),
NULL},
{"query-id", 'I',
N_("The ID of the object whose dimensions are queried"),
N_("ID")},
{"extension-directory", 'x',
// TRANSLATORS: this option makes Inkscape print the name (path) of the extension directory
N_("Print out the extension directory and exit"),
NULL},
{"vacuum-defs", 0,
N_("Remove unused definitions from the defs section(s) of the document"),
NULL},
{"verb-list", 0,
N_("List the IDs of all the verbs in Inkscape"),
NULL},
{"verb", 0,
N_("Verb to call when Inkscape opens."),
N_("VERB-ID")},
{"select", 0,
N_("Object ID to select when Inkscape opens."),
N_("OBJECT-ID")},
{"shell", 0,
N_("Start Inkscape in interative shell mode."),
NULL},
};
static bool needToRecodeParams = true;
#ifdef WIN32
/**
* Return the directory of the .exe that is currently running
*/
{
if (slashPos)
*slashPos = '\0';
return s;
}
/**
* Set up the PATH and PYTHONPATH environment variables on
* win32
*/
{
tmp += ";";
tmp += "\\python;";
tmp += "\\perl";
tmp += ";";
}
tmp = "PYTHONPATH=";
tmp += "\\python;";
tmp += "\\python\\Lib;";
tmp += "\\python\\DLLs";
tmp += ";";
}
return 0;
}
#endif
/**
* Add INKSCAPE_EXTENSIONDIR to PYTHONPATH so that extensions in users home
* can find inkex.py et al. (Bug #197475)
*/
static int set_extensions_env()
{
}
return 0;
}
/**
* This is the classic main() entry point of the program, though on some
* architectures it might be called by something else.
*/
int
{
#ifdef HAVE_FPSETMASK
/* This is inherited from Sodipodi code, where it was in #ifdef __FreeBSD__. It's probably
safe to remove: the default mask is already 0 in C99, and in current FreeBSD according to
the fenv man page on www.freebsd.org, and in glibc according to (libc)FP Exceptions. */
#endif
#ifdef WIN32
/*
Set the current directory to the directory of the
executable. This seems redundant, but is needed for
when inkscape.exe is executed from another directory.
We use relative paths on win32.
HKCR\svgfile\shell\open\command is a good example
*/
rt.setPathInfo();
#endif
// Prevents errors like "Unable to wrap GdkPixbuf..." (in nr-filter-image.cpp for example)
// Bug #197475
/**
* Call bindtextdomain() for various machines's paths
*/
#ifdef ENABLE_NLS
#ifdef WIN32
localePath += "\\";
#else
#ifdef ENABLE_BINRELOC
#else
#endif
#endif
// Allow the user to override the locale directory by setting
// the environment variable INKSCAPE_LOCALEDIR.
if (inkscape_localedir != NULL) {
}
#endif
#ifdef ENABLE_NLS
#endif
#ifndef WIN32
#else
#endif
for (int i = 1; i < argc; i++) {
#ifdef WIN32
#endif //WIN32
)
{
/* main_console handles any exports -- not the gui */
break;
break;
}
}
#ifdef WIN32
#ifndef REPLACEARGS_ANSI
if ( PrintWin32::is_os_wide() )
#endif // REPLACEARGS_ANSI
{
// If the call fails, we'll need to convert charsets
}
#endif // WIN32
/// \todo Should this be a static object (see inkscape.cpp)?
}
{
if ( newFileName )
{
*orig = newFileName;
if ( spare ) {
*spare = newFileName;
}
// g_message("Set a replacement fixup");
}
}
}
{
while ( fl ) {
if ( newFileName ) {
if ( 0 )
{
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
}
fn = newFileName;
newFileName = 0;
}
else
if ( 0 )
{
GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Error: Unable to convert '%s'", safeFn );
gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
}
}
return newFl;
}
{
/// \todo fixme: Move these to some centralized location (Lauris)
// temporarily switch gettext encoding to locale, so that help messages can be output properly
/* Collect own arguments */
// now switch gettext back to UTF-8 (for GUI)
// Now let's see if the file list still holds up
if ( needToRecodeParams )
{
}
// Check the globals for filename-fixup
if ( needToRecodeParams )
{
}
else
{
if ( sp_export_png )
if ( sp_export_svg )
if ( sp_global_printer )
}
// Return the list if wanted, else free it up.
if ( flDest ) {
fl = 0;
} else {
while ( fl ) {
}
}
return 0;
}
static void
if(inkscape_mapalt()) /* returns the map of the keyboard modifier to map to Alt, zero if no mapping */
{
case GDK_MOTION_NOTIFY:
}
break;
case GDK_BUTTON_PRESS:
}
break;
case GDK_KEY_PRESS:
}
break;
default:
break;
}
}
}
int
{
// Add our icon directory to the search path for icon theme lookups.
// Set default window icon. Obeys the theme.
gtk_window_set_default_icon_name("inkscape");
// Do things that were previously in inkscape_gtk_stock_init().
/// \todo FIXME BROKEN - non-UTF-8 sneaks in here.
inkscape_application_init(argv[0], true);
while (fl) {
}
}
if (create_new) {
}
main_instance.run();
#ifdef WIN32
//We might not need anything here
//sp_win32_finish(); <-- this is a NOP func
#endif
return 0;
}
/**
* Process file list
*/
{
while (fl) {
}
} else {
if (sp_vacuum_defs) {
}
if (sp_vacuum_defs && !sp_export_svg) {
// save under the name given in the command line
}
if (sp_global_printer) {
}
if (sp_export_png) {
}
if (sp_export_svg) {
}
if (sp_export_ps) {
}
if (sp_export_eps) {
}
if (sp_export_pdf) {
}
#ifdef WIN32
if (sp_export_emf) {
}
#endif //WIN32
if (sp_query_all) {
do_query_all (doc);
} else if (sp_query_width || sp_query_height) {
} else if (sp_query_x || sp_query_y) {
}
delete doc;
}
}
}
/**
* Run the application as an interactive shell, parsing command lines from stdin
* Returns -1 on error.
*/
int sp_main_shell(char const* command_name)
{
int retval = 0;
const unsigned int buffer_size = 4096;
fprintf(stdout, "Inkscape %s interactive shell mode. Type 'quit' to quit.\n", Inkscape::version_string);
char* linedata = 0;
do {
// Consume rest of line
retval = 0;
}
}
} else {
}
// Time to quit
linedata = 0; // mark for exit
} else if ( len < 1 ) {
// blank string. Do nothing.
} else {
GError* parseError = 0;
if ( ctx ) {
} else {
}
} else {
}
}
}
} // if (linedata...
return retval;
}
{
/* We are started in text mode */
* in a non-Gtk environment. Used in libnrtype's
* FontInstance.cpp and FontFactory.cpp.
*/
g_type_init();
//setlocale(LC_ALL, "");
g_print("Nothing to do!\n");
exit(0);
}
inkscape_application_init(argv[0], false);
if (sp_shell) {
exit(0);
} else {
}
return 0;
}
static void
{
if (id) {
if (o) {
if (!SP_IS_ITEM (o)) {
return;
}
} else {
return;
}
} else {
o = SP_DOCUMENT_ROOT(doc);
}
if (o) {
// "true" SVG bbox for scripting
if (area) {
if (extent) {
} else {
}
} else {
g_print("0");
}
}
}
static void
{
o = SP_DOCUMENT_ROOT(doc);
if (o) {
}
}
static void
{
if (area) {
}
}
while (child) {
}
}
static void
{
g_warning ("--export-use-hints can only be used with --export-id or --export-area-drawing; ignored.");
}
if (sp_export_id || sp_export_area_drawing) {
if (sp_export_id && sp_export_area_drawing) {
} else if (sp_export_id) {
o_area = o;
} else if (sp_export_area_drawing) {
o = SP_DOCUMENT_ROOT (doc);
o_area = o;
}
if (o) {
if (!SP_IS_ITEM (o)) {
return;
}
if (sp_export_id_only) {
}
if (sp_export_use_hints) {
// retrieve export filename hint
if (fn_hint) {
if (sp_export_png) {
g_warning ("Using export filename from the command line (--export-png). Filename hint %s is ignored.", fn_hint);
} else {
}
} else {
g_warning ("Export filename hint not found for the object.");
}
// retrieve export dpi hints
const gchar *dpi_hint = SP_OBJECT_REPR(o)->attribute("inkscape:export-xdpi"); // only xdpi, ydpi is always the same now
if (dpi_hint) {
g_warning ("Using bitmap dimensions from the command line (--export-dpi, --export-width, or --export-height). DPI hint %s is ignored.", dpi_hint);
} else {
}
} else {
g_warning ("Export DPI hint not found for the object.");
}
}
// write object bbox to area
if (areaMaybe) {
} else {
g_warning("Unable to determine a valid bounding box. Nothing exported.");
return;
}
} else {
return;
}
}
if (sp_export_area) {
/* Try to parse area (given in SVG pixels) */
return;
}
/* Export the whole canvas */
}
// set filename and dpi from options, if not yet set from the hints
if (!filename) {
if (!sp_export_png) {
g_warning ("No export filename given and no filename hint. Nothing exported.");
return;
}
}
return;
}
}
if (sp_export_area_snap) {
}
// default dpi
if (dpi == 0.0) {
}
unsigned long int width = 0;
unsigned long int height = 0;
if (sp_export_width) {
errno=0;
g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX);
return;
}
}
if (sp_export_height) {
errno=0;
g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX);
return;
}
}
if (!sp_export_width) {
}
if (!sp_export_height) {
}
if (sp_export_background) {
// override the page color
} else {
// read from namedview
}
if (sp_export_background_opacity) {
// override opacity
if (value > 1.0) {
} else {
}
}
}
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);
sp_export_png_file(doc, filename, 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);
}
}
/**
*
* \param doc Document to export.
* \param uri URI to export to.
* \param mime MIME type to export as.
*/
{
i++;
}
if (i == o.end())
{
return;
}
if (sp_export_id) {
if (o == NULL) {
return;
}
} else {
}
if (sp_export_area_canvas && sp_export_area_drawing) {
g_warning ("You cannot use --export-area-canvas and --export-area-drawing at the same time; only the former will take effect.");
sp_export_area_drawing = false;
}
if (sp_export_area_drawing) {
} else {
}
if (sp_export_area_canvas) {
if (sp_export_eps) {
g_warning ("EPS cannot have its bounding box extend beyond its content, so if your drawing is smaller than the canvas, --export-area-canvas will clip it to drawing.");
}
} else {
}
if (sp_export_eps) {
try {
} catch (...) {}
}
}
if (sp_export_text_to_path) {
} else {
}
if (sp_export_ignore_filters) {
} else {
}
}
#ifdef WIN32
/**
* Export a document to EMF
*
* \param doc Document to export.
* \param uri URI to export to.
*/
{
i++;
}
if (i == o.end())
{
return;
}
}
#endif //WIN32
#ifdef WIN32
{
bool worked = false;
#ifdef REPLACEARGS_DEBUG
MessageBoxA( NULL, "GetCommandLineW() getting called", "GetCommandLineW", MB_OK | MB_ICONINFORMATION );
#endif // REPLACEARGS_DEBUG
wchar_t* line = GetCommandLineW();
if ( line )
{
#ifdef REPLACEARGS_DEBUG
{
if ( utf8Line )
{
{
}
}
}
#endif // REPLACEARGS_DEBUG
int numArgs = 0;
#ifdef REPLACEARGS_ANSI
// test code for trying things on Win95/98/ME
if ( !parsed )
{
#ifdef REPLACEARGS_DEBUG
MessageBoxA( NULL, "Unable to process command-line. Faking it", "CommandLineToArgvW", MB_OK | MB_ICONINFORMATION );
#endif // REPLACEARGS_DEBUG
int pos = 0;
bool inQuotes = false;
bool inWhitespace = true;
{
if ( inQuotes )
{
{
inQuotes = false;
}
}
{
inQuotes = true;
inWhitespace = false;
}
{
if ( !inWhitespace )
{
inWhitespace = true;
}
}
{
inWhitespace = false;
}
else
{
// consume
}
pos++;
}
#ifdef REPLACEARGS_DEBUG
{
char tmp[256];
}
#endif // REPLACEARGS_DEBUG
int i = 0;
{
}
}
#endif // REPLACEARGS_ANSI
if ( parsed )
{
if ( numArgs > 0 )
{
}
{
if ( wildcarded )
{
#ifdef REPLACEARGS_ANSI
#else
#endif // REPLACEARGS_ANSI
if ( last )
{
last[1] = 0;
}
else
{
base[0] = 0;
}
#ifdef REPLACEARGS_ANSI
{
#else
#endif // REPLACEARGS_ANSI
if ( hf != INVALID_HANDLE_VALUE )
{
do
{
#ifdef REPLACEARGS_ANSI
if ( howMany > 0 )
{
}
#else
#endif // REPLACEARGS_ANSI
} while ( found );
}
else
{
}
#ifdef REPLACEARGS_ANSI
}
#endif // REPLACEARGS_ANSI
delete[] base;
}
else
{
}
}
{
int iz = 0;
{
}
}
for ( int i = 0; i < numArgs; i++ )
{
if ( replacement )
{
#ifdef REPLACEARGS_DEBUG
if ( safe2 )
{
{
char tmp[1024];
}
}
#endif // REPLACEARGS_DEBUG
}
else
{
}
}
// Now push our munged params to be the new argv and argc
{
int iz = 0;
{
}
worked = true;
}
}
#ifdef REPLACEARGS_DEBUG
else
{
MessageBoxA( NULL, "Unable to process command-line", "CommandLineToArgvW", MB_OK | MB_ICONINFORMATION );
}
#endif // REPLACEARGS_DEBUG
}
#ifdef REPLACEARGS_DEBUG
else
{
{
MessageBoxA( NULL, "Unable to fetch result from GetCommandLineW()", "GetCommandLineW", MB_OK | MB_ICONINFORMATION );
}
char* line2 = GetCommandLineA();
if ( line2 )
{
{
{
}
}
}
else
{
MessageBoxA( NULL, "Unable to fetch result from GetCommandLineA()", "GetCommandLineA", MB_OK | MB_ICONINFORMATION );
}
}
#endif // REPLACEARGS_DEBUG
return worked;
}
#endif // WIN32
static GSList *
{
gint a;
switch (a) {
case SP_ARG_FILE: {
}
break;
}
case SP_ARG_VERSION: {
exit(0);
break;
}
case SP_ARG_EXTENSIONDIR: {
exit(0);
break;
}
case SP_ARG_VERB_LIST: {
// This really shouldn't go here, we should init the app.
// But, since we're just exiting in this path, there is
// no harm, and this is really a better place to put
// everything else.
exit(0);
break;
}
case SP_ARG_VERB:
case SP_ARG_SELECT: {
// printf("Adding in: %s\n", arg);
}
break;
}
case POPT_ERROR_BADOPT: {
exit(1);
break;
}
default: {
break;
}
}
}
}
}
return fl;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :