file.cpp revision 535b1596de71acb960a629b0f34f0d2171a34348
e781423d621c888bfbcfab74512d797385606aa1dvlierop * File/Print operations
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Lauris Kaplinski <lauris@kaplinski.com>
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Chema Celorio <chema@celorio.com>
e781423d621c888bfbcfab74512d797385606aa1dvlierop * bulia byak <buliabyak@users.sf.net>
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Copyright (C) 1999-2005 Authors
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Copyright (C) 2001-2002 Ximian, Inc.
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Copyright (C) 2004 David Turner
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop * Released under GNU GPL, read the file 'COPYING' for more information
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop * Note: This file needs to be cleaned up extensively.
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlierop * What it probably needs is to have one .h file for
e781423d621c888bfbcfab74512d797385606aa1dvlierop * the API, and two or more .cpp files for the implementations.
e781423d621c888bfbcfab74512d797385606aa1dvlierop/* #include "extension/menu.h" */
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof Kosiński * 'Current' paths. Used to remember which directory
cd8e8082c747cc529d5bf595b4102e88224a1811Krzysztof Kosiński * had the last file accessed.
2b7ee786ac3f40bb6b0d6e19f565b802f29f50e0dvlierop * Static globals are evil. This will be gone soon
e781423d621c888bfbcfab74512d797385606aa1dvlierop * as C++ification continues
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop//#define INK_DUMP_FILENAME_CONV 1
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lierop//#define INK_DUMP_FOPEN 1
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lieropvoid dump_str(gchar const *str, gchar const *prefix);
5b4319e0715220ba39530755e9d971cbf7fee47fDiederik van Lieropvoid dump_ustr(Glib::ustring const &ustr);
e781423d621c888bfbcfab74512d797385606aa1dvlierop/*######################
e781423d621c888bfbcfab74512d797385606aa1dvlierop######################*/
55dd1351535fdbc7d4087cef62b2c3f59de8726edvlierop * Create a blank document and add it to the desktop
11614aeee42f0b626bd7e3f929d9119c59f7c3bddvlierop SPDocument *doc = sp_document_new(templ, TRUE, true);
e781423d621c888bfbcfab74512d797385606aa1dvlierop if (Inkscape::NSApplication::Application::getNewGui())
e781423d621c888bfbcfab74512d797385606aa1dvlierop dt = Inkscape::NSApplication::Editor::createDesktop (doc);
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL));
e781423d621c888bfbcfab74512d797385606aa1dvlierop sources.push_back( profile_path("templates") ); // first try user's local dir
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
e781423d621c888bfbcfab74512d797385606aa1dvlierop if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) {
e781423d621c888bfbcfab74512d797385606aa1dvlierop // TRANSLATORS: default.svg is localizable - this is the name of the default document
11614aeee42f0b626bd7e3f929d9119c59f7c3bddvlierop // template. This way you can localize the default pagesize, translate the name of
e781423d621c888bfbcfab74512d797385606aa1dvlierop // the default layer, etc. If you wish to localize this file, please create a
e781423d621c888bfbcfab74512d797385606aa1dvlierop // localized share/templates/default.xx.svg file, where xx is your language code.
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop char *default_template = g_build_filename(dirname, _("default.svg"), NULL);
e781423d621c888bfbcfab74512d797385606aa1dvlierop if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) {
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop/*######################
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop######################*/
4c8b4484d62b2a47d96b62a8dff90e2b9124edcaDiederik van Lierop * Perform document closures preceding an exit()
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop // no need to call inkscape_exit here; last document being closed will take care of that
71c8857afc501c5e737bce6022fd9ac810d94c05dvlierop/*######################
e781423d621c888bfbcfab74512d797385606aa1dvlierop######################*/
e781423d621c888bfbcfab74512d797385606aa1dvlierop * Open a file, add the document to the desktop
e781423d621c888bfbcfab74512d797385606aa1dvlierop * \param replace_empty if true, and the current desktop is empty, this document
e781423d621c888bfbcfab74512d797385606aa1dvlierop * will replace the empty one.
e781423d621c888bfbcfab74512d797385606aa1dvlieropsp_file_open(gchar const *uri, Inkscape::Extension::Extension *key, bool add_to_recent, bool replace_empty)
if (doc) {
if (add_to_recent) {
return TRUE;
return FALSE;
if (!uri) {
desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved yet. Cannot revert."));
bool do_revert = true;
gchar *text = g_strdup_printf(_("Changes will be lost! Are you sure you want to reload document %s?"), uri);
if (!response) {
do_revert = false;
bool reverted;
if (do_revert) {
reverted = false;
if (reverted) {
for (unsigned i = 0; i < total; i++) {
if (i < dataLen) {
if (i < byteLen) {
if ( i < cstrLen ) {
if (open_path && !Inkscape::IO::file_test(open_path, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
if (!openDialogInstance) {
(char const *)open_path,
: NULL );
if (!success) return;
#ifdef INK_DUMP_FILENAME_CONV
#ifdef INK_DUMP_FILENAME_CONV
&error);
#ifdef INK_DUMP_FILENAME_CONV
#ifdef INK_DUMP_FILENAME_CONV
if (fileName) {
#ifdef INK_DUMP_FILENAME_CONV
&error);
#ifdef INK_DUMP_FILENAME_CONV
if (diff > 0) {
diff),
diff);
return FALSE;
gchar *text = g_strdup_printf(_("No Inkscape extension found to save document (%s). This may have been caused by an unknown filename extension."), safeUri);
return FALSE;
return FALSE;
return TRUE;
char const *filename_extension;
char *temp_filename;
extension = dynamic_cast<Inkscape::Extension::Output *>(Inkscape::Extension::db.get(default_extension));
if (save_path && !Inkscape::IO::file_test(save_path, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) {
#ifdef INK_DUMP_FILENAME_CONV
#ifdef INK_DUMP_FILENAME_CONV
if (!saveDialogInstance) {
(char const *) save_loc,
} // FIXME: else (i.e. if reshowing an already shown dialog) save_loc is not used, it thus always displays the previously opened dir
: NULL );
if (!success) {
return success;
#ifdef INK_DUMP_FILENAME_CONV
&error);
#ifdef INK_DUMP_FILENAME_CONV
if (success) {
return success;
return FALSE;
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No changes need to be saved."));
return success;
if (!SP_ACTIVE_DOCUMENT)
if (!SP_ACTIVE_DOCUMENT)
// const gchar *docbase = (sp_repr_document_root( sp_repr_document( repr ))->attribute("sodipodi:docbase" );
// FIXME: in case of id conflict, newly added thing will be re-ided and thus likely break a reference to it from imported stuff
items_count ++;
for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (desktop) {
for (SPObject *child = sp_object_first_child(SP_DOCUMENT_ROOT(doc)); child != NULL; child = SP_OBJECT_NEXT(child) ) {
if (desktop) {
if (!doc)
if (!importDialogInstance) {
(char const *)import_path,
: NULL );
if (!success) return;
if (fileName) {
#ifdef INK_DUMP_FILENAME_CONV
&error);
#ifdef INK_DUMP_FILENAME_CONV
struct SPEBP {
guchar r, g, b, a;
unsigned (*status)(float, void *);
void *data;
nr_arena_item_invoke_update(ebp->root, &bbox, &gc, NR_ARENA_ITEM_STATE_ALL, NR_ARENA_ITEM_STATE_NONE);
for (int r = 0; r < num_rows; r++) {
*p++ = ebp->r;
*p++ = ebp->g;
*p++ = ebp->b;
*p++ = ebp->a;
for (int r = 0; r < num_rows; r++) {
return num_rows;
if (SP_IS_ITEM(o)
&& !SP_IS_DEFS(o)
&& !SP_IS_ROOT(o)
&& !SP_IS_GROUP(o)
unsigned long bgcolor,
unsigned (*status)(float, void *),
return FALSE;
if (items_only) {
write_status = sp_png_write_rgba_striped(filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
write_status = sp_png_write_rgba_striped(filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp);
return write_status;
if (doc)
if (doc)
if (doc)
"foo.svg",
"file:foo.svg",
"bar\xe1\x84\x92.svg",
for ( int i = 0; things[i]; i++ )
things[i],
str );
things[i],
str );