main.cpp revision a486e5614854c20a8acfb61041d3a625f4bc51d1
#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"
#include <gtk/gtkmessagedialog.h>
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#include <string.h>
#include <locale.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 "slideshow.h"
#include "color.h"
#include "sp-item.h"
#include "sp-root.h"
#include "unit-constants.h"
#include "svg/stringstream.h"
#include "inkscape-private.h"
#include "inkscape-stock.h"
#include "inkscape_version.h"
#include "sp-namedview.h"
#include "sp-guide.h"
#include "sp-object-repr.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"
enum {
};
static void do_query_dimension (SPDocument *doc, bool extent, NR::Dim2 const axis, const gchar *id);
static int sp_new_gui = FALSE;
#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-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 (overrides export-area)"),
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-text-to-path", 'T',
N_("Convert text object to paths on export (EPS)"),
NULL},
{"export-bbox-page", 'B',
N_("Export files with the bounding box set to the page size (EPS)"),
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-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},
{"slideshow", 's',
NULL},
{"new-gui", 'G',
N_("Use the new Gtkmm GUI interface"),
NULL},
{"vacuum-defs", 0,
N_("Remove unused definitions from the defs section(s) of the document"),
NULL},
};
static bool needToRecodeParams = true;
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 ENABLE_NLS
#ifdef WIN32
rt.setPathInfo();
#else
#ifdef ENABLE_BINRELOC
#else
#endif
#endif
#endif
#ifdef ENABLE_NLS
#endif
#ifndef WIN32
#else
/*
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
*/
/// \todo FIXME BROKEN - non-UTF-8 sneaks in here.
#endif
for (int i = 1; i < argc; i++) {
)
{
/* main_console handles any exports -- not the gui */
break;
break;
sp_new_gui = TRUE;
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;
}
int
{
/* Set default icon */
if (Inkscape::IO::file_test(filename, (GFileTest)(G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))) {
}
filename = 0;
if (!sp_global_slideshow) {
/// \todo FIXME BROKEN - non-UTF-8 sneaks in here.
inkscape_application_init(argv[0], true);
while (fl) {
}
}
if (create_new) {
}
} else {
if (fl) {
/// \todo FIXME BROKEN - non-UTF-8 sneaks in here.
inkscape_application_init(argv[0], true);
} else {
g_warning ("No slides to display");
exit(0);
}
}
main_instance.run();
#ifdef WIN32
//We might not need anything here
//sp_win32_finish(); <-- this is a NOP func
#endif
return 0;
}
int
{
/* 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);
while (fl) {
doc = Inkscape::Extension::open(Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), (gchar *)fl->data);
}
} 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_svg) {
}
if (sp_export_ps) {
}
if (sp_export_eps) {
}
if (sp_query_width || sp_query_height) {
} else if (sp_query_x || sp_query_y) {
}
}
}
return 0;
}
static void
{
if (id) {
if (o) {
if (!SP_IS_ITEM (o)) {
return;
}
} else {
return;
}
} else {
o = SP_DOCUMENT_ROOT(doc);
}
if (o) {
if (extent) {
} else {
}
}
}
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) {
} else if (sp_export_area_drawing) {
o = SP_DOCUMENT_ROOT (doc);
}
if (o) {
if (!SP_IS_ITEM (o)) {
return;
}
if (sp_export_area) {
}
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
} else {
return;
}
} else if (sp_export_area) {
/* Try to parse area (given in SVG pixels) */
return;
}
return;
}
} else {
/* 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)
if (sp_export_width) {
return;
}
}
if (sp_export_height) {
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 %d x %d pixels (%g dpi)\n", area.x0, area.y0, area.x1, area.y1, width, height, dpi);
sp_export_png_file(doc, filename, area.x0, area.y0, area.x1, area.y1, width, height, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL);
} else {
g_warning("Calculated bitmap dimensions %d %d are out of range (1 - 65535). Nothing exported.", width, height);
}
}
/**
* Perform an export of either PS or EPS.
*
* \param doc Document to export.
* \param uri URI to export to.
* \param mime MIME type to export as.
*/
{
/** \todo
* FIXME: I've no idea if this is the `proper' way to do this.
* If anyone feels qualified to say that it is, perhaps they
* could remove this comment.
*/
i++;
}
if (i == o.end())
{
g_warning ("Could not find an extension to export this file.");
return;
}
bool old_text_to_path = false;
bool old_bbox_page = false;
try {
}
catch (...) {
g_warning ("Could not set export-text-to-path option for this export.");
}
try {
}
catch (...) {
g_warning ("Could not set export-bbox-page option for this export.");
}
try {
}
catch (...) {
}
}
#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
WIN32_FIND_DATAA data = {0};
#else
WIN32_FIND_DATAW data = {0};
#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;
while ((a = poptGetNextOpt(ctx)) >= 0) {
switch (a) {
case SP_ARG_FILE: {
}
break;
}
case SP_ARG_VERSION: {
exit(0);
break;
}
case SP_ARG_EXTENSIONDIR: {
exit(0);
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 :