~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/main.cpp

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#define __MAIN_C__
2
 
 
3
1
/** \file
4
2
 * Inkscape - an ambitious vector drawing program
5
3
 *
15
13
 *   Pawel Palucha
16
14
 *   Bryce Harrington <bryce@bryceharrington.com>
17
15
 * ... and various people who have worked with various projects
 
16
 *   Jon A. Cruz <jon@oncruz.org>
 
17
 *   Abhishek Sharma
18
18
 *
19
19
 * Copyright (C) 1999-2004 authors
20
20
 * Copyright (C) 2001-2002 Ximian, Inc.
31
31
// This has to be included prior to anything that includes setjmp.h, it croaks otherwise
32
32
#include <png.h>
33
33
 
34
 
#include <gtk/gtkmessagedialog.h>
 
34
#include <gtk/gtk.h>
35
35
 
36
36
#ifdef HAVE_IEEEFP_H
37
37
#include <ieeefp.h>
51
51
#include <glib/gprintf.h>
52
52
#include <glib-object.h>
53
53
#include <gtk/gtk.h>
54
 
#include <gtk/gtkmain.h>
55
 
#include <gtk/gtksignal.h>
56
 
#include <gtk/gtkwindow.h>
57
 
#include <gtk/gtkbox.h>
58
54
 
59
55
#include "gc-core.h"
60
56
 
100
96
#include <extension/input.h>
101
97
 
102
98
#ifdef WIN32
 
99
#include <windows.h>
103
100
#include "registrytool.h"
104
 
#include "extension/internal/win32.h"
105
 
using Inkscape::Extension::Internal::PrintWin32;
106
101
#endif // WIN32
107
102
 
108
103
#include "extension/init.h"
114
109
#define bind_textdomain_codeset(p,c)
115
110
#endif
116
111
 
117
 
#include "application/application.h"
118
112
#include "main-cmdlineact.h"
119
113
#include "widgets/icon.h"
120
114
#include "ui/widget/panel.h"
208
202
static gboolean sp_query_height = FALSE;
209
203
static gboolean sp_query_all = FALSE;
210
204
static gchar *sp_query_id = NULL;
211
 
static int sp_new_gui = FALSE;
212
205
static gboolean sp_shell = FALSE;
213
206
static gboolean sp_vacuum_defs = FALSE;
214
207
 
648
641
 
649
642
    gboolean use_gui;
650
643
 
651
 
#ifndef WIN32
 
644
#if !defined(WIN32) && !defined(GDK_WINDOWING_QUARTZ)
652
645
    use_gui = (g_getenv("DISPLAY") != NULL);
653
646
#else
654
647
    use_gui = TRUE;
704
697
    }
705
698
 
706
699
#ifdef WIN32
707
 
#ifndef REPLACEARGS_ANSI
708
 
    if ( PrintWin32::is_os_wide() )
709
 
#endif // REPLACEARGS_ANSI
710
700
    {
711
701
        // If the call fails, we'll need to convert charsets
712
702
        needToRecodeParams = !replaceArgs( argc, argv );
713
703
    }
714
704
#endif // WIN32
715
705
 
716
 
    /// \todo  Should this be a static object (see inkscape.cpp)?
717
 
    Inkscape::NSApplication::Application app(argc, argv, use_gui, sp_new_gui);
718
 
 
719
 
    return app.run();
 
706
    int retcode;
 
707
 
 
708
    if (use_gui) {
 
709
        retcode = sp_main_gui(argc, (const char **) argv);
 
710
    } else {
 
711
        retcode = sp_main_console(argc, (const char **) argv);
 
712
    }
 
713
 
 
714
    return retcode;
720
715
}
721
716
 
722
717
 
1020
1015
            g_warning("Specified document %s cannot be opened (does not exist or not a valid SVG file)", filename);
1021
1016
        } else {
1022
1017
            if (sp_vacuum_defs) {
1023
 
                vacuum_document(doc);
 
1018
                doc->vacuumDocument();
1024
1019
            }
1025
1020
            if (sp_vacuum_defs && !sp_export_svg) {
1026
1021
                // save under the name given in the command line
1037
1032
                Inkscape::XML::Node *repr;
1038
1033
                rdoc = sp_repr_document_new("svg:svg");
1039
1034
                repr = rdoc->root();
1040
 
                repr = sp_document_root(doc)->updateRepr(rdoc, repr, SP_OBJECT_WRITE_BUILD);
 
1035
                repr = doc->getRoot()->updateRepr(rdoc, repr, SP_OBJECT_WRITE_BUILD);
1041
1036
                sp_repr_save_rebased_file(repr->document(), sp_export_svg, SP_SVG_NS_URI,
1042
 
                                          doc->base, sp_export_svg);
 
1037
                                          doc->getBase(), sp_export_svg);
1043
1038
            }
1044
1039
            if (sp_export_ps) {
1045
1040
                do_export_ps_pdf(doc, sp_export_ps, "image/x-postscript");
1193
1188
            return;
1194
1189
        }
1195
1190
    } else {
1196
 
        o = SP_DOCUMENT_ROOT(doc);
 
1191
        o = doc->getRoot();
1197
1192
    }
1198
1193
 
1199
1194
    if (o) {
1200
 
        sp_document_ensure_up_to_date (doc);
 
1195
        doc->ensureUpToDate();
1201
1196
        SPItem *item = ((SPItem *) o);
1202
1197
 
1203
 
        // "true" SVG bbox for scripting
1204
 
        Geom::OptRect area = item->getBounds(sp_item_i2doc_affine(item));
 
1198
        // visual bbox in document coords for scripting
 
1199
        Geom::OptRect area = item->documentVisualBounds();
1205
1200
        if (area) {
1206
1201
            Inkscape::SVGOStringStream os;
1207
1202
            if (extent) {
1216
1211
    }
1217
1212
}
1218
1213
 
1219
 
static void
1220
 
do_query_all (SPDocument *doc)
 
1214
static void do_query_all(SPDocument *doc)
1221
1215
{
1222
 
    SPObject *o = NULL;
1223
 
 
1224
 
    o = SP_DOCUMENT_ROOT(doc);
 
1216
    SPObject *o = doc->getRoot();
1225
1217
 
1226
1218
    if (o) {
1227
 
        sp_document_ensure_up_to_date (doc);
 
1219
        doc->ensureUpToDate();
1228
1220
        do_query_all_recurse(o);
1229
1221
    }
1230
1222
}
1234
1226
{
1235
1227
    SPItem *item = ((SPItem *) o);
1236
1228
    if (o->getId() && SP_IS_ITEM(item)) {
1237
 
        Geom::OptRect area = item->getBounds(sp_item_i2doc_affine(item));
 
1229
        Geom::OptRect area = item->documentVisualBounds();
1238
1230
        if (area) {
1239
1231
            Inkscape::SVGOStringStream os;
1240
1232
            os << o->getId();
1274
1266
        SPObject *o_area = NULL;
1275
1267
        if (sp_export_id && sp_export_area_drawing) {
1276
1268
            o = doc->getObjectById(sp_export_id);
1277
 
            o_area = SP_DOCUMENT_ROOT (doc);
 
1269
            o_area = doc->getRoot();
1278
1270
        } else if (sp_export_id) {
1279
1271
            o = doc->getObjectById(sp_export_id);
1280
1272
            o_area = o;
1281
1273
        } else if (sp_export_area_drawing) {
1282
 
            o = SP_DOCUMENT_ROOT (doc);
 
1274
            o = doc->getRoot();
1283
1275
            o_area = o;
1284
1276
        }
1285
1277
 
1298
1290
            if (sp_export_use_hints) {
1299
1291
 
1300
1292
                // retrieve export filename hint
1301
 
                const gchar *fn_hint = SP_OBJECT_REPR(o)->attribute("inkscape:export-filename");
 
1293
                const gchar *fn_hint = o->getRepr()->attribute("inkscape:export-filename");
1302
1294
                if (fn_hint) {
1303
1295
                    if (sp_export_png) {
1304
1296
                        g_warning ("Using export filename from the command line (--export-png). Filename hint %s is ignored.", fn_hint);
1313
1305
                }
1314
1306
 
1315
1307
                // retrieve export dpi hints
1316
 
                const gchar *dpi_hint = SP_OBJECT_REPR(o)->attribute("inkscape:export-xdpi"); // only xdpi, ydpi is always the same now
 
1308
                const gchar *dpi_hint = o->getRepr()->attribute("inkscape:export-xdpi"); // only xdpi, ydpi is always the same now
1317
1309
                if (dpi_hint) {
1318
1310
                    if (sp_export_dpi || sp_export_width || sp_export_height) {
1319
1311
                        g_warning ("Using bitmap dimensions from the command line (--export-dpi, --export-width, or --export-height). DPI hint %s is ignored.", dpi_hint);
1327
1319
            }
1328
1320
 
1329
1321
            // write object bbox to area
1330
 
            sp_document_ensure_up_to_date (doc);
1331
 
            Geom::OptRect areaMaybe;
1332
 
            sp_item_invoke_bbox((SPItem *) o_area, areaMaybe, sp_item_i2d_affine((SPItem *) o_area), TRUE);
 
1322
            doc->ensureUpToDate();
 
1323
            Geom::OptRect areaMaybe = static_cast<SPItem *>(o_area)->desktopVisualBounds();
1333
1324
            if (areaMaybe) {
1334
1325
                area = *areaMaybe;
1335
1326
            } else {
1345
1336
    if (sp_export_area) {
1346
1337
        /* Try to parse area (given in SVG pixels) */
1347
1338
        gdouble x0,y0,x1,y1;
1348
 
        if (!sscanf(sp_export_area, "%lg:%lg:%lg:%lg", &x0, &y0, &x1, &y1) == 4) {
 
1339
        if (sscanf(sp_export_area, "%lg:%lg:%lg:%lg", &x0, &y0, &x1, &y1) != 4) {
1349
1340
            g_warning("Cannot parse export area '%s'; use 'x0:y0:x1:y1'. Nothing exported.", sp_export_area);
1350
1341
            return;
1351
1342
        }
1352
1343
        area = Geom::Rect(Geom::Interval(x0,x1), Geom::Interval(y0,y1));
1353
1344
    } else if (sp_export_area_page || !(sp_export_id || sp_export_area_drawing)) {
1354
1345
        /* Export the whole page: note: Inkscape uses 'page' in all menus and dialogs, not 'canvas' */
1355
 
        sp_document_ensure_up_to_date (doc);
1356
 
        Geom::Point origin (SP_ROOT(doc->root)->x.computed, SP_ROOT(doc->root)->y.computed);
1357
 
        area = Geom::Rect(origin, origin + sp_document_dimensions(doc));
 
1346
        doc->ensureUpToDate();
 
1347
        Geom::Point origin(doc->getRoot()->x.computed, doc->getRoot()->y.computed);
 
1348
        area = Geom::Rect(origin, origin + doc->getDimensions());
1358
1349
    }
1359
1350
 
1360
1351
    // set filename and dpi from options, if not yet set from the hints
1448
1439
    gchar *path = 0;
1449
1440
    if (filename_from_hint) {
1450
1441
        //Make relative paths go from the document location, if possible:
1451
 
        if (!g_path_is_absolute(filename) && doc->uri) {
1452
 
            gchar *dirname = g_path_get_dirname(doc->uri);
 
1442
        if (!g_path_is_absolute(filename) && doc->getURI()) {
 
1443
            gchar *dirname = g_path_get_dirname(doc->getURI());
1453
1444
            if (dirname) {
1454
1445
                path = g_build_filename(dirname, filename, NULL);
1455
1446
                g_free(dirname);