From df46631f0e183b8e4cc6f87b45ae8a4cfcc33a78 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Fri, 21 Jun 2013 22:45:22 +0200 Subject: odf metadata - let's begin with a first step to full ODF compatibility (bzr r12383) --- src/extension/internal/odf.cpp | 44 ++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/extension') diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index b23378fc3..9f745cdea 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -1191,16 +1191,29 @@ bool OdfOutput::writeMeta(ZipFile &zf) { creator = iter->second; } - Glib::ustring date = ""; + + Glib::ustring date; + Glib::ustring moddate; + char buf [80]; + time_t rawtime; + struct tm * timeinfo; + time (&rawtime); + timeinfo = localtime (&rawtime); + strftime (buf,80,"%Y-%m-%d %H:%M:%S",timeinfo); + moddate = Glib::ustring(buf); + iter = metadata.find("dc:date"); if (iter != metadata.end()) { date = iter->second; } + else + { + date = moddate; + } outs.writeString("\n"); outs.writeString("\n"); - outs.writeString("\n"); outs.writeString("\n"); outs.writeString("\n"); - outs.writeString("\n"); outs.writeString("\n"); outs.writeString("\n"); - Glib::ustring tmp = Glib::ustring(" ") + InkscapeVersion + "\n"; + Glib::ustring tmp = Glib::ustring::compose(" %1\n", InkscapeVersion); + tmp += Glib::ustring::compose(" %1\n", creator); + tmp += Glib::ustring::compose(" %1\n", date); + tmp += Glib::ustring::compose(" %1\n", moddate); outs.writeUString(tmp); - outs.printf(" %s\n", creator.c_str()); - outs.printf(" %s\n", date.c_str()); for (iter = metadata.begin() ; iter != metadata.end() ; ++iter) { Glib::ustring name = iter->first; @@ -1235,18 +1248,15 @@ bool OdfOutput::writeMeta(ZipFile &zf) outs.writeUString(tmp); } } - outs.writeString(" 2\n"); - outs.writeString(" PT56S\n"); - outs.writeString(" \n"); - outs.writeString(" \n"); - outs.writeString(" \n"); - outs.writeString(" \n"); - outs.writeString(" \n"); + // outs.writeString(" 2\n"); + // outs.writeString(" PT56S\n"); + // outs.writeString(" \n"); + // outs.writeString(" \n"); + // outs.writeString(" \n"); + // outs.writeString(" \n"); + // outs.writeString(" \n"); outs.writeString("\n"); outs.writeString("\n"); - outs.writeString("\n"); - outs.writeString("\n"); - outs.close(); //Make our entry @@ -1533,7 +1543,7 @@ bool OdfOutput::processGradient(SPItem *item, gradientTable.push_back(gi); gradientLookupTable[id] = gradientName; - int gradientCount = gradientTable.size(); + // int gradientCount = gradientTable.size(); char buf[128]; if (gi.style == "linear") { -- cgit v1.2.3 From c3a160589a9cb41c70a56e5e7b66a65857a0d10e Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Mon, 1 Jul 2013 21:04:32 +0100 Subject: Factored layer model out into new Inkscape::LayerModel class. This allows Inkscape::Selection to use a LayerModel that is not associated with a UI. Changed the interface of verbs (SPAction) to use a new ActionContext rather than UI::View::View, again so that verbs may be used in a console mode. Modified boolean operation verbs to work in console-only mode. Fixed up DESKTOP_IS_ACTIVE macro to work in the case of no desktops. Modified main.cpp to process selections and verbs in no-GUI mode. Other changes are all consequences of the SPDesktop, Selection and LayerModel interface changes. (bzr r12387.1.1) --- src/extension/dbus/document-interface.cpp | 5 +++-- src/extension/effect.cpp | 4 ++-- src/extension/effect.h | 2 +- src/extension/internal/bluredge.cpp | 5 +++-- src/extension/internal/filter/filter-all.cpp | 0 5 files changed, 9 insertions(+), 7 deletions(-) mode change 100755 => 100644 src/extension/internal/filter/filter-all.cpp (limited to 'src/extension') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 56d1dfdbd..bdf1fa98c 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -30,6 +30,7 @@ #include "extension/system.h" //IO #include "file.h" //IO #include "helper/action.h" //sp_action_perform +#include "helper/action-context.h" #include "inkscape.h" //inkscape_find_desktop_by_dkey, activate desktops #include "layer-fns.h" //LPOS_BELOW #include "live_effects/parameter/text.h" //text @@ -263,7 +264,7 @@ dbus_call_verb (DocumentInterface *object, int verbid, GError **error) if ( desk2 ) { Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); if ( verb ) { - SPAction *action = verb->get_action(desk2); + SPAction *action = verb->get_action(Inkscape::ActionContext(desk2)); if ( action ) { //if (!object->updates) //document_interface_pause_updates (object, error); @@ -342,7 +343,7 @@ document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError * if ( desk2 ) { Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid ); if ( verb ) { - SPAction *action = verb->get_action(desk2); + SPAction *action = verb->get_action(Inkscape::ActionContext(desk2)); if ( action ) { sp_action_perform( action, NULL ); if (object->updates) { diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 1df8002ad..22c5e4989 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -359,9 +359,9 @@ Effect::set_pref_dialog (PrefDialog * prefdialog) } SPAction * -Effect::EffectVerb::make_action (Inkscape::UI::View::View * view) +Effect::EffectVerb::make_action (Inkscape::ActionContext const & context) { - return make_action_helper(view, &perform, static_cast(this)); + return make_action_helper(context, &perform, static_cast(this)); } /** \brief Decode the verb code and take appropriate action */ diff --git a/src/extension/effect.h b/src/extension/effect.h index 193b90a97..a14cc6e7d 100644 --- a/src/extension/effect.h +++ b/src/extension/effect.h @@ -58,7 +58,7 @@ class Effect : public Extension { /** \brief Name with elipses if that makes sense */ gchar * _elip_name; protected: - virtual SPAction * make_action (Inkscape::UI::View::View * view); + virtual SPAction * make_action (Inkscape::ActionContext const & context); public: /** \brief Use the Verb initializer with the same parameters. */ EffectVerb(gchar const * id, diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 8f1e07211..a3d2fd6e5 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -17,6 +17,7 @@ #include "document.h" #include "selection.h" #include "helper/action.h" +#include "helper/action-context.h" #include "preferences.h" #include "path-chemistry.h" #include "sp-item.h" @@ -99,10 +100,10 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View /* Doing an inset here folks */ offset *= -1.0; prefs->setDoubleUnit("/options/defaultoffsetwidth/value", offset, "px"); - sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_INSET)->get_action(desktop), NULL); + sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_INSET)->get_action(Inkscape::ActionContext(desktop)), NULL); } else if (offset > 0.0) { prefs->setDoubleUnit("/options/defaultoffsetwidth/value", offset, "px"); - sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_OFFSET)->get_action(desktop), NULL); + sp_action_perform(Inkscape::Verb::get(SP_VERB_SELECTION_OFFSET)->get_action(Inkscape::ActionContext(desktop)), NULL); } selection->clear(); diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp old mode 100755 new mode 100644 -- cgit v1.2.3 From 2a53d44964f9105ce0f9c8725853150dc5360096 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Mon, 1 Jul 2013 22:27:23 +0100 Subject: Added error messages when attempting to use verbs requiring GUI in console (--without-gui) mode. (bzr r12387.1.3) --- src/extension/effect.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/extension') diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 22c5e4989..93b1bb91d 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -369,12 +369,15 @@ void Effect::EffectVerb::perform( SPAction *action, void * data ) { Inkscape::UI::View::View * current_view = sp_action_get_view(action); + if (current_view == NULL) { + show_gui_required_message(action); + return; + } // SPDocument * current_document = current_view->doc; Effect::EffectVerb * ev = reinterpret_cast(data); Effect * effect = ev->_effect; if (effect == NULL) return; - if (current_view == NULL) return; if (ev->_showPrefs) { effect->prefs(current_view); -- cgit v1.2.3 From 09ce234c1fc367a2607936e6cf106cb24c60e94f Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Wed, 3 Jul 2013 20:06:11 +0100 Subject: Modified dbus interface so that it works in console mode (--dbus-listen) Modified action context setup so that in console mode, when a document is added to the main inkscape app instance, it gets a selection model and layer model automatically set up for it Made a couple more verbs work in console mode (bzr r12387.1.4) --- src/extension/dbus/application-interface.cpp | 9 + src/extension/dbus/application-interface.h | 4 + src/extension/dbus/application-interface.xml | 18 +- src/extension/dbus/dbus-init.cpp | 40 ++- src/extension/dbus/dbus-init.h | 5 +- src/extension/dbus/document-interface.cpp | 361 +++++++++++++++------------ src/extension/dbus/document-interface.h | 10 +- 7 files changed, 285 insertions(+), 162 deletions(-) (limited to 'src/extension') diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp index 8ee7bd12f..399e1b244 100644 --- a/src/extension/dbus/application-interface.cpp +++ b/src/extension/dbus/application-interface.cpp @@ -18,6 +18,7 @@ #include "application-interface.h" #include #include "dbus-init.h" +#include "file.h" G_DEFINE_TYPE(ApplicationInterface, application_interface, G_TYPE_OBJECT) @@ -131,6 +132,7 @@ application_interface_desktop_close_all (ApplicationInterface *object, gboolean application_interface_exit (ApplicationInterface *object, GError **error) { + sp_file_exit(); return TRUE; } @@ -144,6 +146,13 @@ gchar* application_interface_document_new (ApplicationInterface *object, return (gchar*)Inkscape::Extension::Dbus::init_document(); } +gchar* +application_interface_get_active_document(ApplicationInterface *object, + GError **error) +{ + return (gchar*)Inkscape::Extension::Dbus::init_active_document(); +} + gchar** application_interface_get_document_list (ApplicationInterface *object) { diff --git a/src/extension/dbus/application-interface.h b/src/extension/dbus/application-interface.h index 88219a6b0..b01fee912 100644 --- a/src/extension/dbus/application-interface.h +++ b/src/extension/dbus/application-interface.h @@ -97,6 +97,10 @@ gchar* application_interface_document_new (ApplicationInterface *object, GError **error); +gchar* +application_interface_get_active_document(ApplicationInterface *object, + GError **error); + gchar** application_interface_get_document_list (ApplicationInterface *object); diff --git a/src/extension/dbus/application-interface.xml b/src/extension/dbus/application-interface.xml index ee2c4837b..4185c7e53 100644 --- a/src/extension/dbus/application-interface.xml +++ b/src/extension/dbus/application-interface.xml @@ -32,7 +32,7 @@ - Create a new document interface and return it's location. + Create a new document interface and return its location. @@ -59,7 +59,7 @@ - Exit Inkscape without saving. Fairly straightforward. + Exit Inkscape without saving (in GUI mode). Fairly straightforward. @@ -76,6 +76,20 @@ Originally, there were going to be two interfaces. A desktop and a document. Desktops would be used when the user wanted to see the result of their code and documents would be used when less overhead was desired. Unfortunately as more and more of the code can to rely on the desktop and it's associated support code (including selections and verbs) the document interface was looking more and more limited. Ultimately I decided to just go with the desktop interface since I didn't have a compelling reason for keeping the other one and having two similar interfaces could be very confusing. The desktop interface inherited the document name because I believe it's more familiar to people. Perhaps it would be best to have an option as to whether or not to create a window and fail with a good error message when they call a function that requires one. Or have a second interface for different use cases but have it be completely different, rather than a subset of the first if there are use cases that support it. + UPDATE: 3rd July 2013, Eric Greveson: After having done some initial work to attempt to decouple Inkscape "verbs" from desktops, it is now possible to run a limited subset of actions in command-line mode (with a selection model and document, but no desktop). I believe that the "single document interface" approach, with some functions that may require a GUI, is the better path, and so document interfaces without a desktop are now possible. Most functions still require the desktop to work, though, with the notable exception of selection methods and Boolean operations. + + + + + + + + This string can be used to connect to the current active document. + + + + + Get the location of the current active document (e.g. when running in console mode, when desktops are not available). diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index 9ff6897e5..96d72c0f6 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -108,7 +108,11 @@ init_document (void) { doc = SPDocument::createNewDoc(NULL, 1, TRUE); std::string name("/org/inkscape/"); - name.append(doc->getName()); + // This only works because a new document's name happens to contain + // only valid DBus characters [A-Z][a-z][0-9]_ + // TODO: use the document->serial() instead, like below, and similar to + // how desktops work? + name.append(doc->getName()); std::replace(name.begin(), name.end(), ' ', '_'); connection = dbus_get_connection(); @@ -122,6 +126,38 @@ init_document (void) { return strdup(name.c_str()); } //init_document +gchar * +init_active_document() +{ + SPDocument *doc = inkscape_active_document(); + if (!doc) { + return NULL; + } + + // Document name is not suitable for DBus name, as it might contain invalid chars + std::string name("/org/inkscape/document_"); + std::stringstream ss; + ss << doc->serial(); + name.append(ss.str()); + + DBusGConnection *connection = dbus_get_connection(); + DBusGProxy *proxy = dbus_get_proxy(connection); + + // Has the active document already been registered? + if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { + // No - register it + DocumentInterface *obj = (DocumentInterface*) dbus_register_object (connection, + proxy, + TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, + name.c_str()); + + // Set the document info for this interface + obj->context = inkscape_active_action_context(); + } + return strdup(name.c_str()); +} + gchar * dbus_init_desktop_interface (SPDesktop * dt) { @@ -142,7 +178,7 @@ dbus_init_desktop_interface (SPDesktop * dt) obj = (DocumentInterface*) dbus_register_object (connection, proxy, TYPE_DOCUMENT_INTERFACE, &dbus_glib_document_interface_object_info, name.c_str()); - obj->desk = dt; + obj->context = Inkscape::ActionContext(dt); obj->updates = TRUE; dt->dbus_document_interface=obj; return strdup(name.c_str()); diff --git a/src/extension/dbus/dbus-init.h b/src/extension/dbus/dbus-init.h index 025011f28..486e55b86 100644 --- a/src/extension/dbus/dbus-init.h +++ b/src/extension/dbus/dbus-init.h @@ -10,8 +10,7 @@ #ifndef INKSCAPE_EXTENSION_DBUS_INIT_H__ #define INKSCAPE_EXTENSION_DBUS_INIT_H__ -#include "desktop.h" - +class SPDesktop; namespace Inkscape { namespace Extension { @@ -23,6 +22,8 @@ void init (void); gchar * init_document (void); +gchar * init_active_document (); + gchar * init_desktop (void); gchar * dbus_init_desktop_interface (SPDesktop * dt); diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index bdf1fa98c..f0cc71de1 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -20,6 +20,7 @@ #include "application-interface.h" #include #include +#include "desktop.h" #include "desktop-handles.h" //sp_desktop_document() #include "desktop-style.h" //sp_desktop_get_style #include "display/canvas-text.h" //text @@ -33,6 +34,7 @@ #include "helper/action-context.h" #include "inkscape.h" //inkscape_find_desktop_by_dkey, activate desktops #include "layer-fns.h" //LPOS_BELOW +#include "layer-model.h" #include "live_effects/parameter/text.h" //text #include "print.h" //IO #include "selection-chemistry.h"// lots of selection functions @@ -92,12 +94,12 @@ * place to adjust things. */ Inkscape::XML::Node * -get_repr_by_name (SPDesktop *desk, gchar *name, GError **error) +get_repr_by_name (SPDocument *doc, gchar *name, GError **error) { /* ALTERNATIVE (is this faster if only repr is needed?) Inkscape::XML::Node *node = sp_repr_lookup_name((doc->root)->repr, name); */ - SPObject * obj = sp_desktop_document(desk)->getObjectById(name); + SPObject * obj = doc->getObjectById(name); if (!obj) { g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name); @@ -110,9 +112,9 @@ get_repr_by_name (SPDesktop *desk, gchar *name, GError **error) * See comment for get_repr_by_name, above. */ SPObject * -get_object_by_name (SPDesktop *desk, gchar *name, GError **error) +get_object_by_name (SPDocument *doc, gchar *name, GError **error) { - SPObject * obj = sp_desktop_document(desk)->getObjectById(name); + SPObject * obj = doc->getObjectById(name); if (!obj) { g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name); @@ -184,12 +186,11 @@ selection_get_center_y (Inkscape::Selection *sel){ * they might see the selection box flicker if used in a loop. */ const GSList * -selection_swap(SPDesktop *desk, gchar *name, GError **error) +selection_swap(Inkscape::Selection *sel, gchar *name, GError **error) { - Inkscape::Selection *sel = sp_desktop_selection(desk); const GSList *oldsel = g_slist_copy((GSList *)sel->list()); - sel->set(get_object_by_name(desk, name, error)); + sel->set(get_object_by_name(sel->layerModel()->getDocument(), name, error)); return oldsel; } @@ -197,9 +198,8 @@ selection_swap(SPDesktop *desk, gchar *name, GError **error) * See selection_swap, above */ void -selection_restore(SPDesktop *desk, const GSList * oldsel) +selection_restore(Inkscape::Selection *sel, const GSList * oldsel) { - Inkscape::Selection *sel = sp_desktop_selection(desk); sel->setList(oldsel); } @@ -207,9 +207,8 @@ selection_restore(SPDesktop *desk, const GSList * oldsel) * Shortcut for creating a Node. */ Inkscape::XML::Node * -dbus_create_node (SPDesktop *desk, const gchar *type) +dbus_create_node (SPDocument *doc, const gchar *type) { - SPDocument * doc = sp_desktop_document (desk); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); return xml_doc->createElement(type); @@ -224,8 +223,10 @@ dbus_create_node (SPDesktop *desk, const gchar *type) */ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inkscape::XML::Node *newNode, gchar *desc) { - SPCSSAttr *style = sp_desktop_get_style(object->desk, TRUE); - + SPCSSAttr *style = NULL; + if (object->context.getDesktop()) { + style = sp_desktop_get_style(object->context.getDesktop(), TRUE); + } if (style) { Glib::ustring str; sp_repr_css_write_string(style, str); @@ -235,11 +236,11 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks newNode->setAttribute("style", "fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none", TRUE); } - object->desk->currentLayer()->appendChildRepr(newNode); - object->desk->currentLayer()->updateRepr(); + object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); + object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); if (object->updates) { - Inkscape::DocumentUndo::done(sp_desktop_document(object->desk), 0, (gchar *)desc); + Inkscape::DocumentUndo::done(object->context.getDocument(), 0, (gchar *)desc); //} else { //document_interface_pause_updates(object, error); } @@ -258,23 +259,22 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks gboolean dbus_call_verb (DocumentInterface *object, int verbid, GError **error) { - SPDesktop *desk2 = object->desk; - desktop_ensure_active (desk2); - - if ( desk2 ) { - Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); - if ( verb ) { - SPAction *action = verb->get_action(Inkscape::ActionContext(desk2)); - if ( action ) { - //if (!object->updates) - //document_interface_pause_updates (object, error); - sp_action_perform( action, NULL ); - if (object->updates) - Inkscape::DocumentUndo::done(sp_desktop_document(desk2), verb->get_code(), g_strdup(verb->get_tip())); - //if (!object->updates) - //document_interface_pause_updates (object, error); - return TRUE; - } + SPDesktop *desk = object->context.getDesktop(); + if ( desk ) { + desktop_ensure_active (desk); + } + Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); + if ( verb ) { + SPAction *action = verb->get_action(object->context); + if ( action ) { + //if (!object->updates) + //document_interface_pause_updates (object, error); + sp_action_perform( action, NULL ); + if (object->updates) + Inkscape::DocumentUndo::done(object->context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); + //if (!object->updates) + //document_interface_pause_updates (object, error); + return TRUE; } } g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb failed to execute"); @@ -313,7 +313,7 @@ document_interface_class_init (DocumentInterfaceClass *klass) static void document_interface_init (DocumentInterface *object) { - object->desk = NULL; + object->context = Inkscape::ActionContext(); } @@ -331,26 +331,26 @@ document_interface_new (void) gboolean document_interface_delete_all(DocumentInterface *object, GError ** /*error*/) { - sp_edit_clear_all(object->desk); + sp_edit_clear_all(object->context.getSelection()); return TRUE; } gboolean document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error) { - SPDesktop *desk2 = object->desk; - desktop_ensure_active (object->desk); - if ( desk2 ) { - Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid ); - if ( verb ) { - SPAction *action = verb->get_action(Inkscape::ActionContext(desk2)); - if ( action ) { - sp_action_perform( action, NULL ); - if (object->updates) { - Inkscape::DocumentUndo::done(sp_desktop_document(desk2), verb->get_code(), g_strdup(verb->get_tip())); - } - return TRUE; + SPDesktop *desk = object->context.getDesktop(); + if ( desk ) { + desktop_ensure_active (desk); + } + Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid ); + if ( verb ) { + SPAction *action = verb->get_action(object->context); + if ( action ) { + sp_action_perform( action, NULL ); + if (object->updates) { + Inkscape::DocumentUndo::done(object->context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); } + return TRUE; } } g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb '%s' failed to execute or was not found.", verbid); @@ -368,7 +368,7 @@ document_interface_rectangle (DocumentInterface *object, int x, int y, { - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:rect"); + Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:rect"); sp_repr_set_int(newNode, "x", x); //could also use newNode->setAttribute() sp_repr_set_int(newNode, "y", y); sp_repr_set_int(newNode, "width", width); @@ -380,7 +380,7 @@ gchar* document_interface_ellipse_center (DocumentInterface *object, int cx, int cy, int rx, int ry, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "arc"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -395,7 +395,7 @@ document_interface_polygon (DocumentInterface *object, int cx, int cy, GError **error) { gdouble rot = ((rotation / 180.0) * 3.14159265) - ( 3.14159265 / 2.0); - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "true"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -416,7 +416,7 @@ document_interface_star (DocumentInterface *object, int cx, int cy, int r1, int r2, int sides, gdouble rounded, gdouble arg1, gdouble arg2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "false"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -445,7 +445,7 @@ gchar* document_interface_line (DocumentInterface *object, int x, int y, int x2, int y2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); std::stringstream out; // Not sure why this works. out << "m " << x << "," << y << " " << x2 - x << "," << y2 - y; @@ -457,7 +457,7 @@ gchar* document_interface_spiral (DocumentInterface *object, int cx, int cy, int r, int revolutions, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "spiral"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -478,13 +478,13 @@ gchar* document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) { - Inkscape::XML::Node *text_node = dbus_create_node(object->desk, "svg:text"); + Inkscape::XML::Node *text_node = dbus_create_node(object->context.getDocument(), "svg:text"); sp_repr_set_int(text_node, "x", x); sp_repr_set_int(text_node, "y", y); //just a workaround so i can get an spitem from the name gchar *name = finish_create_shape (object, error, text_node, (gchar *)"create text"); - SPItem* text_obj=(SPItem* )get_object_by_name(object->desk, name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); sp_te_set_repr_text_multiline(text_obj, text); return name; @@ -497,16 +497,16 @@ document_interface_image (DocumentInterface *object, int x, int y, gchar *filena if (!uri) return FALSE; - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:image"); + Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:image"); sp_repr_set_int(newNode, "x", x); sp_repr_set_int(newNode, "y", y); newNode->setAttribute("xlink:href", uri); - object->desk->currentLayer()->appendChildRepr(newNode); - object->desk->currentLayer()->updateRepr(); + object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); + object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); if (object->updates) - Inkscape::DocumentUndo::done(sp_desktop_document(object->desk), 0, "Imported bitmap."); + Inkscape::DocumentUndo::done(object->context.getDocument(), 0, "Imported bitmap."); //g_free(uri); return strdup(newNode->attribute("id")); @@ -514,16 +514,16 @@ document_interface_image (DocumentInterface *object, int x, int y, gchar *filena gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** /*error*/) { - SPDocument * doc = sp_desktop_document (object->desk); + SPDocument * doc = object->context.getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *newNode = xml_doc->createElement(type); - object->desk->currentLayer()->appendChildRepr(newNode); - object->desk->currentLayer()->updateRepr(); + object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); + object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); if (object->updates) { - Inkscape::DocumentUndo::done(sp_desktop_document(object->desk), 0, (gchar *)"created empty node"); + Inkscape::DocumentUndo::done(doc, 0, (gchar *)"created empty node"); //} else { //document_interface_pause_updates(object, error); } @@ -537,39 +537,54 @@ gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** gdouble document_interface_document_get_width (DocumentInterface *object) { - return sp_desktop_document(object->desk)->getWidth(); + return object->context.getDocument()->getWidth(); } gdouble document_interface_document_get_height (DocumentInterface *object) { - return sp_desktop_document(object->desk)->getHeight(); + return object->context.getDocument()->getHeight(); } -gchar *document_interface_document_get_css(DocumentInterface *object, GError ** /*error*/) +gchar *document_interface_document_get_css(DocumentInterface *object, GError ** error) { - SPCSSAttr *current = (object->desk)->current; + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document get CSS requires a GUI"); + return NULL; + } + SPCSSAttr *current = desk->current; Glib::ustring str; sp_repr_css_write_string(current, str); return (str.empty() ? NULL : g_strdup (str.c_str())); } gboolean document_interface_document_merge_css(DocumentInterface *object, - gchar *stylestring, GError ** /*error*/) + gchar *stylestring, GError ** error) { + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document merge CSS requires a GUI"); + return FALSE; + } SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(style, stylestring); - sp_desktop_set_style(object->desk, style); + sp_desktop_set_style(desk, style); return TRUE; } gboolean document_interface_document_set_css(DocumentInterface *object, - gchar *stylestring, GError ** /*error*/) + gchar *stylestring, GError ** error) { + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document set CSS requires a GUI"); + return FALSE; + } SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string (style, stylestring); //Memory leak? - object->desk->current = style; + desk->current = style; return TRUE; } @@ -589,19 +604,28 @@ document_interface_document_set_display_area (DocumentInterface *object, double border, GError **error) { - object->desk->set_display_area (x0, + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document set display area requires a GUI"); + return FALSE; + } + desk->set_display_area (x0, y0, x1, y1, border, false); - return TRUE; + return TRUE; } GArray * document_interface_document_get_display_area (DocumentInterface *object) { - Geom::Rect const d = object->desk->get_display_area(); + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + return NULL; + } + Geom::Rect const d = desk->get_display_area(); GArray * dArr = g_array_new (TRUE, TRUE, sizeof(double)); @@ -626,7 +650,7 @@ gboolean document_interface_set_attribute (DocumentInterface *object, char *shape, char *attribute, char *newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->desk, shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(object->context.getDocument(), shape, error); /* ALTERNATIVE (is this faster?) Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); @@ -646,7 +670,7 @@ document_interface_set_int_attribute (DocumentInterface *object, char *shape, char *attribute, int newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->desk, shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (object->context.getDocument(), shape, error); if (!newNode) return FALSE; @@ -660,7 +684,7 @@ document_interface_set_double_attribute (DocumentInterface *object, char *shape, char *attribute, double newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->desk, shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (object->context.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "New value string was empty.")) return FALSE; @@ -675,7 +699,7 @@ gchar * document_interface_get_attribute (DocumentInterface *object, char *shape, char *attribute, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->desk, shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(object->context.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "Attribute name empty.")) return NULL; @@ -689,11 +713,11 @@ gboolean document_interface_move (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->desk, name, error); + const GSList *oldsel = selection_swap(object->context.getSelection(), name, error); if (!oldsel) return FALSE; - sp_selection_move (object->desk, x, 0 - y); - selection_restore(object->desk, oldsel); + sp_selection_move (object->context.getSelection(), x, 0 - y); + selection_restore(object->context.getSelection(), oldsel); return TRUE; } @@ -701,13 +725,13 @@ gboolean document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->desk, name, error); + const GSList *oldsel = selection_swap(object->context.getSelection(), name, error); if (!oldsel) return FALSE; - Inkscape::Selection * sel = sp_desktop_selection(object->desk); - sp_selection_move (object->desk, x - selection_get_center_x(sel), + Inkscape::Selection * sel = object->context.getSelection(); + sp_selection_move (object->context.getSelection(), x - selection_get_center_x(sel), 0 - (y - selection_get_center_y(sel))); - selection_restore(object->desk, oldsel); + selection_restore(object->context.getSelection(), oldsel); return TRUE; } @@ -715,18 +739,18 @@ gboolean document_interface_object_to_path (DocumentInterface *object, char *shape, GError **error) { - const GSList *oldsel = selection_swap(object->desk, shape, error); + const GSList *oldsel = selection_swap(object->context.getSelection(), shape, error); if (!oldsel) return FALSE; dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); - selection_restore(object->desk, oldsel); + selection_restore(object->context.getSelection(), oldsel); return TRUE; } gchar * document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) { - Inkscape::XML::Node *node = get_repr_by_name(object->desk, pathname, error); + Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), pathname, error); if (!node) return NULL; @@ -763,7 +787,7 @@ document_interface_modify_css (DocumentInterface *object, gchar *shape, { // Doesn't like non-variable strings for some reason. gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->desk, shape, error); + Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), shape, error); if (!dbus_check_string (cssattrb, error, "Attribute string empty.")) return FALSE; @@ -784,7 +808,7 @@ document_interface_merge_css (DocumentInterface *object, gchar *shape, { gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->desk, shape, error); + Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), shape, error); if (!dbus_check_string (stylestring, error, "Style string empty.")) return FALSE; @@ -830,12 +854,12 @@ gboolean document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) { - const GSList *oldsel = selection_swap(object->desk, shape, error); + const GSList *oldsel = selection_swap(object->context.getSelection(), shape, error); if (!oldsel) return FALSE; document_interface_selection_move_to_layer(object, layerstr, error); - selection_restore(object->desk, oldsel); + selection_restore(object->context.getSelection(), oldsel); return TRUE; } @@ -843,7 +867,7 @@ GArray *document_interface_get_node_coordinates(DocumentInterface * /*object*/, { //FIXME: Needs lot's of work. /* - Inkscape::XML::Node *shapenode = get_repr_by_name (object->desk, shape, error); + Inkscape::XML::Node *shapenode = get_repr_by_name (object->context.getDocument(), shape, error); if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } @@ -861,7 +885,7 @@ gboolean document_interface_set_text (DocumentInterface *object, gchar *name, gchar *text, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->desk, name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); //TODO verify object type if (!text_obj) return FALSE; @@ -878,7 +902,7 @@ document_interface_text_apply_style (DocumentInterface *object, gchar *name, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->desk, name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); //void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPCSSAttr const *css) //TODO verify object type @@ -907,7 +931,7 @@ document_interface_text_apply_style (DocumentInterface *object, gchar *name, gboolean document_interface_save (DocumentInterface *object, GError **error) { - SPDocument * doc = sp_desktop_document(object->desk); + SPDocument * doc = object->context.getDocument(); printf("1: %s\n2: %s\n3: %s\n", doc->getURI(), doc->getBase(), doc->getName()); if (doc->getURI()) return document_interface_save_as (object, doc->getURI(), error); @@ -917,11 +941,14 @@ document_interface_save (DocumentInterface *object, GError **error) gboolean document_interface_load(DocumentInterface *object, gchar *filename, GError ** /*error*/) { - desktop_ensure_active(object->desk); + SPDesktop *desk = object->context.getDesktop(); + if (desk) { + desktop_ensure_active(desk); + } const Glib::ustring file(filename); sp_file_open(file, NULL, TRUE, TRUE); if (object->updates) { - Inkscape::DocumentUndo::done(sp_desktop_document(object->desk), SP_VERB_FILE_OPEN, "Opened File"); + Inkscape::DocumentUndo::done(object->context.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); } return TRUE; } @@ -930,9 +957,12 @@ gchar * document_interface_import (DocumentInterface *object, gchar *filename, GError **error) { - desktop_ensure_active (object->desk); + SPDesktop *desk = object->context.getDesktop(); + if (desk) { + desktop_ensure_active(desk); + } const Glib::ustring file(filename); - SPDocument * doc = sp_desktop_document(object->desk); + SPDocument * doc = object->context.getDocument(); SPObject *new_obj = NULL; new_obj = file_import(doc, file, NULL); @@ -943,7 +973,7 @@ gboolean document_interface_save_as (DocumentInterface *object, const gchar *filename, GError **error) { - SPDocument * doc = sp_desktop_document(object->desk); + SPDocument * doc = object->context.getDocument(); #ifdef WITH_GNOME_VFS const Glib::ustring file(filename); return file_save_remote(doc, file, NULL, TRUE, TRUE); @@ -967,7 +997,7 @@ document_interface_save_as (DocumentInterface *object, gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError ** /*error*/) { - SPDocument * doc = sp_desktop_document(object->desk); + SPDocument * doc = object->context.getDocument(); if (doc) { doc->modified_since_save = FALSE; } @@ -978,7 +1008,7 @@ gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError gboolean document_interface_print_to_file (DocumentInterface *object, GError **error) { - SPDocument * doc = sp_desktop_document(object->desk); + SPDocument * doc = object->context.getDocument(); sp_print_document_to_file (doc, g_strdup("/home/soren/test.pdf")); return TRUE; @@ -1021,39 +1051,55 @@ document_interface_redo (DocumentInterface *object, GError **error) Need to make sure it plays well with verbs because they are used so much. ****************************************************************************/ -void document_interface_pause_updates(DocumentInterface *object, GError ** /*error*/) +void document_interface_pause_updates(DocumentInterface *object, GError ** error) { + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document pause updates requires a GUI"); + return; + } object->updates = FALSE; - object->desk->canvas->drawing_disabled = 1; - //object->desk->canvas->need_redraw = 0; - //object->desk->canvas->need_repick = 0; - //sp_desktop_document(object->desk)->root->uflags = FALSE; - //sp_desktop_document(object->desk)->root->mflags = FALSE; + desk->canvas->drawing_disabled = 1; + //desk->canvas->need_redraw = 0; + //desk->canvas->need_repick = 0; + //object->context.getDocument()->root->uflags = FALSE; + //object->context.getDocument()->root->mflags = FALSE; } -void document_interface_resume_updates(DocumentInterface *object, GError ** /*error*/) +void document_interface_resume_updates(DocumentInterface *object, GError ** error) { + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document resume updates requires a GUI"); + return; + } object->updates = TRUE; - object->desk->canvas->drawing_disabled = 0; - //object->desk->canvas->need_redraw = 1; - //object->desk->canvas->need_repick = 1; - //sp_desktop_document(object->desk)->root->uflags = TRUE; - //sp_desktop_document(object->desk)->root->mflags = TRUE; - //sp_desktop_document(object->desk)->_updateDocument(); + desk->canvas->drawing_disabled = 0; + //desk->canvas->need_redraw = 1; + //desk->canvas->need_repick = 1; + //object->context.getDocument()->root->uflags = TRUE; + //object->context.getDocument()->root->mflags = TRUE; + //object->context.getDocument()->_updateDocument(); //FIXME: use better verb than rect. - Inkscape::DocumentUndo::done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); + Inkscape::DocumentUndo::done(object->context.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); } -void document_interface_update(DocumentInterface *object, GError ** /*error*/) +void document_interface_update(DocumentInterface *object, GError ** error) { - sp_desktop_document(object->desk)->getRoot()->uflags = TRUE; - sp_desktop_document(object->desk)->getRoot()->mflags = TRUE; - object->desk->enableInteraction(); - sp_desktop_document(object->desk)->_updateDocument(); - object->desk->disableInteraction(); - sp_desktop_document(object->desk)->getRoot()->uflags = FALSE; - sp_desktop_document(object->desk)->getRoot()->mflags = FALSE; - //Inkscape::DocumentUndo::done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document update requires a GUI"); + return; + } + SPDocument *doc = object->context.getDocument(); + doc->getRoot()->uflags = TRUE; + doc->getRoot()->mflags = TRUE; + desk->enableInteraction(); + doc->_updateDocument(); + desk->disableInteraction(); + doc->getRoot()->uflags = FALSE; + doc->getRoot()->mflags = FALSE; + //Inkscape::DocumentUndo::done(doc, SP_VERB_CONTEXT_RECT, "Multiple actions"); } /**************************************************************************** @@ -1062,7 +1108,7 @@ void document_interface_update(DocumentInterface *object, GError ** /*error*/) gboolean document_interface_selection_get(DocumentInterface *object, char ***out, GError ** /*error*/) { - Inkscape::Selection * sel = sp_desktop_selection(object->desk); + Inkscape::Selection * sel = object->context.getSelection(); GSList const *oldsel = sel->list(); int size = g_slist_length((GSList *) oldsel); @@ -1082,11 +1128,11 @@ gboolean document_interface_selection_get(DocumentInterface *object, char ***out gboolean document_interface_selection_add (DocumentInterface *object, char *name, GError **error) { - SPObject * obj = get_object_by_name(object->desk, name, error); + SPObject * obj = get_object_by_name(object->context.getDocument(), name, error); if (!obj) return FALSE; - Inkscape::Selection *selection = sp_desktop_selection(object->desk); + Inkscape::Selection *selection = object->context.getSelection(); selection->add(obj); return TRUE; @@ -1105,8 +1151,8 @@ document_interface_selection_add_list (DocumentInterface *object, gboolean document_interface_selection_set(DocumentInterface *object, char *name, GError ** /*error*/) { - SPDocument * doc = sp_desktop_document(object->desk); - Inkscape::Selection *selection = sp_desktop_selection(object->desk); + SPDocument * doc = object->context.getDocument(); + Inkscape::Selection *selection = object->context.getSelection(); selection->set(doc->getObjectById(name)); return TRUE; } @@ -1115,7 +1161,7 @@ gboolean document_interface_selection_set_list (DocumentInterface *object, gchar **names, GError **error) { - sp_desktop_selection(object->desk)->clear(); + object->context.getSelection()->clear(); int i; for (i=0;names[i] != NULL;i++) { document_interface_selection_add(object, names[i], error); @@ -1125,7 +1171,7 @@ document_interface_selection_set_list (DocumentInterface *object, gboolean document_interface_selection_rotate(DocumentInterface *object, int angle, GError ** /*error*/) { - Inkscape::Selection *selection = sp_desktop_selection(object->desk); + Inkscape::Selection *selection = object->context.getSelection(); sp_selection_rotate(selection, angle); return TRUE; } @@ -1139,7 +1185,7 @@ document_interface_selection_delete (DocumentInterface *object, GError **error) gboolean document_interface_selection_clear(DocumentInterface *object, GError ** /*error*/) { - sp_desktop_selection(object->desk)->clear(); + object->context.getSelection()->clear(); return TRUE; } @@ -1205,7 +1251,12 @@ document_interface_selection_copy (DocumentInterface *object, GError **error) gboolean document_interface_selection_paste (DocumentInterface *object, GError **error) { - desktop_ensure_active (object->desk); + SPDesktop *desk = object->context.getDesktop(); + if (!desk) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document selection paste requires a GUI"); + return FALSE; + } + desktop_ensure_active (desk); if (!object->updates) document_interface_pause_updates (object, error); sp_selection_paste (object->desk, TRUE); @@ -1223,7 +1274,7 @@ document_interface_selection_paste (DocumentInterface *object, GError **error) gboolean document_interface_selection_scale(DocumentInterface *object, gdouble grow, GError ** /*error*/) { - Inkscape::Selection *selection = sp_desktop_selection(object->desk); + Inkscape::Selection *selection = object->context.getSelection(); if (!selection) { return FALSE; @@ -1234,13 +1285,13 @@ gboolean document_interface_selection_scale(DocumentInterface *object, gdouble g gboolean document_interface_selection_move(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) { - sp_selection_move(object->desk, x, 0 - y); //switching coordinate systems. + sp_selection_move(object->context.getSelection(), x, 0 - y); //switching coordinate systems. return TRUE; } gboolean document_interface_selection_move_to(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) { - Inkscape::Selection * sel = sp_desktop_selection(object->desk); + Inkscape::Selection * sel = object->context.getSelection(); Geom::OptRect sel_bbox = sel->visualBounds(); if (sel_bbox) { @@ -1257,15 +1308,19 @@ gboolean document_interface_selection_move_to_layer (DocumentInterface *object, gchar *layerstr, GError **error) { - SPDesktop * dt = object->desk; + SPDesktop *dt = object->context.getDesktop(); + if (!dt) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document selection move to layer requires a GUI"); + return FALSE; + } - Inkscape::Selection *selection = sp_desktop_selection(dt); + Inkscape::Selection *selection = object->context.getSelection(); // check if something is selected if (selection->isEmpty()) return FALSE; - SPObject *next = get_object_by_name(object->desk, layerstr, error); + SPObject *next = get_object_by_name(object->context.getDocument(), layerstr, error); if (!next) return FALSE; @@ -1274,7 +1329,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, sp_selection_cut(dt); - dt->setCurrentLayer(next); + object->context.getSelection()->layerModel()->setCurrentLayer(next); sp_selection_paste(dt, TRUE); } @@ -1284,7 +1339,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, GArray * document_interface_selection_get_center (DocumentInterface *object) { - Inkscape::Selection * sel = sp_desktop_selection(object->desk); + Inkscape::Selection * sel = object->context.getSelection(); if (sel) { @@ -1322,8 +1377,8 @@ document_interface_selection_combine (DocumentInterface *object, gchar *cmd, else return NULL; - if (sp_desktop_selection(object->desk)->singleRepr() != NULL) - return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); + if (object->context.getSelection()->singleRepr() != NULL) + return g_strdup(object->context.getSelection()->singleRepr()->attribute("id")); return NULL; } @@ -1356,9 +1411,9 @@ document_interface_selection_change_level (DocumentInterface *object, gchar *cmd gchar *document_interface_layer_new(DocumentInterface *object, GError ** /*error*/) { - SPDesktop * dt = object->desk; - SPObject *new_layer = Inkscape::create_layer(dt->currentRoot(), dt->currentLayer(), Inkscape::LPOS_BELOW); - dt->setCurrentLayer(new_layer); + Inkscape::LayerModel * layerModel = object->context.getSelection()->layerModel(); + SPObject *new_layer = Inkscape::create_layer(layerModel->currentRoot(), layerModel->currentLayer(), Inkscape::LPOS_BELOW); + layerModel->setCurrentLayer(new_layer); return g_strdup(get_name_from_object(new_layer)); } @@ -1366,12 +1421,12 @@ gboolean document_interface_layer_set (DocumentInterface *object, gchar *layerstr, GError **error) { - SPObject * obj = get_object_by_name (object->desk, layerstr, error); + SPObject * obj = get_object_by_name (object->context.getDocument(), layerstr, error); if (!obj) return FALSE; - object->desk->setCurrentLayer (obj); + object->context.getSelection()->layerModel()->setCurrentLayer (obj); return TRUE; } @@ -1427,7 +1482,7 @@ gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) gboolean document_interface_get_children (DocumentInterface *object, char *name, char ***out, GError **error) { - SPItem* parent=(SPItem* )get_object_by_name(object->desk, name, error); + SPItem* parent=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); GSList const *children = parent->childList(false); @@ -1450,7 +1505,7 @@ document_interface_get_children (DocumentInterface *object, char *name, char ** gchar* document_interface_get_parent (DocumentInterface *object, char *name, GError **error) { - SPItem* node=(SPItem* )get_object_by_name(object->desk, name, error); + SPItem* node=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); SPObject* parent=node->parent; @@ -1462,7 +1517,7 @@ document_interface_get_parent (DocumentInterface *object, char *name, GError ** //just pseudo code gboolean document_interface_get_xpath (DocumentInterface *object, char *xpath_expression, char ***out, GError **error){ - SPDocument * doc = sp_desktop_document (object->desk); + SPDocument * doc = object->context.getDocument(); Inkscape::XML::Document *repr = doc->getReprDoc(); xmlXPathObjectPtr xpathObj; diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 5fcbb919b..9b8d34dd3 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -30,8 +30,12 @@ #undef DBUS_MESSAGE_TYPE_ERROR #undef DBUS_MESSAGE_TYPE_SIGNAL -#include "desktop.h" +#include "helper/action-context.h" +class SPDesktop; +class SPItem; + +// TODO: this define doesn't seem to be used... although the path itself is also hardcoded in dbus-init.cpp #define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document" #define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ()) @@ -47,8 +51,8 @@ typedef struct _DocumentInterface DocumentInterface; typedef struct _DocumentInterfaceClass DocumentInterfaceClass; struct _DocumentInterface { - GObject parent; - SPDesktop *desk; + GObject parent; + Inkscape::ActionContext context; gboolean updates; }; -- cgit v1.2.3 From 1c75594f5c37e86dec195ec1975254315ef180e9 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Wed, 3 Jul 2013 23:00:06 +0100 Subject: Changed dbus interface to treat 'division' like other boolops, with a new return type for selection_combine to support this (array of string). This also fixes a bug with not setting the error flag when returning NULL from this method. Refactored some more selection verbs to allow use in no-GUI mode. (bzr r12387.1.5) --- src/extension/dbus/application-interface.cpp | 6 +++- src/extension/dbus/document-interface.cpp | 26 ++++++------------ src/extension/dbus/document-interface.h | 9 ++---- src/extension/dbus/document-interface.xml | 32 ++++++---------------- src/extension/dbus/wrapper/inkscape-dbus-wrapper.c | 18 +++--------- src/extension/dbus/wrapper/inkscape-dbus-wrapper.h | 6 +--- 6 files changed, 29 insertions(+), 68 deletions(-) (limited to 'src/extension') diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp index 399e1b244..1b1dbf0f5 100644 --- a/src/extension/dbus/application-interface.cpp +++ b/src/extension/dbus/application-interface.cpp @@ -150,7 +150,11 @@ gchar* application_interface_get_active_document(ApplicationInterface *object, GError **error) { - return (gchar*)Inkscape::Extension::Dbus::init_active_document(); + gchar *result = (gchar*)Inkscape::Extension::Dbus::init_active_document(); + if (!result) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "No active document"); + } + return result; } gchar** diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index f0cc71de1..87b769e26 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -1222,13 +1222,11 @@ document_interface_selection_invert (DocumentInterface *object, GError **error) gboolean document_interface_selection_group (DocumentInterface *object, GError **error) { - //sp_selection_group (object->desk); return dbus_call_verb (object, SP_VERB_SELECTION_GROUP, error); } gboolean document_interface_selection_ungroup (DocumentInterface *object, GError **error) { - //sp_selection_ungroup (object->desk); return dbus_call_verb (object, SP_VERB_SELECTION_UNGROUP, error); } @@ -1362,8 +1360,8 @@ document_interface_selection_to_path (DocumentInterface *object, GError **error) } -gchar * -document_interface_selection_combine (DocumentInterface *object, gchar *cmd, +gboolean +document_interface_selection_combine (DocumentInterface *object, gchar *cmd, char ***newpaths, GError **error) { if (strcmp(cmd, "union") == 0) @@ -1374,20 +1372,14 @@ document_interface_selection_combine (DocumentInterface *object, gchar *cmd, dbus_call_verb (object, SP_VERB_SELECTION_DIFF, error); else if (strcmp(cmd, "exclusion") == 0) dbus_call_verb (object, SP_VERB_SELECTION_SYMDIFF, error); - else - return NULL; - - if (object->context.getSelection()->singleRepr() != NULL) - return g_strdup(object->context.getSelection()->singleRepr()->attribute("id")); - return NULL; -} - -gboolean -document_interface_selection_divide (DocumentInterface *object, char ***out, GError **error) -{ - dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + else if (strcmp(cmd, "division") == 0) + dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + else { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Operation command not recognised"); + return FALSE; + } - return document_interface_selection_get (object, out, error); + return document_interface_selection_get (object, newpaths, error); } gboolean diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 9b8d34dd3..5eef3d0c0 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -363,14 +363,9 @@ document_interface_selection_get_center (DocumentInterface *object); gboolean document_interface_selection_to_path (DocumentInterface *object, GError **error); -gchar * -document_interface_selection_combine (DocumentInterface *object, gchar *cmd, - GError **error); - gboolean -document_interface_selection_divide (DocumentInterface *object, - char ***out, GError **error); - +document_interface_selection_combine (DocumentInterface *object, gchar *cmd, char ***newpaths, + GError **error); gboolean document_interface_selection_change_level (DocumentInterface *object, gchar *cmd, diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index aeacfae44..7481c0893 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -21,7 +21,7 @@ - +c @@ -1348,36 +1348,20 @@ Type of combination. - - + - The new path created, if there is one. NULL otherwise. + List of the ids of resulting paths after applying the operation. Will erase all objects in the selection and replace with a single aggregate path. There are 5 types that can be passed in: - Union: The new shape is all of the other shapes put together, even if they don't overlap (paths can have multiple non-contiguous areas.) - Intersection: The new shape is composed of the area where ALL the objects in the selection overlap. If there is no area where all shapes overlap the new shape will be empty. - Difference: The area of the second shape is subtracted from the first, only works with two objects. - Exclusion: The new shape is the area(s) where none of the objects in the selection overlaped. Only works with two objects. - Division: the first object is split into multiple segments by the second object. Only works with two objects and if multiple paths result they are grouped and the group id is returned. - - - - - - - - - List of the ids of resulting paths. - - - - - Returns the result of cutting the bottom object by all other intersecting paths. - This may make many seperate layers. + 'union': The new shape is all of the other shapes put together, even if they don't overlap (paths can have multiple non-contiguous areas.) + 'intersection': The new shape is composed of the area where ALL the objects in the selection overlap. If there is no area where all shapes overlap the new shape will be empty. + 'difference': The area of the second shape is subtracted from the first, only works with two objects. + 'exclusion': The new shape is the area(s) where none of the objects in the selection overlaped. Only works with two objects. + 'division': the first object is split into multiple segments by the second object. Only works with two objects. diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c index 0be1be42e..c7e453593 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c @@ -687,24 +687,14 @@ inkscape_selection_to_path (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_to_path (proxy, error); } -//static -char * -inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error) -{ - char * OUT_newpath; - DBusGProxy *proxy = doc->proxy; - org_inkscape_document_selection_combine (proxy, IN_type, &OUT_newpath, error); - return OUT_newpath; -} - //static char ** -inkscape_selection_divide (DocumentInterface *doc, GError **error) +inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error) { - char ** OUT_pieces; + char ** OUT_newpaths; DBusGProxy *proxy = doc->proxy; - org_inkscape_document_selection_divide (proxy, &OUT_pieces, error); - return OUT_pieces; + org_inkscape_document_selection_combine (proxy, IN_type, &OUT_newpaths, error); + return OUT_newpaths; } //static diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h index 684f1b142..79f8188d4 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h @@ -303,13 +303,9 @@ inkscape_selection_get_center (DocumentInterface *doc, GError **error); gboolean inkscape_selection_to_path (DocumentInterface *doc, GError **error); -//static -char * -inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error); - //static char ** -inkscape_selection_divide (DocumentInterface *doc, GError **error); +inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error); //static gboolean -- cgit v1.2.3 From 104efe4e3ecadc975ab76748c66f041abf8ee7b1 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Thu, 4 Jul 2013 15:01:44 +0100 Subject: Code readability improvements and licence changes for action-context.* based on merge request code review and feedback (bzr r12387.1.7) --- src/extension/dbus/dbus-init.cpp | 4 +- src/extension/dbus/document-interface.cpp | 299 +++++++++++++----------------- src/extension/dbus/document-interface.h | 2 +- src/extension/effect.cpp | 7 +- 4 files changed, 130 insertions(+), 182 deletions(-) (limited to 'src/extension') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index 96d72c0f6..fe59fc154 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -153,7 +153,7 @@ init_active_document() name.c_str()); // Set the document info for this interface - obj->context = inkscape_active_action_context(); + obj->doc_context = inkscape_active_action_context(); } return strdup(name.c_str()); } @@ -178,7 +178,7 @@ dbus_init_desktop_interface (SPDesktop * dt) obj = (DocumentInterface*) dbus_register_object (connection, proxy, TYPE_DOCUMENT_INTERFACE, &dbus_glib_document_interface_object_info, name.c_str()); - obj->context = Inkscape::ActionContext(dt); + obj->doc_context = Inkscape::ActionContext(dt); obj->updates = TRUE; dt->dbus_document_interface=obj; return strdup(name.c_str()); diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 87b769e26..6d6f983c5 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -190,7 +190,7 @@ selection_swap(Inkscape::Selection *sel, gchar *name, GError **error) { const GSList *oldsel = g_slist_copy((GSList *)sel->list()); - sel->set(get_object_by_name(sel->layerModel()->getDocument(), name, error)); + sel->set(get_object_by_name(sel->layers()->getDocument(), name, error)); return oldsel; } @@ -224,8 +224,8 @@ dbus_create_node (SPDocument *doc, const gchar *type) gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inkscape::XML::Node *newNode, gchar *desc) { SPCSSAttr *style = NULL; - if (object->context.getDesktop()) { - style = sp_desktop_get_style(object->context.getDesktop(), TRUE); + if (object->doc_context.getDesktop()) { + style = sp_desktop_get_style(object->doc_context.getDesktop(), TRUE); } if (style) { Glib::ustring str; @@ -236,13 +236,11 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks newNode->setAttribute("style", "fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none", TRUE); } - object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); - object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); + object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); if (object->updates) { - Inkscape::DocumentUndo::done(object->context.getDocument(), 0, (gchar *)desc); - //} else { - //document_interface_pause_updates(object, error); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), 0, (gchar *)desc); } return strdup(newNode->attribute("id")); @@ -259,21 +257,17 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks gboolean dbus_call_verb (DocumentInterface *object, int verbid, GError **error) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if ( desk ) { desktop_ensure_active (desk); } Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); if ( verb ) { - SPAction *action = verb->get_action(object->context); + SPAction *action = verb->get_action(object->doc_context); if ( action ) { - //if (!object->updates) - //document_interface_pause_updates (object, error); sp_action_perform( action, NULL ); if (object->updates) - Inkscape::DocumentUndo::done(object->context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); - //if (!object->updates) - //document_interface_pause_updates (object, error); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); return TRUE; } } @@ -281,6 +275,20 @@ dbus_call_verb (DocumentInterface *object, int verbid, GError **error) return FALSE; } +/* + * Check that the desktop is not NULL. If it is NULL, set the error to a useful message. + */ +bool +ensure_desktop_valid(SPDesktop* desk, GError **error) +{ + if (desk) { + return true; + } + + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document interface action requires a GUI"); + return false; +} + /**************************************************************************** DOCUMENT INTERFACE CLASS STUFF ****************************************************************************/ @@ -313,7 +321,7 @@ document_interface_class_init (DocumentInterfaceClass *klass) static void document_interface_init (DocumentInterface *object) { - object->context = Inkscape::ActionContext(); + object->doc_context = Inkscape::ActionContext(); } @@ -331,24 +339,24 @@ document_interface_new (void) gboolean document_interface_delete_all(DocumentInterface *object, GError ** /*error*/) { - sp_edit_clear_all(object->context.getSelection()); + sp_edit_clear_all(object->doc_context.getSelection()); return TRUE; } gboolean document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if ( desk ) { desktop_ensure_active (desk); } Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid ); if ( verb ) { - SPAction *action = verb->get_action(object->context); + SPAction *action = verb->get_action(object->doc_context); if ( action ) { sp_action_perform( action, NULL ); if (object->updates) { - Inkscape::DocumentUndo::done(object->context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); } return TRUE; } @@ -368,7 +376,7 @@ document_interface_rectangle (DocumentInterface *object, int x, int y, { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:rect"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:rect"); sp_repr_set_int(newNode, "x", x); //could also use newNode->setAttribute() sp_repr_set_int(newNode, "y", y); sp_repr_set_int(newNode, "width", width); @@ -380,7 +388,7 @@ gchar* document_interface_ellipse_center (DocumentInterface *object, int cx, int cy, int rx, int ry, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "arc"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -395,7 +403,7 @@ document_interface_polygon (DocumentInterface *object, int cx, int cy, GError **error) { gdouble rot = ((rotation / 180.0) * 3.14159265) - ( 3.14159265 / 2.0); - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "true"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -416,7 +424,7 @@ document_interface_star (DocumentInterface *object, int cx, int cy, int r1, int r2, int sides, gdouble rounded, gdouble arg1, gdouble arg2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "false"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -445,7 +453,7 @@ gchar* document_interface_line (DocumentInterface *object, int x, int y, int x2, int y2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); std::stringstream out; // Not sure why this works. out << "m " << x << "," << y << " " << x2 - x << "," << y2 - y; @@ -457,7 +465,7 @@ gchar* document_interface_spiral (DocumentInterface *object, int cx, int cy, int r, int revolutions, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "spiral"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -478,13 +486,13 @@ gchar* document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) { - Inkscape::XML::Node *text_node = dbus_create_node(object->context.getDocument(), "svg:text"); + Inkscape::XML::Node *text_node = dbus_create_node(object->doc_context.getDocument(), "svg:text"); sp_repr_set_int(text_node, "x", x); sp_repr_set_int(text_node, "y", y); //just a workaround so i can get an spitem from the name gchar *name = finish_create_shape (object, error, text_node, (gchar *)"create text"); - SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); sp_te_set_repr_text_multiline(text_obj, text); return name; @@ -497,16 +505,16 @@ document_interface_image (DocumentInterface *object, int x, int y, gchar *filena if (!uri) return FALSE; - Inkscape::XML::Node *newNode = dbus_create_node(object->context.getDocument(), "svg:image"); + Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:image"); sp_repr_set_int(newNode, "x", x); sp_repr_set_int(newNode, "y", y); newNode->setAttribute("xlink:href", uri); - object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); - object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); + object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); if (object->updates) - Inkscape::DocumentUndo::done(object->context.getDocument(), 0, "Imported bitmap."); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), 0, "Imported bitmap."); //g_free(uri); return strdup(newNode->attribute("id")); @@ -514,18 +522,16 @@ document_interface_image (DocumentInterface *object, int x, int y, gchar *filena gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** /*error*/) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *newNode = xml_doc->createElement(type); - object->context.getSelection()->layerModel()->currentLayer()->appendChildRepr(newNode); - object->context.getSelection()->layerModel()->currentLayer()->updateRepr(); + object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); if (object->updates) { Inkscape::DocumentUndo::done(doc, 0, (gchar *)"created empty node"); - //} else { - //document_interface_pause_updates(object, error); } return strdup(newNode->attribute("id")); @@ -537,22 +543,19 @@ gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** gdouble document_interface_document_get_width (DocumentInterface *object) { - return object->context.getDocument()->getWidth(); + return object->doc_context.getDocument()->getWidth(); } gdouble document_interface_document_get_height (DocumentInterface *object) { - return object->context.getDocument()->getHeight(); + return object->doc_context.getDocument()->getHeight(); } gchar *document_interface_document_get_css(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document get CSS requires a GUI"); - return NULL; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), NULL); SPCSSAttr *current = desk->current; Glib::ustring str; sp_repr_css_write_string(current, str); @@ -562,11 +565,8 @@ gchar *document_interface_document_get_css(DocumentInterface *object, GError ** gboolean document_interface_document_merge_css(DocumentInterface *object, gchar *stylestring, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document merge CSS requires a GUI"); - return FALSE; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(style, stylestring); sp_desktop_set_style(desk, style); @@ -576,11 +576,8 @@ gboolean document_interface_document_merge_css(DocumentInterface *object, gboolean document_interface_document_set_css(DocumentInterface *object, gchar *stylestring, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document set CSS requires a GUI"); - return FALSE; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string (style, stylestring); //Memory leak? @@ -604,11 +601,8 @@ document_interface_document_set_display_area (DocumentInterface *object, double border, GError **error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document set display area requires a GUI"); - return FALSE; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); desk->set_display_area (x0, y0, x1, @@ -621,7 +615,7 @@ document_interface_document_set_display_area (DocumentInterface *object, GArray * document_interface_document_get_display_area (DocumentInterface *object) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if (!desk) { return NULL; } @@ -650,7 +644,7 @@ gboolean document_interface_set_attribute (DocumentInterface *object, char *shape, char *attribute, char *newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(object->doc_context.getDocument(), shape, error); /* ALTERNATIVE (is this faster?) Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); @@ -670,7 +664,7 @@ document_interface_set_int_attribute (DocumentInterface *object, char *shape, char *attribute, int newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (object->doc_context.getDocument(), shape, error); if (!newNode) return FALSE; @@ -684,7 +678,7 @@ document_interface_set_double_attribute (DocumentInterface *object, char *shape, char *attribute, double newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (object->doc_context.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "New value string was empty.")) return FALSE; @@ -699,7 +693,7 @@ gchar * document_interface_get_attribute (DocumentInterface *object, char *shape, char *attribute, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(object->doc_context.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "Attribute name empty.")) return NULL; @@ -713,11 +707,11 @@ gboolean document_interface_move (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), name, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), name, error); if (!oldsel) return FALSE; - sp_selection_move (object->context.getSelection(), x, 0 - y); - selection_restore(object->context.getSelection(), oldsel); + sp_selection_move (object->doc_context.getSelection(), x, 0 - y); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } @@ -725,13 +719,13 @@ gboolean document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), name, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), name, error); if (!oldsel) return FALSE; - Inkscape::Selection * sel = object->context.getSelection(); - sp_selection_move (object->context.getSelection(), x - selection_get_center_x(sel), + Inkscape::Selection * sel = object->doc_context.getSelection(); + sp_selection_move (object->doc_context.getSelection(), x - selection_get_center_x(sel), 0 - (y - selection_get_center_y(sel))); - selection_restore(object->context.getSelection(), oldsel); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } @@ -739,18 +733,18 @@ gboolean document_interface_object_to_path (DocumentInterface *object, char *shape, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), shape, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), shape, error); if (!oldsel) return FALSE; dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); - selection_restore(object->context.getSelection(), oldsel); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } gchar * document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) { - Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), pathname, error); + Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), pathname, error); if (!node) return NULL; @@ -787,7 +781,7 @@ document_interface_modify_css (DocumentInterface *object, gchar *shape, { // Doesn't like non-variable strings for some reason. gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), shape, error); if (!dbus_check_string (cssattrb, error, "Attribute string empty.")) return FALSE; @@ -808,7 +802,7 @@ document_interface_merge_css (DocumentInterface *object, gchar *shape, { gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->context.getDocument(), shape, error); + Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), shape, error); if (!dbus_check_string (stylestring, error, "Style string empty.")) return FALSE; @@ -854,12 +848,12 @@ gboolean document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) { - const GSList *oldsel = selection_swap(object->context.getSelection(), shape, error); + const GSList *oldsel = selection_swap(object->doc_context.getSelection(), shape, error); if (!oldsel) return FALSE; document_interface_selection_move_to_layer(object, layerstr, error); - selection_restore(object->context.getSelection(), oldsel); + selection_restore(object->doc_context.getSelection(), oldsel); return TRUE; } @@ -867,7 +861,7 @@ GArray *document_interface_get_node_coordinates(DocumentInterface * /*object*/, { //FIXME: Needs lot's of work. /* - Inkscape::XML::Node *shapenode = get_repr_by_name (object->context.getDocument(), shape, error); + Inkscape::XML::Node *shapenode = get_repr_by_name (object->doc_context.getDocument(), shape, error); if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } @@ -885,7 +879,7 @@ gboolean document_interface_set_text (DocumentInterface *object, gchar *name, gchar *text, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); //TODO verify object type if (!text_obj) return FALSE; @@ -902,7 +896,7 @@ document_interface_text_apply_style (DocumentInterface *object, gchar *name, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); //void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPCSSAttr const *css) //TODO verify object type @@ -931,7 +925,7 @@ document_interface_text_apply_style (DocumentInterface *object, gchar *name, gboolean document_interface_save (DocumentInterface *object, GError **error) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); printf("1: %s\n2: %s\n3: %s\n", doc->getURI(), doc->getBase(), doc->getName()); if (doc->getURI()) return document_interface_save_as (object, doc->getURI(), error); @@ -941,14 +935,14 @@ document_interface_save (DocumentInterface *object, GError **error) gboolean document_interface_load(DocumentInterface *object, gchar *filename, GError ** /*error*/) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if (desk) { desktop_ensure_active(desk); } const Glib::ustring file(filename); sp_file_open(file, NULL, TRUE, TRUE); if (object->updates) { - Inkscape::DocumentUndo::done(object->context.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); } return TRUE; } @@ -957,12 +951,12 @@ gchar * document_interface_import (DocumentInterface *object, gchar *filename, GError **error) { - SPDesktop *desk = object->context.getDesktop(); + SPDesktop *desk = object->doc_context.getDesktop(); if (desk) { desktop_ensure_active(desk); } const Glib::ustring file(filename); - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); SPObject *new_obj = NULL; new_obj = file_import(doc, file, NULL); @@ -973,7 +967,8 @@ gboolean document_interface_save_as (DocumentInterface *object, const gchar *filename, GError **error) { - SPDocument * doc = object->context.getDocument(); + // FIXME: Isn't there a verb we can use for this instead? + SPDocument * doc = object->doc_context.getDocument(); #ifdef WITH_GNOME_VFS const Glib::ustring file(filename); return file_save_remote(doc, file, NULL, TRUE, TRUE); @@ -986,18 +981,16 @@ document_interface_save_as (DocumentInterface *object, Inkscape::Extension::save(NULL, doc, filename, false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } catch (...) { - //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); + // FIXME: catch ... is not usually a great idea, why is it needed here? return false; } - //SP_ACTIVE_DESKTOP->event_log->rememberFileSave(); - //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, "Document saved."); return true; } gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError ** /*error*/) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); if (doc) { doc->modified_since_save = FALSE; } @@ -1008,7 +1001,7 @@ gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError gboolean document_interface_print_to_file (DocumentInterface *object, GError **error) { - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); sp_print_document_to_file (doc, g_strdup("/home/soren/test.pdf")); return TRUE; @@ -1053,45 +1046,27 @@ document_interface_redo (DocumentInterface *object, GError **error) void document_interface_pause_updates(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document pause updates requires a GUI"); - return; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); object->updates = FALSE; desk->canvas->drawing_disabled = 1; - //desk->canvas->need_redraw = 0; - //desk->canvas->need_repick = 0; - //object->context.getDocument()->root->uflags = FALSE; - //object->context.getDocument()->root->mflags = FALSE; } void document_interface_resume_updates(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document resume updates requires a GUI"); - return; - } + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); object->updates = TRUE; desk->canvas->drawing_disabled = 0; - //desk->canvas->need_redraw = 1; - //desk->canvas->need_repick = 1; - //object->context.getDocument()->root->uflags = TRUE; - //object->context.getDocument()->root->mflags = TRUE; - //object->context.getDocument()->_updateDocument(); //FIXME: use better verb than rect. - Inkscape::DocumentUndo::done(object->context.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); + Inkscape::DocumentUndo::done(object->doc_context.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); } void document_interface_update(DocumentInterface *object, GError ** error) { - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document update requires a GUI"); - return; - } - SPDocument *doc = object->context.getDocument(); + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); + SPDocument *doc = object->doc_context.getDocument(); doc->getRoot()->uflags = TRUE; doc->getRoot()->mflags = TRUE; desk->enableInteraction(); @@ -1108,7 +1083,7 @@ void document_interface_update(DocumentInterface *object, GError ** error) gboolean document_interface_selection_get(DocumentInterface *object, char ***out, GError ** /*error*/) { - Inkscape::Selection * sel = object->context.getSelection(); + Inkscape::Selection * sel = object->doc_context.getSelection(); GSList const *oldsel = sel->list(); int size = g_slist_length((GSList *) oldsel); @@ -1128,11 +1103,11 @@ gboolean document_interface_selection_get(DocumentInterface *object, char ***out gboolean document_interface_selection_add (DocumentInterface *object, char *name, GError **error) { - SPObject * obj = get_object_by_name(object->context.getDocument(), name, error); + SPObject * obj = get_object_by_name(object->doc_context.getDocument(), name, error); if (!obj) return FALSE; - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); selection->add(obj); return TRUE; @@ -1151,8 +1126,8 @@ document_interface_selection_add_list (DocumentInterface *object, gboolean document_interface_selection_set(DocumentInterface *object, char *name, GError ** /*error*/) { - SPDocument * doc = object->context.getDocument(); - Inkscape::Selection *selection = object->context.getSelection(); + SPDocument * doc = object->doc_context.getDocument(); + Inkscape::Selection *selection = object->doc_context.getSelection(); selection->set(doc->getObjectById(name)); return TRUE; } @@ -1161,7 +1136,7 @@ gboolean document_interface_selection_set_list (DocumentInterface *object, gchar **names, GError **error) { - object->context.getSelection()->clear(); + object->doc_context.getSelection()->clear(); int i; for (i=0;names[i] != NULL;i++) { document_interface_selection_add(object, names[i], error); @@ -1171,7 +1146,7 @@ document_interface_selection_set_list (DocumentInterface *object, gboolean document_interface_selection_rotate(DocumentInterface *object, int angle, GError ** /*error*/) { - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); sp_selection_rotate(selection, angle); return TRUE; } @@ -1179,20 +1154,18 @@ gboolean document_interface_selection_rotate(DocumentInterface *object, int angl gboolean document_interface_selection_delete (DocumentInterface *object, GError **error) { - //sp_selection_delete (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_DELETE, error); } gboolean document_interface_selection_clear(DocumentInterface *object, GError ** /*error*/) { - object->context.getSelection()->clear(); + object->doc_context.getSelection()->clear(); return TRUE; } gboolean document_interface_select_all (DocumentInterface *object, GError **error) { - //sp_edit_select_all (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL, error); } @@ -1200,7 +1173,6 @@ gboolean document_interface_select_all_in_all_layers(DocumentInterface *object, GError **error) { - //sp_edit_select_all_in_all_layers (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error); } @@ -1215,7 +1187,6 @@ gboolean document_interface_selection_box(DocumentInterface * /*object*/, int /* gboolean document_interface_selection_invert (DocumentInterface *object, GError **error) { - //sp_edit_invert (object->desk); return dbus_call_verb (object, SP_VERB_EDIT_INVERT, error); } @@ -1233,46 +1204,30 @@ document_interface_selection_ungroup (DocumentInterface *object, GError **error) gboolean document_interface_selection_cut (DocumentInterface *object, GError **error) { - //desktop_ensure_active (object->desk); - //sp_selection_cut (object->desk); + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); return dbus_call_verb (object, SP_VERB_EDIT_CUT, error); } gboolean document_interface_selection_copy (DocumentInterface *object, GError **error) { - //desktop_ensure_active (object->desk); - //sp_selection_copy (); + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); return dbus_call_verb (object, SP_VERB_EDIT_COPY, error); } -/* -gboolean -document_interface_selection_paste (DocumentInterface *object, GError **error) -{ - SPDesktop *desk = object->context.getDesktop(); - if (!desk) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document selection paste requires a GUI"); - return FALSE; - } - desktop_ensure_active (desk); - if (!object->updates) - document_interface_pause_updates (object, error); - sp_selection_paste (object->desk, TRUE); - if (!object->updates) - document_interface_pause_updates (object, error); - return TRUE; - //return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); -} -*/ + gboolean document_interface_selection_paste (DocumentInterface *object, GError **error) { + SPDesktop *desk = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); } gboolean document_interface_selection_scale(DocumentInterface *object, gdouble grow, GError ** /*error*/) { - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); if (!selection) { return FALSE; @@ -1283,13 +1238,13 @@ gboolean document_interface_selection_scale(DocumentInterface *object, gdouble g gboolean document_interface_selection_move(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) { - sp_selection_move(object->context.getSelection(), x, 0 - y); //switching coordinate systems. + sp_selection_move(object->doc_context.getSelection(), x, 0 - y); //switching coordinate systems. return TRUE; } gboolean document_interface_selection_move_to(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) { - Inkscape::Selection * sel = object->context.getSelection(); + Inkscape::Selection * sel = object->doc_context.getSelection(); Geom::OptRect sel_bbox = sel->visualBounds(); if (sel_bbox) { @@ -1306,19 +1261,16 @@ gboolean document_interface_selection_move_to_layer (DocumentInterface *object, gchar *layerstr, GError **error) { - SPDesktop *dt = object->context.getDesktop(); - if (!dt) { - g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document selection move to layer requires a GUI"); - return FALSE; - } + SPDesktop *dt = object->doc_context.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(dt, error), FALSE); - Inkscape::Selection *selection = object->context.getSelection(); + Inkscape::Selection *selection = object->doc_context.getSelection(); // check if something is selected if (selection->isEmpty()) return FALSE; - SPObject *next = get_object_by_name(object->context.getDocument(), layerstr, error); + SPObject *next = get_object_by_name(object->doc_context.getDocument(), layerstr, error); if (!next) return FALSE; @@ -1327,7 +1279,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, sp_selection_cut(dt); - object->context.getSelection()->layerModel()->setCurrentLayer(next); + object->doc_context.getSelection()->layers()->setCurrentLayer(next); sp_selection_paste(dt, TRUE); } @@ -1337,7 +1289,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, GArray * document_interface_selection_get_center (DocumentInterface *object) { - Inkscape::Selection * sel = object->context.getSelection(); + Inkscape::Selection * sel = object->doc_context.getSelection(); if (sel) { @@ -1403,9 +1355,9 @@ document_interface_selection_change_level (DocumentInterface *object, gchar *cmd gchar *document_interface_layer_new(DocumentInterface *object, GError ** /*error*/) { - Inkscape::LayerModel * layerModel = object->context.getSelection()->layerModel(); - SPObject *new_layer = Inkscape::create_layer(layerModel->currentRoot(), layerModel->currentLayer(), Inkscape::LPOS_BELOW); - layerModel->setCurrentLayer(new_layer); + Inkscape::LayerModel * layers = object->doc_context.getSelection()->layers(); + SPObject *new_layer = Inkscape::create_layer(layers->currentRoot(), layers->currentLayer(), Inkscape::LPOS_BELOW); + layers->setCurrentLayer(new_layer); return g_strdup(get_name_from_object(new_layer)); } @@ -1413,12 +1365,12 @@ gboolean document_interface_layer_set (DocumentInterface *object, gchar *layerstr, GError **error) { - SPObject * obj = get_object_by_name (object->context.getDocument(), layerstr, error); + SPObject * obj = get_object_by_name (object->doc_context.getDocument(), layerstr, error); if (!obj) return FALSE; - object->context.getSelection()->layerModel()->setCurrentLayer (obj); + object->doc_context.getSelection()->layers()->setCurrentLayer (obj); return TRUE; } @@ -1462,7 +1414,6 @@ document_interface_layer_previous (DocumentInterface *object, GError **error) DocumentInterface *fugly; gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) { - //DocumentInterface *obj; if (!item) return TRUE; g_signal_emit (desk->dbus_document_interface, signals[OBJECT_MOVED_SIGNAL], 0, item->getId()); return TRUE; @@ -1474,7 +1425,7 @@ gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) gboolean document_interface_get_children (DocumentInterface *object, char *name, char ***out, GError **error) { - SPItem* parent=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* parent=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); GSList const *children = parent->childList(false); @@ -1497,7 +1448,7 @@ document_interface_get_children (DocumentInterface *object, char *name, char ** gchar* document_interface_get_parent (DocumentInterface *object, char *name, GError **error) { - SPItem* node=(SPItem* )get_object_by_name(object->context.getDocument(), name, error); + SPItem* node=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); SPObject* parent=node->parent; @@ -1509,7 +1460,7 @@ document_interface_get_parent (DocumentInterface *object, char *name, GError ** //just pseudo code gboolean document_interface_get_xpath (DocumentInterface *object, char *xpath_expression, char ***out, GError **error){ - SPDocument * doc = object->context.getDocument(); + SPDocument * doc = object->doc_context.getDocument(); Inkscape::XML::Document *repr = doc->getReprDoc(); xmlXPathObjectPtr xpathObj; diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 5eef3d0c0..f90fe7c80 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -52,7 +52,7 @@ typedef struct _DocumentInterfaceClass DocumentInterfaceClass; struct _DocumentInterface { GObject parent; - Inkscape::ActionContext context; + Inkscape::ActionContext doc_context; ///< stores information about which document, selection, desktop etc this interface is linked to gboolean updates; }; diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 93b1bb91d..dcccf3d7d 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -368,12 +368,9 @@ Effect::EffectVerb::make_action (Inkscape::ActionContext const & context) void Effect::EffectVerb::perform( SPAction *action, void * data ) { + g_return_if_fail(ensure_desktop_valid(action)); Inkscape::UI::View::View * current_view = sp_action_get_view(action); - if (current_view == NULL) { - show_gui_required_message(action); - return; - } -// SPDocument * current_document = current_view->doc; + Effect::EffectVerb * ev = reinterpret_cast(data); Effect * effect = ev->_effect; -- cgit v1.2.3 From 036013caefc09f34ef9b418e1ca148a821c777d6 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Thu, 4 Jul 2013 23:51:56 +0100 Subject: Further renaming of DBus variables (object -> app_interface/doc_interface and doc_context -> target) Fixes to application interface for document_new (now only works in console mode, and behaves as expected) (bzr r12387.1.8) --- src/extension/dbus/application-interface.cpp | 48 ++- src/extension/dbus/application-interface.h | 20 +- src/extension/dbus/application-interface.xml | 9 +- src/extension/dbus/dbus-init.cpp | 107 +++--- src/extension/dbus/document-interface.cpp | 474 +++++++++++++-------------- src/extension/dbus/document-interface.h | 166 +++++----- 6 files changed, 424 insertions(+), 400 deletions(-) (limited to 'src/extension') diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp index 1b1dbf0f5..c0bc19d90 100644 --- a/src/extension/dbus/application-interface.cpp +++ b/src/extension/dbus/application-interface.cpp @@ -19,6 +19,7 @@ #include #include "dbus-init.h" #include "file.h" +#include "inkscape.h" G_DEFINE_TYPE(ApplicationInterface, application_interface, G_TYPE_OBJECT) @@ -38,13 +39,32 @@ application_interface_class_init (ApplicationInterfaceClass *klass) } static void -application_interface_init (ApplicationInterface *object) +application_interface_init (ApplicationInterface *app_interface) { dbus_g_error_domain_register (INKSCAPE_ERROR, NULL, INKSCAPE_TYPE_ERROR); } +static bool +ensure_desktop_valid(GError **error) +{ + if (!inkscape_use_gui()) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires a GUI"); + return false; + } + return true; +} + +static bool +ensure_desktop_not_present(GError **error) +{ + if (inkscape_use_gui()) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires non-GUI (command line) mode"); + return false; + } + return true; +} ApplicationInterface * application_interface_new (void) @@ -95,27 +115,28 @@ GType inkscape_error_get_type(void) ****************************************************************************/ gchar* -application_interface_desktop_new (ApplicationInterface *object, +application_interface_desktop_new (ApplicationInterface *app_interface, GError **error) { - return (gchar*)Inkscape::Extension::Dbus::init_desktop(); + g_return_val_if_fail(ensure_desktop_valid(error), NULL); + return (gchar*)Inkscape::Extension::Dbus::init_desktop(); } gchar** -application_interface_get_desktop_list (ApplicationInterface *object) +application_interface_get_desktop_list (ApplicationInterface *app_interface) { return NULL; } gchar* -application_interface_get_active_desktop (ApplicationInterface *object, +application_interface_get_active_desktop (ApplicationInterface *app_interface, GError **error) { return NULL; } gboolean -application_interface_set_active_desktop (ApplicationInterface *object, +application_interface_set_active_desktop (ApplicationInterface *app_interface, gchar* document_name, GError **error) { @@ -123,14 +144,14 @@ application_interface_set_active_desktop (ApplicationInterface *object, } gboolean -application_interface_desktop_close_all (ApplicationInterface *object, +application_interface_desktop_close_all (ApplicationInterface *app_interface, GError **error) { return TRUE; } gboolean -application_interface_exit (ApplicationInterface *object, GError **error) +application_interface_exit (ApplicationInterface *app_interface, GError **error) { sp_file_exit(); return TRUE; @@ -140,14 +161,15 @@ application_interface_exit (ApplicationInterface *object, GError **error) DOCUMENT FUNCTIONS ****************************************************************************/ -gchar* application_interface_document_new (ApplicationInterface *object, +gchar* application_interface_document_new (ApplicationInterface *app_interface, GError **error) { - return (gchar*)Inkscape::Extension::Dbus::init_document(); + g_return_val_if_fail(ensure_desktop_not_present(error), NULL); + return (gchar*)Inkscape::Extension::Dbus::init_document(); } gchar* -application_interface_get_active_document(ApplicationInterface *object, +application_interface_get_active_document(ApplicationInterface *app_interface, GError **error) { gchar *result = (gchar*)Inkscape::Extension::Dbus::init_active_document(); @@ -158,13 +180,13 @@ application_interface_get_active_document(ApplicationInterface *object, } gchar** -application_interface_get_document_list (ApplicationInterface *object) +application_interface_get_document_list (ApplicationInterface *app_interface) { return NULL; } gboolean -application_interface_document_close_all (ApplicationInterface *object, +application_interface_document_close_all (ApplicationInterface *app_interface, GError **error) { return TRUE; diff --git a/src/extension/dbus/application-interface.h b/src/extension/dbus/application-interface.h index b01fee912..c108402cb 100644 --- a/src/extension/dbus/application-interface.h +++ b/src/extension/dbus/application-interface.h @@ -67,45 +67,45 @@ GType inkscape_error_get_type (void); ****************************************************************************/ gchar* -application_interface_desktop_new (ApplicationInterface *object, +application_interface_desktop_new (ApplicationInterface *app_interface, GError **error); gchar** -application_interface_get_desktop_list (ApplicationInterface *object); +application_interface_get_desktop_list (ApplicationInterface *app_interface); gchar* -application_interface_get_active_desktop (ApplicationInterface *object, +application_interface_get_active_desktop (ApplicationInterface *app_interface, GError **error); gboolean -application_interface_set_active_desktop (ApplicationInterface *object, +application_interface_set_active_desktop (ApplicationInterface *app_interface, gchar* document_name, GError **error); gboolean -application_interface_desktop_close_all (ApplicationInterface *object, +application_interface_desktop_close_all (ApplicationInterface *app_interface, GError **error); gboolean -application_interface_exit (ApplicationInterface *object, GError **error); +application_interface_exit (ApplicationInterface *app_interface, GError **error); /**************************************************************************** DOCUMENT FUNCTIONS ****************************************************************************/ gchar* -application_interface_document_new (ApplicationInterface *object, +application_interface_document_new (ApplicationInterface *app_interface, GError **error); gchar* -application_interface_get_active_document(ApplicationInterface *object, +application_interface_get_active_document(ApplicationInterface *app_interface, GError **error); gchar** -application_interface_get_document_list (ApplicationInterface *object); +application_interface_get_document_list (ApplicationInterface *app_interface); gboolean -application_interface_document_close_all (ApplicationInterface *object, +application_interface_document_close_all (ApplicationInterface *app_interface, GError **error); diff --git a/src/extension/dbus/application-interface.xml b/src/extension/dbus/application-interface.xml index 4185c7e53..1553971cc 100644 --- a/src/extension/dbus/application-interface.xml +++ b/src/extension/dbus/application-interface.xml @@ -32,7 +32,7 @@ - Create a new document interface and return its location. + Create a new document interface and return its location. Only call this when Inkscape is running in GUI mode. @@ -45,21 +45,21 @@ - List all the interfaces that it is possible to connect to. + List all the interfaces that it is possible to connect to. TODO: not implemented. - Close all document interfaces without saving. + Close all document interfaces without saving. TODO: not implemented. - Exit Inkscape without saving (in GUI mode). Fairly straightforward. + Exit Inkscape without saving. Fairly straightforward. @@ -77,6 +77,7 @@ Originally, there were going to be two interfaces. A desktop and a document. Desktops would be used when the user wanted to see the result of their code and documents would be used when less overhead was desired. Unfortunately as more and more of the code can to rely on the desktop and it's associated support code (including selections and verbs) the document interface was looking more and more limited. Ultimately I decided to just go with the desktop interface since I didn't have a compelling reason for keeping the other one and having two similar interfaces could be very confusing. The desktop interface inherited the document name because I believe it's more familiar to people. Perhaps it would be best to have an option as to whether or not to create a window and fail with a good error message when they call a function that requires one. Or have a second interface for different use cases but have it be completely different, rather than a subset of the first if there are use cases that support it. UPDATE: 3rd July 2013, Eric Greveson: After having done some initial work to attempt to decouple Inkscape "verbs" from desktops, it is now possible to run a limited subset of actions in command-line mode (with a selection model and document, but no desktop). I believe that the "single document interface" approach, with some functions that may require a GUI, is the better path, and so document interfaces without a desktop are now possible. Most functions still require the desktop to work, though, with the notable exception of selection methods and Boolean operations. + As a result, this function should ONLY be called when using Inkscape in command-line mode. Use "desktop_new" instead if running in GUI mode. diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index fe59fc154..eb62f4b3a 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -78,6 +78,44 @@ dbus_register_object (DBusGConnection *connection, return object; } +/* + * PRIVATE register a document interface for the document in the given ActionContext, if none exists. + * Return the DBus path to the interface (something like /org/inkscape/document_0). + * Note that while a DocumentInterface could be used either for a document with no desktop, or a + * document with a desktop, this function is only used for creating interfaces in the former case. + * Desktop-associated DocumentInterfaces are named /org/inkscape/desktop_0, etc. + * FIXME: This state of affairs probably needs tidying up at some point in the future. + */ +static gchar * +dbus_register_document(Inkscape::ActionContext const & target) +{ + SPDocument *doc = target.getDocument(); + g_assert(doc != NULL); + + // Document name is not suitable for DBus name, as it might contain invalid chars + std::string name("/org/inkscape/document_"); + std::stringstream ss; + ss << doc->serial(); + name.append(ss.str()); + + DBusGConnection *connection = dbus_get_connection(); + DBusGProxy *proxy = dbus_get_proxy(connection); + + // Has the document already been registered? + if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { + // No - register it + DocumentInterface *doc_interface = (DocumentInterface*) dbus_register_object (connection, + proxy, + TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, + name.c_str()); + + // Set the document info for this interface + doc_interface->target = target; + } + return strdup(name.c_str()); +} + /* Initialize a Dbus service */ void init (void) @@ -97,34 +135,19 @@ init (void) TYPE_APPLICATION_INTERFACE, &dbus_glib_application_interface_object_info, DBUS_APPLICATION_INTERFACE_PATH); -} //init +} gchar * -init_document (void) { - DBusGConnection *connection; - DBusGProxy *proxy; - SPDocument *doc; - - doc = SPDocument::createNewDoc(NULL, 1, TRUE); - - std::string name("/org/inkscape/"); - // This only works because a new document's name happens to contain - // only valid DBus characters [A-Z][a-z][0-9]_ - // TODO: use the document->serial() instead, like below, and similar to - // how desktops work? - name.append(doc->getName()); - std::replace(name.begin(), name.end(), ' ', '_'); - - connection = dbus_get_connection(); - proxy = dbus_get_proxy(connection); +init_document (void) +{ + // This is for command-line use only + g_assert(!inkscape_use_gui()); - dbus_register_object (connection, - proxy, - TYPE_DOCUMENT_INTERFACE, - &dbus_glib_document_interface_object_info, - name.c_str()); - return strdup(name.c_str()); -} //init_document + // Create a blank document and get its selection model etc in an ActionContext + SPDocument *doc = SPDocument::createNewDoc(NULL, 1, TRUE); + inkscape_add_document(doc); + return dbus_register_document(inkscape_action_context_for_document(doc)); +} gchar * init_active_document() @@ -134,28 +157,7 @@ init_active_document() return NULL; } - // Document name is not suitable for DBus name, as it might contain invalid chars - std::string name("/org/inkscape/document_"); - std::stringstream ss; - ss << doc->serial(); - name.append(ss.str()); - - DBusGConnection *connection = dbus_get_connection(); - DBusGProxy *proxy = dbus_get_proxy(connection); - - // Has the active document already been registered? - if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { - // No - register it - DocumentInterface *obj = (DocumentInterface*) dbus_register_object (connection, - proxy, - TYPE_DOCUMENT_INTERFACE, - &dbus_glib_document_interface_object_info, - name.c_str()); - - // Set the document info for this interface - obj->doc_context = inkscape_active_action_context(); - } - return strdup(name.c_str()); + return dbus_register_document(inkscape_active_action_context()); } gchar * @@ -163,7 +165,6 @@ dbus_init_desktop_interface (SPDesktop * dt) { DBusGConnection *connection; DBusGProxy *proxy; - DocumentInterface *obj; std::string name("/org/inkscape/desktop_"); std::stringstream out; @@ -175,12 +176,12 @@ dbus_init_desktop_interface (SPDesktop * dt) connection = dbus_get_connection(); proxy = dbus_get_proxy(connection); - obj = (DocumentInterface*) dbus_register_object (connection, + DocumentInterface *doc_interface = (DocumentInterface*) dbus_register_object (connection, proxy, TYPE_DOCUMENT_INTERFACE, &dbus_glib_document_interface_object_info, name.c_str()); - obj->doc_context = Inkscape::ActionContext(dt); - obj->updates = TRUE; - dt->dbus_document_interface=obj; + doc_interface->target = Inkscape::ActionContext(dt); + doc_interface->updates = TRUE; + dt->dbus_document_interface=doc_interface; return strdup(name.c_str()); } @@ -195,7 +196,7 @@ init_desktop (void) { out << dt->dkey; name.append(out.str()); return strdup(name.c_str()); -} //init_desktop +} diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 6d6f983c5..3cb03646a 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -221,11 +221,11 @@ dbus_create_node (SPDocument *doc, const gchar *type) * There is probably a better way to do this (use the shape tools default styles) * but I'm not sure how. */ -gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inkscape::XML::Node *newNode, gchar *desc) +gchar *finish_create_shape (DocumentInterface *doc_interface, GError ** /*error*/, Inkscape::XML::Node *newNode, gchar *desc) { SPCSSAttr *style = NULL; - if (object->doc_context.getDesktop()) { - style = sp_desktop_get_style(object->doc_context.getDesktop(), TRUE); + if (doc_interface->target.getDesktop()) { + style = sp_desktop_get_style(doc_interface->target.getDesktop(), TRUE); } if (style) { Glib::ustring str; @@ -236,11 +236,11 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks newNode->setAttribute("style", "fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none", TRUE); } - object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); - object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); + doc_interface->target.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + doc_interface->target.getSelection()->layers()->currentLayer()->updateRepr(); - if (object->updates) { - Inkscape::DocumentUndo::done(object->doc_context.getDocument(), 0, (gchar *)desc); + if (doc_interface->updates) { + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), 0, (gchar *)desc); } return strdup(newNode->attribute("id")); @@ -255,19 +255,19 @@ gchar *finish_create_shape (DocumentInterface *object, GError ** /*error*/, Inks * document_interface_call_verb is similar but is called by the user. */ gboolean -dbus_call_verb (DocumentInterface *object, int verbid, GError **error) +dbus_call_verb (DocumentInterface *doc_interface, int verbid, GError **error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); if ( desk ) { desktop_ensure_active (desk); } Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); if ( verb ) { - SPAction *action = verb->get_action(object->doc_context); + SPAction *action = verb->get_action(doc_interface->target); if ( action ) { sp_action_perform( action, NULL ); - if (object->updates) - Inkscape::DocumentUndo::done(object->doc_context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); + if (doc_interface->updates) + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); return TRUE; } } @@ -319,9 +319,9 @@ document_interface_class_init (DocumentInterfaceClass *klass) } static void -document_interface_init (DocumentInterface *object) +document_interface_init (DocumentInterface *doc_interface) { - object->doc_context = Inkscape::ActionContext(); + doc_interface->target = Inkscape::ActionContext(); } @@ -337,26 +337,26 @@ document_interface_new (void) MISC FUNCTIONS ****************************************************************************/ -gboolean document_interface_delete_all(DocumentInterface *object, GError ** /*error*/) +gboolean document_interface_delete_all(DocumentInterface *doc_interface, GError ** /*error*/) { - sp_edit_clear_all(object->doc_context.getSelection()); + sp_edit_clear_all(doc_interface->target.getSelection()); return TRUE; } gboolean -document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error) +document_interface_call_verb (DocumentInterface *doc_interface, gchar *verbid, GError **error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); if ( desk ) { desktop_ensure_active (desk); } Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid ); if ( verb ) { - SPAction *action = verb->get_action(object->doc_context); + SPAction *action = verb->get_action(doc_interface->target); if ( action ) { sp_action_perform( action, NULL ); - if (object->updates) { - Inkscape::DocumentUndo::done(object->doc_context.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); + if (doc_interface->updates) { + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), verb->get_code(), g_strdup(verb->get_tip())); } return TRUE; } @@ -371,39 +371,39 @@ document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError * ****************************************************************************/ gchar* -document_interface_rectangle (DocumentInterface *object, int x, int y, +document_interface_rectangle (DocumentInterface *doc_interface, int x, int y, int width, int height, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:rect"); + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:rect"); sp_repr_set_int(newNode, "x", x); //could also use newNode->setAttribute() sp_repr_set_int(newNode, "y", y); sp_repr_set_int(newNode, "width", width); sp_repr_set_int(newNode, "height", height); - return finish_create_shape (object, error, newNode, (gchar *)"create rectangle"); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create rectangle"); } gchar* -document_interface_ellipse_center (DocumentInterface *object, int cx, int cy, +document_interface_ellipse_center (DocumentInterface *doc_interface, int cx, int cy, int rx, int ry, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "arc"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); sp_repr_set_int(newNode, "sodipodi:rx", rx); sp_repr_set_int(newNode, "sodipodi:ry", ry); - return finish_create_shape (object, error, newNode, (gchar *)"create circle"); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create circle"); } gchar* -document_interface_polygon (DocumentInterface *object, int cx, int cy, +document_interface_polygon (DocumentInterface *doc_interface, int cx, int cy, int radius, int rotation, int sides, GError **error) { gdouble rot = ((rotation / 180.0) * 3.14159265) - ( 3.14159265 / 2.0); - Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "true"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -416,15 +416,15 @@ document_interface_polygon (DocumentInterface *object, int cx, int cy, sp_repr_set_svg_double(newNode, "sodipodi:arg2", rot); sp_repr_set_svg_double(newNode, "inkscape:rounded", 0); - return finish_create_shape (object, error, newNode, (gchar *)"create polygon"); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create polygon"); } gchar* -document_interface_star (DocumentInterface *object, int cx, int cy, +document_interface_star (DocumentInterface *doc_interface, int cx, int cy, int r1, int r2, int sides, gdouble rounded, gdouble arg1, gdouble arg2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); newNode->setAttribute("inkscape:flatsided", "false"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -437,35 +437,35 @@ document_interface_star (DocumentInterface *object, int cx, int cy, sp_repr_set_svg_double(newNode, "sodipodi:arg2", arg2); sp_repr_set_svg_double(newNode, "inkscape:rounded", rounded); - return finish_create_shape (object, error, newNode, (gchar *)"create star"); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create star"); } gchar* -document_interface_ellipse (DocumentInterface *object, int x, int y, +document_interface_ellipse (DocumentInterface *doc_interface, int x, int y, int width, int height, GError **error) { int rx = width/2; int ry = height/2; - return document_interface_ellipse_center (object, x+rx, y+ry, rx, ry, error); + return document_interface_ellipse_center (doc_interface, x+rx, y+ry, rx, ry, error); } gchar* -document_interface_line (DocumentInterface *object, int x, int y, +document_interface_line (DocumentInterface *doc_interface, int x, int y, int x2, int y2, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); std::stringstream out; // Not sure why this works. out << "m " << x << "," << y << " " << x2 - x << "," << y2 - y; newNode->setAttribute("d", out.str().c_str()); - return finish_create_shape (object, error, newNode, (gchar *)"create line"); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create line"); } gchar* -document_interface_spiral (DocumentInterface *object, int cx, int cy, +document_interface_spiral (DocumentInterface *doc_interface, int cx, int cy, int r, int revolutions, GError **error) { - Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:path"); + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); newNode->setAttribute("sodipodi:type", "spiral"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -474,7 +474,7 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, sp_repr_set_int(newNode, "sodipodi:t0", 0); sp_repr_set_int(newNode, "sodipodi:argument", 0); sp_repr_set_int(newNode, "sodipodi:expansion", 1); - gchar * retval = finish_create_shape (object, error, newNode, (gchar *)"create spiral"); + gchar * retval = finish_create_shape (doc_interface, error, newNode, (gchar *)"create spiral"); //Makes sure there is no fill for spirals by default. gchar* newString = g_strconcat(newNode->attribute("style"), ";fill:none", NULL); newNode->setAttribute("style", newString); @@ -483,54 +483,54 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, } gchar* -document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) +document_interface_text (DocumentInterface *doc_interface, int x, int y, gchar *text, GError **error) { - Inkscape::XML::Node *text_node = dbus_create_node(object->doc_context.getDocument(), "svg:text"); + Inkscape::XML::Node *text_node = dbus_create_node(doc_interface->target.getDocument(), "svg:text"); sp_repr_set_int(text_node, "x", x); sp_repr_set_int(text_node, "y", y); //just a workaround so i can get an spitem from the name - gchar *name = finish_create_shape (object, error, text_node, (gchar *)"create text"); + gchar *name = finish_create_shape (doc_interface, error, text_node, (gchar *)"create text"); - SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); sp_te_set_repr_text_multiline(text_obj, text); return name; } gchar * -document_interface_image (DocumentInterface *object, int x, int y, gchar *filename, GError **error) +document_interface_image (DocumentInterface *doc_interface, int x, int y, gchar *filename, GError **error) { gchar * uri = g_filename_to_uri (filename, FALSE, error); if (!uri) return FALSE; - Inkscape::XML::Node *newNode = dbus_create_node(object->doc_context.getDocument(), "svg:image"); + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:image"); sp_repr_set_int(newNode, "x", x); sp_repr_set_int(newNode, "y", y); newNode->setAttribute("xlink:href", uri); - object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); - object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); + doc_interface->target.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + doc_interface->target.getSelection()->layers()->currentLayer()->updateRepr(); - if (object->updates) - Inkscape::DocumentUndo::done(object->doc_context.getDocument(), 0, "Imported bitmap."); + if (doc_interface->updates) + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), 0, "Imported bitmap."); //g_free(uri); return strdup(newNode->attribute("id")); } -gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** /*error*/) +gchar *document_interface_node(DocumentInterface *doc_interface, gchar *type, GError ** /*error*/) { - SPDocument * doc = object->doc_context.getDocument(); + SPDocument * doc = doc_interface->target.getDocument(); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *newNode = xml_doc->createElement(type); - object->doc_context.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); - object->doc_context.getSelection()->layers()->currentLayer()->updateRepr(); + doc_interface->target.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + doc_interface->target.getSelection()->layers()->currentLayer()->updateRepr(); - if (object->updates) { + if (doc_interface->updates) { Inkscape::DocumentUndo::done(doc, 0, (gchar *)"created empty node"); } @@ -541,20 +541,20 @@ gchar *document_interface_node(DocumentInterface *object, gchar *type, GError ** ENVIRONMENT FUNCTIONS ****************************************************************************/ gdouble -document_interface_document_get_width (DocumentInterface *object) +document_interface_document_get_width (DocumentInterface *doc_interface) { - return object->doc_context.getDocument()->getWidth(); + return doc_interface->target.getDocument()->getWidth(); } gdouble -document_interface_document_get_height (DocumentInterface *object) +document_interface_document_get_height (DocumentInterface *doc_interface) { - return object->doc_context.getDocument()->getHeight(); + return doc_interface->target.getDocument()->getHeight(); } -gchar *document_interface_document_get_css(DocumentInterface *object, GError ** error) +gchar *document_interface_document_get_css(DocumentInterface *doc_interface, GError ** error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(desk, error), NULL); SPCSSAttr *current = desk->current; Glib::ustring str; @@ -562,10 +562,10 @@ gchar *document_interface_document_get_css(DocumentInterface *object, GError ** return (str.empty() ? NULL : g_strdup (str.c_str())); } -gboolean document_interface_document_merge_css(DocumentInterface *object, +gboolean document_interface_document_merge_css(DocumentInterface *doc_interface, gchar *stylestring, GError ** error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(style, stylestring); @@ -573,10 +573,10 @@ gboolean document_interface_document_merge_css(DocumentInterface *object, return TRUE; } -gboolean document_interface_document_set_css(DocumentInterface *object, +gboolean document_interface_document_set_css(DocumentInterface *doc_interface, gchar *stylestring, GError ** error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string (style, stylestring); @@ -586,14 +586,14 @@ gboolean document_interface_document_set_css(DocumentInterface *object, } gboolean -document_interface_document_resize_to_fit_selection (DocumentInterface *object, +document_interface_document_resize_to_fit_selection (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); + return dbus_call_verb (doc_interface, SP_VERB_FIT_CANVAS_TO_SELECTION, error); } gboolean -document_interface_document_set_display_area (DocumentInterface *object, +document_interface_document_set_display_area (DocumentInterface *doc_interface, double x0, double y0, double x1, @@ -601,7 +601,7 @@ document_interface_document_set_display_area (DocumentInterface *object, double border, GError **error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); desk->set_display_area (x0, y0, @@ -613,9 +613,9 @@ document_interface_document_set_display_area (DocumentInterface *object, GArray * -document_interface_document_get_display_area (DocumentInterface *object) +document_interface_document_get_display_area (DocumentInterface *doc_interface) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); if (!desk) { return NULL; } @@ -641,10 +641,10 @@ document_interface_document_get_display_area (DocumentInterface *object) ****************************************************************************/ gboolean -document_interface_set_attribute (DocumentInterface *object, char *shape, +document_interface_set_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, char *newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->doc_context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(doc_interface->target.getDocument(), shape, error); /* ALTERNATIVE (is this faster?) Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); @@ -660,11 +660,11 @@ document_interface_set_attribute (DocumentInterface *object, char *shape, } gboolean -document_interface_set_int_attribute (DocumentInterface *object, +document_interface_set_int_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, int newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->doc_context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (doc_interface->target.getDocument(), shape, error); if (!newNode) return FALSE; @@ -674,11 +674,11 @@ document_interface_set_int_attribute (DocumentInterface *object, gboolean -document_interface_set_double_attribute (DocumentInterface *object, +document_interface_set_double_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, double newval, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name (object->doc_context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name (doc_interface->target.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "New value string was empty.")) return FALSE; @@ -690,10 +690,10 @@ document_interface_set_double_attribute (DocumentInterface *object, } gchar * -document_interface_get_attribute (DocumentInterface *object, char *shape, +document_interface_get_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, GError **error) { - Inkscape::XML::Node *newNode = get_repr_by_name(object->doc_context.getDocument(), shape, error); + Inkscape::XML::Node *newNode = get_repr_by_name(doc_interface->target.getDocument(), shape, error); if (!dbus_check_string (attribute, error, "Attribute name empty.")) return NULL; @@ -704,47 +704,47 @@ document_interface_get_attribute (DocumentInterface *object, char *shape, } gboolean -document_interface_move (DocumentInterface *object, gchar *name, gdouble x, +document_interface_move (DocumentInterface *doc_interface, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->doc_context.getSelection(), name, error); + const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), name, error); if (!oldsel) return FALSE; - sp_selection_move (object->doc_context.getSelection(), x, 0 - y); - selection_restore(object->doc_context.getSelection(), oldsel); + sp_selection_move (doc_interface->target.getSelection(), x, 0 - y); + selection_restore(doc_interface->target.getSelection(), oldsel); return TRUE; } gboolean -document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, +document_interface_move_to (DocumentInterface *doc_interface, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->doc_context.getSelection(), name, error); + const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), name, error); if (!oldsel) return FALSE; - Inkscape::Selection * sel = object->doc_context.getSelection(); - sp_selection_move (object->doc_context.getSelection(), x - selection_get_center_x(sel), + Inkscape::Selection * sel = doc_interface->target.getSelection(); + sp_selection_move (doc_interface->target.getSelection(), x - selection_get_center_x(sel), 0 - (y - selection_get_center_y(sel))); - selection_restore(object->doc_context.getSelection(), oldsel); + selection_restore(doc_interface->target.getSelection(), oldsel); return TRUE; } gboolean -document_interface_object_to_path (DocumentInterface *object, +document_interface_object_to_path (DocumentInterface *doc_interface, char *shape, GError **error) { - const GSList *oldsel = selection_swap(object->doc_context.getSelection(), shape, error); + const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); if (!oldsel) return FALSE; - dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); - selection_restore(object->doc_context.getSelection(), oldsel); + dbus_call_verb (doc_interface, SP_VERB_OBJECT_TO_CURVE, error); + selection_restore(doc_interface->target.getSelection(), oldsel); return TRUE; } gchar * -document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) +document_interface_get_path (DocumentInterface *doc_interface, char *pathname, GError **error) { - Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), pathname, error); + Inkscape::XML::Node *node = get_repr_by_name(doc_interface->target.getDocument(), pathname, error); if (!node) return NULL; @@ -758,30 +758,30 @@ document_interface_get_path (DocumentInterface *object, char *pathname, GError * } gboolean -document_interface_transform (DocumentInterface *object, gchar *shape, +document_interface_transform (DocumentInterface *doc_interface, gchar *shape, gchar *transformstr, GError **error) { //FIXME: This should merge transformations. gchar trans[] = "transform"; - document_interface_set_attribute (object, shape, trans, transformstr, error); + document_interface_set_attribute (doc_interface, shape, trans, transformstr, error); return TRUE; } gchar * -document_interface_get_css (DocumentInterface *object, gchar *shape, +document_interface_get_css (DocumentInterface *doc_interface, gchar *shape, GError **error) { gchar style[] = "style"; - return document_interface_get_attribute (object, shape, style, error); + return document_interface_get_attribute (doc_interface, shape, style, error); } gboolean -document_interface_modify_css (DocumentInterface *object, gchar *shape, +document_interface_modify_css (DocumentInterface *doc_interface, gchar *shape, gchar *cssattrb, gchar *newval, GError **error) { // Doesn't like non-variable strings for some reason. gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), shape, error); + Inkscape::XML::Node *node = get_repr_by_name(doc_interface->target.getDocument(), shape, error); if (!dbus_check_string (cssattrb, error, "Attribute string empty.")) return FALSE; @@ -797,12 +797,12 @@ document_interface_modify_css (DocumentInterface *object, gchar *shape, } gboolean -document_interface_merge_css (DocumentInterface *object, gchar *shape, +document_interface_merge_css (DocumentInterface *doc_interface, gchar *shape, gchar *stylestring, GError **error) { gchar style[] = "style"; - Inkscape::XML::Node *node = get_repr_by_name(object->doc_context.getDocument(), shape, error); + Inkscape::XML::Node *node = get_repr_by_name(doc_interface->target.getDocument(), shape, error); if (!dbus_check_string (stylestring, error, "Style string empty.")) return FALSE; @@ -823,7 +823,7 @@ document_interface_merge_css (DocumentInterface *object, gchar *shape, } gboolean -document_interface_set_color (DocumentInterface *object, gchar *shape, +document_interface_set_color (DocumentInterface *doc_interface, gchar *shape, int r, int g, int b, gboolean fill, GError **error) { gchar style[15]; @@ -839,29 +839,29 @@ document_interface_set_color (DocumentInterface *object, gchar *shape, snprintf(style, 15, "stroke:#%.2x%.2x%.2x", r, g, b); if (strcmp(shape, "document") == 0) - return document_interface_document_merge_css (object, style, error); + return document_interface_document_merge_css (doc_interface, style, error); - return document_interface_merge_css (object, shape, style, error); + return document_interface_merge_css (doc_interface, shape, style, error); } gboolean -document_interface_move_to_layer (DocumentInterface *object, gchar *shape, +document_interface_move_to_layer (DocumentInterface *doc_interface, gchar *shape, gchar *layerstr, GError **error) { - const GSList *oldsel = selection_swap(object->doc_context.getSelection(), shape, error); + const GSList *oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); if (!oldsel) return FALSE; - document_interface_selection_move_to_layer(object, layerstr, error); - selection_restore(object->doc_context.getSelection(), oldsel); + document_interface_selection_move_to_layer(doc_interface, layerstr, error); + selection_restore(doc_interface->target.getSelection(), oldsel); return TRUE; } -GArray *document_interface_get_node_coordinates(DocumentInterface * /*object*/, gchar * /*shape*/) +GArray *document_interface_get_node_coordinates(DocumentInterface * /*doc_interface*/, gchar * /*shape*/) { //FIXME: Needs lot's of work. /* - Inkscape::XML::Node *shapenode = get_repr_by_name (object->doc_context.getDocument(), shape, error); + Inkscape::XML::Node *shapenode = get_repr_by_name (doc_interface->target.getDocument(), shape, error); if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } @@ -876,10 +876,10 @@ GArray *document_interface_get_node_coordinates(DocumentInterface * /*object*/, gboolean -document_interface_set_text (DocumentInterface *object, gchar *name, gchar *text, GError **error) +document_interface_set_text (DocumentInterface *doc_interface, gchar *name, gchar *text, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); //TODO verify object type if (!text_obj) return FALSE; @@ -891,12 +891,12 @@ document_interface_set_text (DocumentInterface *object, gchar *name, gchar *text gboolean -document_interface_text_apply_style (DocumentInterface *object, gchar *name, +document_interface_text_apply_style (DocumentInterface *doc_interface, gchar *name, int start_pos, int end_pos, gchar *style, gchar *styleval, GError **error) { - SPItem* text_obj=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); + SPItem* text_obj=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); //void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPCSSAttr const *css) //TODO verify object type @@ -923,40 +923,40 @@ document_interface_text_apply_style (DocumentInterface *object, gchar *name, ****************************************************************************/ gboolean -document_interface_save (DocumentInterface *object, GError **error) +document_interface_save (DocumentInterface *doc_interface, GError **error) { - SPDocument * doc = object->doc_context.getDocument(); + SPDocument * doc = doc_interface->target.getDocument(); printf("1: %s\n2: %s\n3: %s\n", doc->getURI(), doc->getBase(), doc->getName()); if (doc->getURI()) - return document_interface_save_as (object, doc->getURI(), error); + return document_interface_save_as (doc_interface, doc->getURI(), error); return FALSE; } -gboolean document_interface_load(DocumentInterface *object, +gboolean document_interface_load(DocumentInterface *doc_interface, gchar *filename, GError ** /*error*/) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); if (desk) { desktop_ensure_active(desk); } const Glib::ustring file(filename); sp_file_open(file, NULL, TRUE, TRUE); - if (object->updates) { - Inkscape::DocumentUndo::done(object->doc_context.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); + if (doc_interface->updates) { + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); } return TRUE; } gchar * -document_interface_import (DocumentInterface *object, +document_interface_import (DocumentInterface *doc_interface, gchar *filename, GError **error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); if (desk) { desktop_ensure_active(desk); } const Glib::ustring file(filename); - SPDocument * doc = object->doc_context.getDocument(); + SPDocument * doc = doc_interface->target.getDocument(); SPObject *new_obj = NULL; new_obj = file_import(doc, file, NULL); @@ -964,11 +964,11 @@ document_interface_import (DocumentInterface *object, } gboolean -document_interface_save_as (DocumentInterface *object, +document_interface_save_as (DocumentInterface *doc_interface, const gchar *filename, GError **error) { // FIXME: Isn't there a verb we can use for this instead? - SPDocument * doc = object->doc_context.getDocument(); + SPDocument * doc = doc_interface->target.getDocument(); #ifdef WITH_GNOME_VFS const Glib::ustring file(filename); return file_save_remote(doc, file, NULL, TRUE, TRUE); @@ -988,9 +988,9 @@ document_interface_save_as (DocumentInterface *object, return true; } -gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError ** /*error*/) +gboolean document_interface_mark_as_unmodified(DocumentInterface *doc_interface, GError ** /*error*/) { - SPDocument * doc = object->doc_context.getDocument(); + SPDocument * doc = doc_interface->target.getDocument(); if (doc) { doc->modified_since_save = FALSE; } @@ -999,9 +999,9 @@ gboolean document_interface_mark_as_unmodified(DocumentInterface *object, GError /* gboolean -document_interface_print_to_file (DocumentInterface *object, GError **error) +document_interface_print_to_file (DocumentInterface *doc_interface, GError **error) { - SPDocument * doc = object->doc_context.getDocument(); + SPDocument * doc = doc_interface->target.getDocument(); sp_print_document_to_file (doc, g_strdup("/home/soren/test.pdf")); return TRUE; @@ -1012,27 +1012,27 @@ document_interface_print_to_file (DocumentInterface *object, GError **error) ****************************************************************************/ gboolean -document_interface_close (DocumentInterface *object, GError **error) +document_interface_close (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_FILE_CLOSE_VIEW, error); + return dbus_call_verb (doc_interface, SP_VERB_FILE_CLOSE_VIEW, error); } gboolean -document_interface_exit (DocumentInterface *object, GError **error) +document_interface_exit (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_FILE_QUIT, error); + return dbus_call_verb (doc_interface, SP_VERB_FILE_QUIT, error); } gboolean -document_interface_undo (DocumentInterface *object, GError **error) +document_interface_undo (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_EDIT_UNDO, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_UNDO, error); } gboolean -document_interface_redo (DocumentInterface *object, GError **error) +document_interface_redo (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_EDIT_REDO, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_REDO, error); } @@ -1044,29 +1044,29 @@ document_interface_redo (DocumentInterface *object, GError **error) Need to make sure it plays well with verbs because they are used so much. ****************************************************************************/ -void document_interface_pause_updates(DocumentInterface *object, GError ** error) +void document_interface_pause_updates(DocumentInterface *doc_interface, GError ** error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_if_fail(ensure_desktop_valid(desk, error)); - object->updates = FALSE; + doc_interface->updates = FALSE; desk->canvas->drawing_disabled = 1; } -void document_interface_resume_updates(DocumentInterface *object, GError ** error) +void document_interface_resume_updates(DocumentInterface *doc_interface, GError ** error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_if_fail(ensure_desktop_valid(desk, error)); - object->updates = TRUE; + doc_interface->updates = TRUE; desk->canvas->drawing_disabled = 0; //FIXME: use better verb than rect. - Inkscape::DocumentUndo::done(object->doc_context.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); } -void document_interface_update(DocumentInterface *object, GError ** error) +void document_interface_update(DocumentInterface *doc_interface, GError ** error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_if_fail(ensure_desktop_valid(desk, error)); - SPDocument *doc = object->doc_context.getDocument(); + SPDocument *doc = doc_interface->target.getDocument(); doc->getRoot()->uflags = TRUE; doc->getRoot()->mflags = TRUE; desk->enableInteraction(); @@ -1081,9 +1081,9 @@ void document_interface_update(DocumentInterface *object, GError ** error) SELECTION FUNCTIONS FIXME: use call_verb where appropriate (once update system is tested.) ****************************************************************************/ -gboolean document_interface_selection_get(DocumentInterface *object, char ***out, GError ** /*error*/) +gboolean document_interface_selection_get(DocumentInterface *doc_interface, char ***out, GError ** /*error*/) { - Inkscape::Selection * sel = object->doc_context.getSelection(); + Inkscape::Selection * sel = doc_interface->target.getSelection(); GSList const *oldsel = sel->list(); int size = g_slist_length((GSList *) oldsel); @@ -1101,82 +1101,82 @@ gboolean document_interface_selection_get(DocumentInterface *object, char ***out } gboolean -document_interface_selection_add (DocumentInterface *object, char *name, GError **error) +document_interface_selection_add (DocumentInterface *doc_interface, char *name, GError **error) { - SPObject * obj = get_object_by_name(object->doc_context.getDocument(), name, error); + SPObject * obj = get_object_by_name(doc_interface->target.getDocument(), name, error); if (!obj) return FALSE; - Inkscape::Selection *selection = object->doc_context.getSelection(); + Inkscape::Selection *selection = doc_interface->target.getSelection(); selection->add(obj); return TRUE; } gboolean -document_interface_selection_add_list (DocumentInterface *object, +document_interface_selection_add_list (DocumentInterface *doc_interface, char **names, GError **error) { int i; for (i=0;names[i] != NULL;i++) { - document_interface_selection_add(object, names[i], error); + document_interface_selection_add(doc_interface, names[i], error); } return TRUE; } -gboolean document_interface_selection_set(DocumentInterface *object, char *name, GError ** /*error*/) +gboolean document_interface_selection_set(DocumentInterface *doc_interface, char *name, GError ** /*error*/) { - SPDocument * doc = object->doc_context.getDocument(); - Inkscape::Selection *selection = object->doc_context.getSelection(); + SPDocument * doc = doc_interface->target.getDocument(); + Inkscape::Selection *selection = doc_interface->target.getSelection(); selection->set(doc->getObjectById(name)); return TRUE; } gboolean -document_interface_selection_set_list (DocumentInterface *object, +document_interface_selection_set_list (DocumentInterface *doc_interface, gchar **names, GError **error) { - object->doc_context.getSelection()->clear(); + doc_interface->target.getSelection()->clear(); int i; for (i=0;names[i] != NULL;i++) { - document_interface_selection_add(object, names[i], error); + document_interface_selection_add(doc_interface, names[i], error); } return TRUE; } -gboolean document_interface_selection_rotate(DocumentInterface *object, int angle, GError ** /*error*/) +gboolean document_interface_selection_rotate(DocumentInterface *doc_interface, int angle, GError ** /*error*/) { - Inkscape::Selection *selection = object->doc_context.getSelection(); + Inkscape::Selection *selection = doc_interface->target.getSelection(); sp_selection_rotate(selection, angle); return TRUE; } gboolean -document_interface_selection_delete (DocumentInterface *object, GError **error) +document_interface_selection_delete (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_EDIT_DELETE, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_DELETE, error); } -gboolean document_interface_selection_clear(DocumentInterface *object, GError ** /*error*/) +gboolean document_interface_selection_clear(DocumentInterface *doc_interface, GError ** /*error*/) { - object->doc_context.getSelection()->clear(); + doc_interface->target.getSelection()->clear(); return TRUE; } gboolean -document_interface_select_all (DocumentInterface *object, GError **error) +document_interface_select_all (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_SELECT_ALL, error); } gboolean -document_interface_select_all_in_all_layers(DocumentInterface *object, +document_interface_select_all_in_all_layers(DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error); } -gboolean document_interface_selection_box(DocumentInterface * /*object*/, int /*x*/, int /*y*/, +gboolean document_interface_selection_box(DocumentInterface * /*doc_interface*/, int /*x*/, int /*y*/, int /*x2*/, int /*y2*/, gboolean /*replace*/, GError ** /*error*/) { @@ -1185,49 +1185,49 @@ gboolean document_interface_selection_box(DocumentInterface * /*object*/, int /* } gboolean -document_interface_selection_invert (DocumentInterface *object, GError **error) +document_interface_selection_invert (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_EDIT_INVERT, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_INVERT, error); } gboolean -document_interface_selection_group (DocumentInterface *object, GError **error) +document_interface_selection_group (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_SELECTION_GROUP, error); + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_GROUP, error); } gboolean -document_interface_selection_ungroup (DocumentInterface *object, GError **error) +document_interface_selection_ungroup (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_SELECTION_UNGROUP, error); + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_UNGROUP, error); } gboolean -document_interface_selection_cut (DocumentInterface *object, GError **error) +document_interface_selection_cut (DocumentInterface *doc_interface, GError **error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); - return dbus_call_verb (object, SP_VERB_EDIT_CUT, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_CUT, error); } gboolean -document_interface_selection_copy (DocumentInterface *object, GError **error) +document_interface_selection_copy (DocumentInterface *doc_interface, GError **error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); - return dbus_call_verb (object, SP_VERB_EDIT_COPY, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_COPY, error); } gboolean -document_interface_selection_paste (DocumentInterface *object, GError **error) +document_interface_selection_paste (DocumentInterface *doc_interface, GError **error) { - SPDesktop *desk = object->doc_context.getDesktop(); + SPDesktop *desk = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); - return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_PASTE, error); } -gboolean document_interface_selection_scale(DocumentInterface *object, gdouble grow, GError ** /*error*/) +gboolean document_interface_selection_scale(DocumentInterface *doc_interface, gdouble grow, GError ** /*error*/) { - Inkscape::Selection *selection = object->doc_context.getSelection(); + Inkscape::Selection *selection = doc_interface->target.getSelection(); if (!selection) { return FALSE; @@ -1236,15 +1236,15 @@ gboolean document_interface_selection_scale(DocumentInterface *object, gdouble g return TRUE; } -gboolean document_interface_selection_move(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) +gboolean document_interface_selection_move(DocumentInterface *doc_interface, gdouble x, gdouble y, GError ** /*error*/) { - sp_selection_move(object->doc_context.getSelection(), x, 0 - y); //switching coordinate systems. + sp_selection_move(doc_interface->target.getSelection(), x, 0 - y); //switching coordinate systems. return TRUE; } -gboolean document_interface_selection_move_to(DocumentInterface *object, gdouble x, gdouble y, GError ** /*error*/) +gboolean document_interface_selection_move_to(DocumentInterface *doc_interface, gdouble x, gdouble y, GError ** /*error*/) { - Inkscape::Selection * sel = object->doc_context.getSelection(); + Inkscape::Selection * sel = doc_interface->target.getSelection(); Geom::OptRect sel_bbox = sel->visualBounds(); if (sel_bbox) { @@ -1258,19 +1258,19 @@ gboolean document_interface_selection_move_to(DocumentInterface *object, gdouble // This needs to use lower level cut_impl and paste_impl (messy) // See the built-in sp_selection_to_next_layer and duplicate. gboolean -document_interface_selection_move_to_layer (DocumentInterface *object, +document_interface_selection_move_to_layer (DocumentInterface *doc_interface, gchar *layerstr, GError **error) { - SPDesktop *dt = object->doc_context.getDesktop(); + SPDesktop *dt = doc_interface->target.getDesktop(); g_return_val_if_fail(ensure_desktop_valid(dt, error), FALSE); - Inkscape::Selection *selection = object->doc_context.getSelection(); + Inkscape::Selection *selection = doc_interface->target.getSelection(); // check if something is selected if (selection->isEmpty()) return FALSE; - SPObject *next = get_object_by_name(object->doc_context.getDocument(), layerstr, error); + SPObject *next = get_object_by_name(doc_interface->target.getDocument(), layerstr, error); if (!next) return FALSE; @@ -1279,7 +1279,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, sp_selection_cut(dt); - object->doc_context.getSelection()->layers()->setCurrentLayer(next); + doc_interface->target.getSelection()->layers()->setCurrentLayer(next); sp_selection_paste(dt, TRUE); } @@ -1287,9 +1287,9 @@ document_interface_selection_move_to_layer (DocumentInterface *object, } GArray * -document_interface_selection_get_center (DocumentInterface *object) +document_interface_selection_get_center (DocumentInterface *doc_interface) { - Inkscape::Selection * sel = object->doc_context.getSelection(); + Inkscape::Selection * sel = doc_interface->target.getSelection(); if (sel) { @@ -1306,46 +1306,46 @@ document_interface_selection_get_center (DocumentInterface *object) } gboolean -document_interface_selection_to_path (DocumentInterface *object, GError **error) +document_interface_selection_to_path (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); + return dbus_call_verb (doc_interface, SP_VERB_OBJECT_TO_CURVE, error); } gboolean -document_interface_selection_combine (DocumentInterface *object, gchar *cmd, char ***newpaths, +document_interface_selection_combine (DocumentInterface *doc_interface, gchar *cmd, char ***newpaths, GError **error) { if (strcmp(cmd, "union") == 0) - dbus_call_verb (object, SP_VERB_SELECTION_UNION, error); + dbus_call_verb (doc_interface, SP_VERB_SELECTION_UNION, error); else if (strcmp(cmd, "intersection") == 0) - dbus_call_verb (object, SP_VERB_SELECTION_INTERSECT, error); + dbus_call_verb (doc_interface, SP_VERB_SELECTION_INTERSECT, error); else if (strcmp(cmd, "difference") == 0) - dbus_call_verb (object, SP_VERB_SELECTION_DIFF, error); + dbus_call_verb (doc_interface, SP_VERB_SELECTION_DIFF, error); else if (strcmp(cmd, "exclusion") == 0) - dbus_call_verb (object, SP_VERB_SELECTION_SYMDIFF, error); + dbus_call_verb (doc_interface, SP_VERB_SELECTION_SYMDIFF, error); else if (strcmp(cmd, "division") == 0) - dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + dbus_call_verb (doc_interface, SP_VERB_SELECTION_CUT, error); else { g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Operation command not recognised"); return FALSE; } - return document_interface_selection_get (object, newpaths, error); + return document_interface_selection_get (doc_interface, newpaths, error); } gboolean -document_interface_selection_change_level (DocumentInterface *object, gchar *cmd, +document_interface_selection_change_level (DocumentInterface *doc_interface, gchar *cmd, GError **error) { if (strcmp(cmd, "raise") == 0) - return dbus_call_verb (object, SP_VERB_SELECTION_RAISE, error); + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_RAISE, error); if (strcmp(cmd, "lower") == 0) - return dbus_call_verb (object, SP_VERB_SELECTION_LOWER, error); + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_LOWER, error); if ((strcmp(cmd, "to_top") == 0) || (strcmp(cmd, "to_front") == 0)) - return dbus_call_verb (object, SP_VERB_SELECTION_TO_FRONT, error); + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_TO_FRONT, error); if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0)) - return dbus_call_verb (object, SP_VERB_SELECTION_TO_BACK, error); + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_TO_BACK, error); return TRUE; } @@ -1353,58 +1353,58 @@ document_interface_selection_change_level (DocumentInterface *object, gchar *cmd LAYER FUNCTIONS ****************************************************************************/ -gchar *document_interface_layer_new(DocumentInterface *object, GError ** /*error*/) +gchar *document_interface_layer_new(DocumentInterface *doc_interface, GError ** /*error*/) { - Inkscape::LayerModel * layers = object->doc_context.getSelection()->layers(); + Inkscape::LayerModel * layers = doc_interface->target.getSelection()->layers(); SPObject *new_layer = Inkscape::create_layer(layers->currentRoot(), layers->currentLayer(), Inkscape::LPOS_BELOW); layers->setCurrentLayer(new_layer); return g_strdup(get_name_from_object(new_layer)); } gboolean -document_interface_layer_set (DocumentInterface *object, +document_interface_layer_set (DocumentInterface *doc_interface, gchar *layerstr, GError **error) { - SPObject * obj = get_object_by_name (object->doc_context.getDocument(), layerstr, error); + SPObject * obj = get_object_by_name (doc_interface->target.getDocument(), layerstr, error); if (!obj) return FALSE; - object->doc_context.getSelection()->layers()->setCurrentLayer (obj); + doc_interface->target.getSelection()->layers()->setCurrentLayer (obj); return TRUE; } -gchar **document_interface_layer_get_all(DocumentInterface * /*object*/) +gchar **document_interface_layer_get_all(DocumentInterface * /*doc_interface*/) { //FIXME: implement. return NULL; } gboolean -document_interface_layer_change_level (DocumentInterface *object, +document_interface_layer_change_level (DocumentInterface *doc_interface, gchar *cmd, GError **error) { if (strcmp(cmd, "raise") == 0) - return dbus_call_verb (object, SP_VERB_LAYER_RAISE, error); + return dbus_call_verb (doc_interface, SP_VERB_LAYER_RAISE, error); if (strcmp(cmd, "lower") == 0) - return dbus_call_verb (object, SP_VERB_LAYER_LOWER, error); + return dbus_call_verb (doc_interface, SP_VERB_LAYER_LOWER, error); if ((strcmp(cmd, "to_top") == 0) || (strcmp(cmd, "to_front") == 0)) - return dbus_call_verb (object, SP_VERB_LAYER_TO_TOP, error); + return dbus_call_verb (doc_interface, SP_VERB_LAYER_TO_TOP, error); if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0)) - return dbus_call_verb (object, SP_VERB_LAYER_TO_BOTTOM, error); + return dbus_call_verb (doc_interface, SP_VERB_LAYER_TO_BOTTOM, error); return TRUE; } gboolean -document_interface_layer_next (DocumentInterface *object, GError **error) +document_interface_layer_next (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_LAYER_NEXT, error); + return dbus_call_verb (doc_interface, SP_VERB_LAYER_NEXT, error); } gboolean -document_interface_layer_previous (DocumentInterface *object, GError **error) +document_interface_layer_previous (DocumentInterface *doc_interface, GError **error) { - return dbus_call_verb (object, SP_VERB_LAYER_PREV, error); + return dbus_call_verb (doc_interface, SP_VERB_LAYER_PREV, error); } @@ -1423,9 +1423,9 @@ gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) gboolean -document_interface_get_children (DocumentInterface *object, char *name, char ***out, GError **error) +document_interface_get_children (DocumentInterface *doc_interface, char *name, char ***out, GError **error) { - SPItem* parent=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); + SPItem* parent=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); GSList const *children = parent->childList(false); @@ -1446,9 +1446,9 @@ document_interface_get_children (DocumentInterface *object, char *name, char ** gchar* -document_interface_get_parent (DocumentInterface *object, char *name, GError **error) +document_interface_get_parent (DocumentInterface *doc_interface, char *name, GError **error) { - SPItem* node=(SPItem* )get_object_by_name(object->doc_context.getDocument(), name, error); + SPItem* node=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); SPObject* parent=node->parent; @@ -1459,8 +1459,8 @@ document_interface_get_parent (DocumentInterface *object, char *name, GError ** #if 0 //just pseudo code gboolean -document_interface_get_xpath (DocumentInterface *object, char *xpath_expression, char ***out, GError **error){ - SPDocument * doc = object->doc_context.getDocument(); +document_interface_get_xpath (DocumentInterface *doc_interface, char *xpath_expression, char ***out, GError **error){ + SPDocument * doc = doc_interface->target.getDocument(); Inkscape::XML::Document *repr = doc->getReprDoc(); xmlXPathObjectPtr xpathObj; diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index f90fe7c80..00d964f36 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -52,7 +52,7 @@ typedef struct _DocumentInterfaceClass DocumentInterfaceClass; struct _DocumentInterface { GObject parent; - Inkscape::ActionContext doc_context; ///< stores information about which document, selection, desktop etc this interface is linked to + Inkscape::ActionContext target; ///< stores information about which document, selection, desktop etc this interface is linked to gboolean updates; }; @@ -71,10 +71,10 @@ struct DBUSPoint { ****************************************************************************/ gboolean -document_interface_delete_all (DocumentInterface *object, GError **error); +document_interface_delete_all (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_call_verb (DocumentInterface *object, +document_interface_call_verb (DocumentInterface *doc_interface, gchar *verbid, GError **error); /**************************************************************************** @@ -82,48 +82,48 @@ document_interface_call_verb (DocumentInterface *object, ****************************************************************************/ gchar* -document_interface_rectangle (DocumentInterface *object, int x, int y, +document_interface_rectangle (DocumentInterface *doc_interface, int x, int y, int width, int height, GError **error); gchar* -document_interface_ellipse (DocumentInterface *object, int x, int y, +document_interface_ellipse (DocumentInterface *doc_interface, int x, int y, int width, int height, GError **error); gchar* -document_interface_polygon (DocumentInterface *object, int cx, int cy, +document_interface_polygon (DocumentInterface *doc_interface, int cx, int cy, int radius, int rotation, int sides, GError **error); gchar* -document_interface_star (DocumentInterface *object, int cx, int cy, +document_interface_star (DocumentInterface *doc_interface, int cx, int cy, int r1, int r2, int sides, gdouble rounded, gdouble arg1, gdouble arg2, GError **error); gchar* -document_interface_spiral (DocumentInterface *object, int cx, int cy, +document_interface_spiral (DocumentInterface *doc_interface, int cx, int cy, int r, int revolutions, GError **error); gchar* -document_interface_line (DocumentInterface *object, int x, int y, +document_interface_line (DocumentInterface *doc_interface, int x, int y, int x2, int y2, GError **error); gchar* -document_interface_text (DocumentInterface *object, int x, int y, +document_interface_text (DocumentInterface *doc_interface, int x, int y, gchar *text, GError **error); gboolean -document_interface_set_text (DocumentInterface *object, gchar *name, +document_interface_set_text (DocumentInterface *doc_interface, gchar *name, gchar *text, GError **error); gboolean -document_interface_text_apply_style (DocumentInterface *object, gchar *name, +document_interface_text_apply_style (DocumentInterface *doc_interface, gchar *name, int start_pos, int end_pos, gchar *style, gchar *styleval, GError **error); gchar * -document_interface_image (DocumentInterface *object, int x, int y, +document_interface_image (DocumentInterface *doc_interface, int x, int y, gchar *filename, GError **error); gchar* -document_interface_node (DocumentInterface *object, gchar *svgtype, +document_interface_node (DocumentInterface *doc_interface, gchar *svgtype, GError **error); @@ -131,27 +131,27 @@ document_interface_node (DocumentInterface *object, gchar *svgtype, ENVIORNMENT FUNCTIONS ****************************************************************************/ gdouble -document_interface_document_get_width (DocumentInterface *object); +document_interface_document_get_width (DocumentInterface *doc_interface); gdouble -document_interface_document_get_height (DocumentInterface *object); +document_interface_document_get_height (DocumentInterface *doc_interface); gchar * -document_interface_document_get_css (DocumentInterface *object, GError **error); +document_interface_document_get_css (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_document_merge_css (DocumentInterface *object, +document_interface_document_merge_css (DocumentInterface *doc_interface, gchar *stylestring, GError **error); gboolean -document_interface_document_set_css (DocumentInterface *object, +document_interface_document_set_css (DocumentInterface *doc_interface, gchar *stylestring, GError **error); gboolean -document_interface_document_resize_to_fit_selection (DocumentInterface *object, +document_interface_document_resize_to_fit_selection (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_document_set_display_area (DocumentInterface *object, +document_interface_document_set_display_area (DocumentInterface *doc_interface, double x0, double y0, double x1, @@ -159,95 +159,95 @@ document_interface_document_set_display_area (DocumentInterface *object, double border, GError **error); GArray * -document_interface_document_get_display_area (DocumentInterface *object); +document_interface_document_get_display_area (DocumentInterface *doc_interface); /**************************************************************************** OBJECT FUNCTIONS ****************************************************************************/ gboolean -document_interface_set_attribute (DocumentInterface *object, +document_interface_set_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, char *newval, GError **error); gboolean -document_interface_set_int_attribute (DocumentInterface *object, +document_interface_set_int_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, int newval, GError **error); gboolean -document_interface_set_double_attribute (DocumentInterface *object, +document_interface_set_double_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, double newval, GError **error); gchar * -document_interface_get_attribute (DocumentInterface *object, +document_interface_get_attribute (DocumentInterface *doc_interface, char *shape, char *attribute, GError **error); gboolean -document_interface_move (DocumentInterface *object, gchar *name, +document_interface_move (DocumentInterface *doc_interface, gchar *name, gdouble x, gdouble y, GError **error); gboolean -document_interface_move_to (DocumentInterface *object, gchar *name, +document_interface_move_to (DocumentInterface *doc_interface, gchar *name, gdouble x, gdouble y, GError **error); gboolean -document_interface_object_to_path (DocumentInterface *object, +document_interface_object_to_path (DocumentInterface *doc_interface, char *shape, GError **error); gchar * -document_interface_get_path (DocumentInterface *object, +document_interface_get_path (DocumentInterface *doc_interface, char *pathname, GError **error); gboolean -document_interface_transform (DocumentInterface *object, gchar *shape, +document_interface_transform (DocumentInterface *doc_interface, gchar *shape, gchar *transformstr, GError **error); gchar * -document_interface_get_css (DocumentInterface *object, gchar *shape, +document_interface_get_css (DocumentInterface *doc_interface, gchar *shape, GError **error); gboolean -document_interface_modify_css (DocumentInterface *object, gchar *shape, +document_interface_modify_css (DocumentInterface *doc_interface, gchar *shape, gchar *cssattrb, gchar *newval, GError **error); gboolean -document_interface_merge_css (DocumentInterface *object, gchar *shape, +document_interface_merge_css (DocumentInterface *doc_interface, gchar *shape, gchar *stylestring, GError **error); gboolean -document_interface_set_color (DocumentInterface *object, gchar *shape, +document_interface_set_color (DocumentInterface *doc_interface, gchar *shape, int r, int g, int b, gboolean fill, GError **error); gboolean -document_interface_move_to_layer (DocumentInterface *object, gchar *shape, +document_interface_move_to_layer (DocumentInterface *doc_interface, gchar *shape, gchar *layerstr, GError **error); GArray * -document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape); +document_interface_get_node_coordinates (DocumentInterface *doc_interface, gchar *shape); /**************************************************************************** FILE I/O FUNCTIONS ****************************************************************************/ gboolean -document_interface_save (DocumentInterface *object, GError **error); +document_interface_save (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_load (DocumentInterface *object, +document_interface_load (DocumentInterface *doc_interface, gchar *filename, GError **error); gboolean -document_interface_save_as (DocumentInterface *object, +document_interface_save_as (DocumentInterface *doc_interface, const gchar *filename, GError **error); gboolean -document_interface_mark_as_unmodified (DocumentInterface *object, GError **error); +document_interface_mark_as_unmodified (DocumentInterface *doc_interface, GError **error); /* gboolean -document_interface_print_to_file (DocumentInterface *object, GError **error); +document_interface_print_to_file (DocumentInterface *doc_interface, GError **error); */ /**************************************************************************** @@ -255,120 +255,120 @@ document_interface_print_to_file (DocumentInterface *object, GError **error); ****************************************************************************/ gboolean -document_interface_close (DocumentInterface *object, GError **error); +document_interface_close (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_exit (DocumentInterface *object, GError **error); +document_interface_exit (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_undo (DocumentInterface *object, GError **error); +document_interface_undo (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_redo (DocumentInterface *object, GError **error); +document_interface_redo (DocumentInterface *doc_interface, GError **error); /**************************************************************************** UPDATE FUNCTIONS ****************************************************************************/ void -document_interface_pause_updates (DocumentInterface *object, GError **error); +document_interface_pause_updates (DocumentInterface *doc_interface, GError **error); void -document_interface_resume_updates (DocumentInterface *object, GError **error); +document_interface_resume_updates (DocumentInterface *doc_interface, GError **error); void -document_interface_update (DocumentInterface *object, GError **error); +document_interface_update (DocumentInterface *doc_interface, GError **error); /**************************************************************************** SELECTION FUNCTIONS ****************************************************************************/ gboolean -document_interface_selection_get (DocumentInterface *object, char ***out, GError **error); +document_interface_selection_get (DocumentInterface *doc_interface, char ***out, GError **error); gboolean -document_interface_selection_add (DocumentInterface *object, +document_interface_selection_add (DocumentInterface *doc_interface, char *name, GError **error); gboolean -document_interface_selection_add_list (DocumentInterface *object, +document_interface_selection_add_list (DocumentInterface *doc_interface, char **names, GError **error); gboolean -document_interface_selection_set (DocumentInterface *object, +document_interface_selection_set (DocumentInterface *doc_interface, char *name, GError **error); gboolean -document_interface_selection_set_list (DocumentInterface *object, +document_interface_selection_set_list (DocumentInterface *doc_interface, gchar **names, GError **error); gboolean -document_interface_selection_rotate (DocumentInterface *object, +document_interface_selection_rotate (DocumentInterface *doc_interface, int angle, GError **error); gboolean -document_interface_selection_delete(DocumentInterface *object, GError **error); +document_interface_selection_delete(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_clear(DocumentInterface *object, GError **error); +document_interface_selection_clear(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_select_all(DocumentInterface *object, GError **error); +document_interface_select_all(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_select_all_in_all_layers(DocumentInterface *object, +document_interface_select_all_in_all_layers(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_box (DocumentInterface *object, int x, int y, +document_interface_selection_box (DocumentInterface *doc_interface, int x, int y, int x2, int y2, gboolean replace, GError **error); gboolean -document_interface_selection_invert (DocumentInterface *object, GError **error); +document_interface_selection_invert (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_group(DocumentInterface *object, GError **error); +document_interface_selection_group(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_ungroup(DocumentInterface *object, GError **error); +document_interface_selection_ungroup(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_cut(DocumentInterface *object, GError **error); +document_interface_selection_cut(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_copy(DocumentInterface *object, GError **error); +document_interface_selection_copy(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_paste(DocumentInterface *object, GError **error); +document_interface_selection_paste(DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_scale (DocumentInterface *object, +document_interface_selection_scale (DocumentInterface *doc_interface, gdouble grow, GError **error); gboolean -document_interface_selection_move (DocumentInterface *object, gdouble x, +document_interface_selection_move (DocumentInterface *doc_interface, gdouble x, gdouble y, GError **error); gboolean -document_interface_selection_move_to (DocumentInterface *object, gdouble x, +document_interface_selection_move_to (DocumentInterface *doc_interface, gdouble x, gdouble y, GError **error); gboolean -document_interface_selection_move_to_layer (DocumentInterface *object, +document_interface_selection_move_to_layer (DocumentInterface *doc_interface, gchar *layerstr, GError **error); GArray * -document_interface_selection_get_center (DocumentInterface *object); +document_interface_selection_get_center (DocumentInterface *doc_interface); gboolean -document_interface_selection_to_path (DocumentInterface *object, GError **error); +document_interface_selection_to_path (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_selection_combine (DocumentInterface *object, gchar *cmd, char ***newpaths, +document_interface_selection_combine (DocumentInterface *doc_interface, gchar *cmd, char ***newpaths, GError **error); gboolean -document_interface_selection_change_level (DocumentInterface *object, gchar *cmd, +document_interface_selection_change_level (DocumentInterface *doc_interface, gchar *cmd, GError **error); /**************************************************************************** @@ -376,24 +376,24 @@ document_interface_selection_change_level (DocumentInterface *object, gchar *cmd ****************************************************************************/ gchar * -document_interface_layer_new (DocumentInterface *object, GError **error); +document_interface_layer_new (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_layer_set (DocumentInterface *object, +document_interface_layer_set (DocumentInterface *doc_interface, gchar *layerstr, GError **error); gchar ** -document_interface_layer_get_all (DocumentInterface *object); +document_interface_layer_get_all (DocumentInterface *doc_interface); gboolean -document_interface_layer_change_level (DocumentInterface *object, +document_interface_layer_change_level (DocumentInterface *doc_interface, gchar *cmd, GError **error); gboolean -document_interface_layer_next (DocumentInterface *object, GError **error); +document_interface_layer_next (DocumentInterface *doc_interface, GError **error); gboolean -document_interface_layer_previous (DocumentInterface *object, GError **error); +document_interface_layer_previous (DocumentInterface *doc_interface, GError **error); @@ -409,13 +409,13 @@ extern DocumentInterface *fugly; gboolean dbus_send_ping (SPDesktop* desk, SPItem *item); gboolean -document_interface_get_children (DocumentInterface *object, char *name, char ***out, GError **error); +document_interface_get_children (DocumentInterface *doc_interface, char *name, char ***out, GError **error); gchar* -document_interface_get_parent (DocumentInterface *object, char *name, GError **error); +document_interface_get_parent (DocumentInterface *doc_interface, char *name, GError **error); gchar* -document_interface_import (DocumentInterface *object, +document_interface_import (DocumentInterface *doc_interface, gchar *filename, GError **error); G_END_DECLS -- cgit v1.2.3 From bea3d29ac007d6c8faca786538fafb0d7d789ffc Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Wed, 10 Jul 2013 11:50:45 +0100 Subject: Added "dbus-name" command line option to allow a D-Bus bus name other than "org.inkscape" to be specified. This allows multiple Inkscape instances to be controlled over D-Bus in a single user session. (bzr r12402.1.1) --- src/extension/dbus/dbus-init.cpp | 29 ++++++++++++++++++++-- src/extension/dbus/dbus-init.h | 10 ++++++++ src/extension/dbus/document-interface.h | 3 --- src/extension/dbus/wrapper/inkscape-dbus-wrapper.h | 2 -- 4 files changed, 37 insertions(+), 7 deletions(-) (limited to 'src/extension') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index eb62f4b3a..19b48e10d 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -36,7 +36,14 @@ #include - +namespace +{ + // This stores the bus name to use for this app instance. By default, it + // will be set to org.inkscape. However, users may provide other names by + // setting command-line parameters when starting Inkscape, so that more + // than one instance of Inkscape may be used by external scripts. + gchar *instance_bus_name = NULL; +} namespace Inkscape { namespace Extension { @@ -120,6 +127,11 @@ dbus_register_document(Inkscape::ActionContext const & target) void init (void) { + if (instance_bus_name == NULL) { + // Set the bus name to the default + instance_bus_name = strdup("org.inkscape"); + } + guint result; GError *error = NULL; DBusGConnection *connection; @@ -127,7 +139,7 @@ init (void) connection = dbus_get_connection(); proxy = dbus_get_proxy(connection); org_freedesktop_DBus_request_name (proxy, - "org.inkscape", + instance_bus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); //create interface for application dbus_register_object (connection, @@ -198,6 +210,19 @@ init_desktop (void) { return strdup(name.c_str()); } +void +dbus_set_bus_name(gchar * bus_name) +{ + g_assert(bus_name != NULL); + g_assert(instance_bus_name == NULL); + instance_bus_name = strdup(bus_name); +} +gchar * +dbus_get_bus_name() +{ + g_assert(instance_bus_name != NULL); + return instance_bus_name; +} } } } /* namespace Inkscape::Extension::Dbus */ diff --git a/src/extension/dbus/dbus-init.h b/src/extension/dbus/dbus-init.h index 486e55b86..7862ad3c3 100644 --- a/src/extension/dbus/dbus-init.h +++ b/src/extension/dbus/dbus-init.h @@ -28,6 +28,16 @@ gchar * init_desktop (void); gchar * dbus_init_desktop_interface (SPDesktop * dt); +/** Set the bus name to use. Default is "org.inkscape". + This function should only be called once, before init(), if a non-default + bus name is required. */ +void dbus_set_bus_name(gchar * bus_name); + +/** Get the bus name for this instance. Default is "org.inkscape". + This function should only be called after init(). + The returned gchar * is owned by this module and should not be freed. */ +gchar * dbus_get_bus_name(); + } } } /* namespace Dbus, Extension, Inkscape */ #endif /* INKSCAPE_EXTENSION_DBUS_INIT_H__ */ diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 00d964f36..27460de52 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -34,9 +34,6 @@ class SPDesktop; class SPItem; - -// TODO: this define doesn't seem to be used... although the path itself is also hardcoded in dbus-init.cpp -#define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document" #define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ()) #define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface)) diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h index 79f8188d4..20830bd65 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h @@ -8,8 +8,6 @@ //#include //#include - -#define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document" #define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ()) #define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface)) -- cgit v1.2.3 From eb7b26af09df66f30ba50058e9e4a583028cd81a Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 23 Jul 2013 12:54:01 +0200 Subject: Remove the disabled script dialog and the nonfunctional Java binding (bzr r12428) --- src/extension/CMakeLists.txt | 4 - src/extension/script/InkscapeScript.cpp | 223 -------------------------------- src/extension/script/InkscapeScript.h | 102 --------------- src/extension/script/Makefile_insert | 6 - src/extension/script/makefile.in | 17 --- 5 files changed, 352 deletions(-) delete mode 100644 src/extension/script/InkscapeScript.cpp delete mode 100644 src/extension/script/InkscapeScript.h delete mode 100644 src/extension/script/Makefile_insert delete mode 100644 src/extension/script/makefile.in (limited to 'src/extension') diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index fa4fdd740..4507d9ce2 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -62,8 +62,6 @@ set(extension_SRC internal/pdfinput/pdf-parser.cpp internal/pdfinput/svg-builder.cpp - script/InkscapeScript.cpp - # ------ # Header db.h @@ -136,8 +134,6 @@ set(extension_SRC internal/svg.h internal/svgz.h internal/vsd-input.h - - script/InkscapeScript.h ) if(WIN32) diff --git a/src/extension/script/InkscapeScript.cpp b/src/extension/script/InkscapeScript.cpp deleted file mode 100644 index 02cd28fa5..000000000 --- a/src/extension/script/InkscapeScript.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * This is a simple mechanism to bind Inkscape to Java, and thence - * to all of the nice things that can be layered upon that. - * - * Authors: - * Bob Jamison - * - * Copyright (C) 2007-2008 Bob Jamison - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -#include "InkscapeScript.h" - - -#include - - -namespace Inkscape -{ -namespace Extension -{ -namespace Script -{ - - -typedef Inkscape::Bind::Value Value; - - -/** - * - */ -InkscapeScript::InkscapeScript() -{ -} - - - - -/** - * - */ -InkscapeScript::~InkscapeScript() -{ -} - - - - -/** - * Interprets the script in the 'script' buffer, - * storing the stdout output in 'output', and any - * error messages in 'error.' Language is one of the - * enumerated types in ScriptLanguage above. - */ -bool InkscapeScript::interpretScript(const Glib::ustring &script, - Glib::ustring & /*output*/, - Glib::ustring & /*error*/, - ScriptLanguage language) -{ - const char *langname=NULL; - //if() instead of switch() lets us scope vars - if (language == InkscapeScript::JAVASCRIPT) - { - langname="javascript"; - } - else if (language == InkscapeScript::PYTHON) - { - langname="python"; - } - else if (language == InkscapeScript::RUBY) - { - langname="ruby"; - } - else - { - g_warning("interpretScript: Unknown Script Language type: %d\n", - language); - return false; - } - - Inkscape::Bind::JavaBindery *binder = - Inkscape::Bind::JavaBindery::getInstance(); - if (!binder->loadJVM()) //idempotent - { - g_warning("interpretScript: unable to start JVM\n"); - return false; - } - std::vector parms; - Value retval; - Value parm; - parm.setString(langname); - parms.push_back(parm); - parm.setString(script); - parms.push_back(parm); - - //binder->stdOutClear(); - //binder->stdErrClear(); - bool ret = binder->callStatic(Value::BIND_BOOLEAN, - "org/inkscape/cmn/ScriptRunner", - "run", - "(Ljava/lang/String;Ljava/lang/String;)Z", - parms, - retval); - //output = binder->stdOutGet(); - //error = binder->stdErrGet(); - - if (!ret) - { - g_warning("interpretScript: failed\n"); - return false; - } - - return true; -} - - -/** - * Interprets the script in the named file, - * storing the stdout output in 'output', and any - * error messages in 'error.' Language is one of the - * enumerated types in ScriptLanguage above. - */ -bool InkscapeScript::interpretFile(const Glib::ustring &fname, - Glib::ustring & /*output*/, - Glib::ustring & /*error*/, - ScriptLanguage language) -{ - const char *langname=NULL; - //if() instead of switch() lets us scope vars - if (language == InkscapeScript::JAVASCRIPT) - { - langname="Javascript"; - } - else if (language == InkscapeScript::PYTHON) - { - langname="Python"; - } - else if (language == InkscapeScript::RUBY) - { - langname="Ruby"; - } - else - { - g_warning("interpretFile: Unknown Script Language type: %d\n", - language); - return false; - } - - Inkscape::Bind::JavaBindery *binder = - Inkscape::Bind::JavaBindery::getInstance(); - if (!binder->loadJVM()) //idempotent - { - g_warning("interpretFile: unable to start JVM\n"); - return false; - } - std::vector parms; - Value retval; - Value parm; - parm.setString(langname); - parms.push_back(parm); - parm.setString(fname); - parms.push_back(parm); - - //binder->stdOutClear(); - //binder->stdErrClear(); - bool ret = binder->callStatic(Value::BIND_BOOLEAN, - "org/inkscape/cmn/ScriptRunner", - "runFile", - "(Ljava/lang/String;Ljava/lang/String;)Z", - parms, - retval); - //output = binder->stdOutGet(); - //error = binder->stdErrGet(); - - if (!ret) - { - g_warning("interpretFile: failed\n"); - return false; - } - - return true; -} - - - - - - - - - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - -//######################################################################### -//# E N D O F F I L E -//######################################################################### - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/script/InkscapeScript.h b/src/extension/script/InkscapeScript.h deleted file mode 100644 index 8d6346582..000000000 --- a/src/extension/script/InkscapeScript.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef SEEN_INKSCAPE_SCRIPT_H -#define SEEN_INKSCAPE_SCRIPT_H - -/* - * Authors: - * Bob Jamison - * - * Copyright (C) 2004-2008 Bob Jamison - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "config.h" - -namespace Glib { -class ustring; -} - -namespace Inkscape -{ -namespace Extension -{ -namespace Script -{ - - - -/** - * Inkscape Scripting container. - * This class is used to run scripts, either from a file or buffer. - */ -class InkscapeScript -{ -public: - - /** - * Which type of language? - */ - typedef enum - { - JAVASCRIPT, - PYTHON, - RUBY - } ScriptLanguage; - - /** - * Creates a generic script interpreter. - */ - InkscapeScript(); - - /** - * Destructor - */ - virtual ~InkscapeScript(); - - /** - * Interprets the script in the 'script' buffer, - * storing the stdout output in 'output', and any - * error messages in 'error.' Language is one of the - * enumerated types in ScriptLanguage above. - */ - bool interpretScript(const Glib::ustring &script, - Glib::ustring &output, - Glib::ustring &error, - ScriptLanguage language); - - /** - * Interprets the script in the named file, - * storing the stdout output in 'output', and any - * error messages in 'error.' Language is one of the - * enumerated types in ScriptLanguage above. - */ - bool interpretFile(const Glib::ustring &fname, - Glib::ustring &output, - Glib::ustring &error, - ScriptLanguage language); - - - -}; //class InkscapeScript - - - - -} // namespace Script -} // namespace Extension -} // namespace Inkscape - - - -#endif /* __INKSCAPE_SCRIPT_H__ */ - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/extension/script/Makefile_insert b/src/extension/script/Makefile_insert deleted file mode 100644 index c0bd91e81..000000000 --- a/src/extension/script/Makefile_insert +++ /dev/null @@ -1,6 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -ink_common_sources += \ - extension/script/InkscapeScript.h \ - extension/script/InkscapeScript.cpp - diff --git a/src/extension/script/makefile.in b/src/extension/script/makefile.in deleted file mode 100644 index f4857a9e3..000000000 --- a/src/extension/script/makefile.in +++ /dev/null @@ -1,17 +0,0 @@ -# Convenience stub makefile to call the real Makefile. - -@SET_MAKE@ - -OBJEXT = @OBJEXT@ - -# Explicit so that it's the default rule. -all: - cd ../.. && $(MAKE) extension/script/all - -clean %.a %.$(OBJEXT): - cd ../.. && $(MAKE) extension/script/$@ - -.PHONY: all clean - -.SUFFIXES: -.SUFFIXES: .a .$(OBJEXT) -- cgit v1.2.3 From f1cdb3b3f47c7187d9325e8ddd8e630268dc8e8b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 31 Jul 2013 18:33:03 -0400 Subject: Eliminate "unit-constants.h". (bzr r12380.1.54) --- src/extension/internal/cairo-render-context.cpp | 5 ++--- src/extension/internal/cairo-renderer-pdf-out.cpp | 4 ++-- src/extension/internal/cairo-renderer.cpp | 18 +++++++++--------- src/extension/internal/emf-win32-inout.cpp | 1 - src/extension/internal/emf-win32-print.cpp | 2 -- src/extension/internal/gdkpixbuf-input.cpp | 4 ++-- src/extension/internal/latex-pstricks.cpp | 6 +++--- src/extension/internal/latex-text-renderer.cpp | 4 ++-- src/extension/internal/pdfinput/pdf-parser.cpp | 8 ++++---- src/extension/internal/pdfinput/svg-builder.cpp | 4 ++-- 10 files changed, 26 insertions(+), 30 deletions(-) (limited to 'src/extension') diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index d7a560f04..09b769229 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -44,12 +44,11 @@ #include "sp-pattern.h" #include "sp-mask.h" #include "sp-clippath.h" +#include "util/units.h" #ifdef WIN32 #include "libnrtype/FontFactory.h" // USE_PANGO_WIN32 #endif -#include - #include "cairo-render-context.h" #include "cairo-renderer.h" #include "extension/system.h" @@ -855,7 +854,7 @@ CairoRenderContext::_finishSurfaceSetup(cairo_surface_t *surface, cairo_matrix_t _surface = surface; if (_vector_based_target) { - cairo_scale(_cr, PT_PER_PX, PT_PER_PX); + cairo_scale(_cr, Inkscape::Util::Quantity::convert(1, "px", "pt"), Inkscape::Util::Quantity::convert(1, "px", "pt")); } else if (cairo_surface_get_content(_surface) != CAIRO_CONTENT_ALPHA) { // set background color on non-alpha surfaces // TODO: bgcolor should be derived from SPDocument diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index 6f641fd36..da4cf1bc1 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -39,7 +39,7 @@ #include <2geom/affine.h> #include "document.h" -#include "unit-constants.h" +#include "util/units.h" namespace Inkscape { namespace Extension { @@ -197,7 +197,7 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, float new_bleedmargin_px = 0.; try { - new_bleedmargin_px = mod->get_param_float("bleed") * PX_PER_MM; + new_bleedmargin_px = mod->get_param_float("bleed") * Inkscape::Util::Quantity::convert(1, "mm", "px"); } catch(...) { g_warning("Parameter might not exist"); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 0a3cff26a..f7ab63c98 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -55,7 +55,7 @@ #include "sp-mask.h" #include "sp-clippath.h" -#include +#include "util/units.h" #include "helper/png-write.h" #include "helper/pixbuf-ops.h" @@ -442,7 +442,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) */ res = ctx->getBitmapResolution(); if(res == 0) { - res = PX_PER_IN; + res = Inkscape::Util::Quantity::convert(1, "in", "px"); } TRACE(("sp_asbitmap_render: resolution: %f\n", res )); @@ -463,8 +463,8 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) } // The width and height of the bitmap in pixels - unsigned width = ceil(bbox->width() * (res / PX_PER_IN)); - unsigned height = ceil(bbox->height() * (res / PX_PER_IN)); + unsigned width = ceil(bbox->width() * (res / Inkscape::Util::Quantity::convert(1, "in", "px"))); + unsigned height = ceil(bbox->height() * (res / Inkscape::Util::Quantity::convert(1, "in", "px"))); if (width == 0 || height == 0) return; @@ -477,7 +477,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) double shift_y = bbox->max()[Geom::Y]; // For default 90 dpi, snap bitmap to pixel grid - if (res == PX_PER_IN) { + if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { shift_x = round (shift_x); shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion. // Remove the negations when the inversion is gone. @@ -629,7 +629,7 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page if (ctx->_vector_based_target) { // convert from px to pt - d *= Geom::Scale(PT_PER_PX); + d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "pt")); } ctx->_width = d.width(); @@ -647,11 +647,11 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page } else { double high = doc->getHeight(); if (ctx->_vector_based_target) - high *= PT_PER_PX; + high *= Inkscape::Util::Quantity::convert(1, "px", "pt"); // this transform translates the export drawing to a virtual page (0,0)-(width,height) - Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? PX_PER_PT : 1.0), - (d.bottom() - high) * (ctx->_vector_based_target ? PX_PER_PT : 1.0))); + Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0), + (d.bottom() - high) * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0))); ctx->transform(tp); } } diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index e9360a0ea..62cb53413 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -37,7 +37,6 @@ #include "extension/output.h" #include "display/drawing.h" #include "display/drawing-item.h" -#include "unit-constants.h" #include "clear-n_.h" #include "document.h" diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 2b79fd5a4..99f101bb8 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -43,8 +43,6 @@ #include "emf-win32-print.h" -#include "unit-constants.h" - #include "extension/system.h" #include "extension/print.h" #include "document.h" diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index abfad518f..994258ccc 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -12,7 +12,7 @@ #include "selection-chemistry.h" #include "sp-image.h" #include "document-undo.h" -#include "unit-constants.h" +#include "util/units.h" #include "image-resolution.h" #include @@ -79,7 +79,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) double width = gdk_pixbuf_get_width(pb); double height = gdk_pixbuf_get_height(pb); - double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", PX_PER_IN); + double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px")); bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); ImageResolution *ir = 0; double xscale = 1; diff --git a/src/extension/internal/latex-pstricks.cpp b/src/extension/internal/latex-pstricks.cpp index c1eddf539..2ece1ba87 100644 --- a/src/extension/internal/latex-pstricks.cpp +++ b/src/extension/internal/latex-pstricks.cpp @@ -21,7 +21,7 @@ #include <2geom/hvlinesegment.h> #include #include -#include +#include "util/units.h" #include "helper/geom-curves.h" #include "extension/print.h" @@ -117,8 +117,8 @@ unsigned int PrintLatex::begin (Inkscape::Extension::Print *mod, SPDocument *doc } // width and height in pt - _width = doc->getWidth() * PT_PER_PX; - _height = doc->getHeight() * PT_PER_PX; + _width = doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt"); + _height = doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt"); if (res >= 0) { diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index ecc201733..57a71b467 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -39,7 +39,7 @@ #include "sp-rect.h" #include "text-editing.h" -#include +#include "util/units.h" #include "extension/system.h" @@ -611,7 +611,7 @@ LaTeXTextRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, float bl // scaling of the image when including it in LaTeX os << " \\ifx\\svgwidth\\undefined%\n"; - os << " \\setlength{\\unitlength}{" << d.width() * PT_PER_PX << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 + os << " \\setlength{\\unitlength}{" << d.width() * Inkscape::Util::Quantity::convert(1, "px", "pt") << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 os << " \\ifx\\svgscale\\undefined%\n"; os << " \\relax%\n"; os << " \\else%\n"; diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 3be7af34f..3b63e9cbe 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -34,7 +34,7 @@ extern "C" { #include "svg-builder.h" #include "Gfx.h" #include "pdf-parser.h" -#include "unit-constants.h" +#include "util/units.h" #include "goo/gmem.h" #include "goo/GooTimer.h" @@ -279,14 +279,14 @@ PdfParser::PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *bui ignoreUndef = 0; operatorHistory = NULL; builder = builderA; - builder->setDocumentSize(state->getPageWidth()*PX_PER_PT, - state->getPageHeight()*PX_PER_PT); + builder->setDocumentSize(state->getPageWidth()*Inkscape::Util::Quantity::convert(1, "pt", "px"), + state->getPageHeight()*Inkscape::Util::Quantity::convert(1, "pt", "px")); double *ctm = state->getCTM(); double scaledCTM[6]; for (int i = 0; i < 6; ++i) { baseMatrix[i] = ctm[i]; - scaledCTM[i] = PX_PER_PT * ctm[i]; + scaledCTM[i] = Inkscape::Util::Quantity::convert(1, "pt", "px") * ctm[i]; } saveState(); builder->setTransform((double*)&scaledCTM); diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index 75849f6cc..6d9ac1b1a 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -33,7 +33,7 @@ #include "svg/css-ostringstream.h" #include "svg/svg-color.h" #include "color.h" -#include "unit-constants.h" +#include "util/units.h" #include "io/stringstream.h" #include "io/base64stream.h" #include "display/nr-filter-utils.h" @@ -777,7 +777,7 @@ gchar *SvgBuilder::_createGradient(GfxShading *shading, double *matrix, bool for Geom::Affine pat_matrix(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); if ( !for_shading && _is_top_level ) { - Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * PT_PER_PX); + Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * Inkscape::Util::Quantity::convert(1, "px", "pt")); pat_matrix *= flip; } gchar *transform_text = sp_svg_transform_write(pat_matrix); -- cgit v1.2.3 From aaa29715c3e2e854d6c25b6a3c3216f18824d669 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 1 Aug 2013 12:44:34 -0400 Subject: Fixed Windows compile bug. (bzr r12380.1.56) --- src/extension/internal/emf-win32-inout.cpp | 13 +++--- src/extension/internal/emf-win32-print.cpp | 70 +++++++++++++++--------------- 2 files changed, 42 insertions(+), 41 deletions(-) (limited to 'src/extension') diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index 62cb53413..627d78b16 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -39,6 +39,7 @@ #include "display/drawing-item.h" #include "clear-n_.h" #include "document.h" +#include "util/units.h" #define WIN32_LEAN_AND_MEAN #include @@ -59,7 +60,7 @@ namespace Inkscape { namespace Extension { namespace Internal { -static float device_scale = DEVICESCALE; +static float device_scale = Inkscape::Util::Quantity::convert(1, "px", "pt"); static float device_x; static float device_y; static RECTL rc_old; @@ -776,18 +777,18 @@ myEnhMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, ENHMETARECORD const * d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left; d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top; - device_x = pEmr->rclFrame.left/100.0*PX_PER_MM; - device_y = pEmr->rclFrame.top/100.0*PX_PER_MM; + device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); + device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); d->MMX = d->dc[d->level].PixelsInX / 100.0; d->MMY = d->dc[d->level].PixelsInY / 100.0; - d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM; - d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM; + d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::Convert(1, "mm", "px"); + d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::Convert(1, "mm", "px"); // calculate ratio of Inkscape dpi/device dpi if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx) - device_scale = PX_PER_MM*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; + device_scale = Inkscape::Util::Quantity::Convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; tmp_outdef << " width=\"" << d->MMX << "mm\"\n" << diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 99f101bb8..8784f4ace 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -127,7 +127,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * if (bbox) d = *bbox; } - d *= Geom::Scale(IN_PER_PX); + d *= Geom::Scale(Inkscape::Util::Quantity::Convert(1, "px", "in")); float dwInchesX = d.width(); float dwInchesY = d.height(); @@ -194,7 +194,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY); GdiComment(hdc, strlen(buff), (BYTE*) buff); - snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * MM_PER_IN, dwInchesY * MM_PER_IN); + snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * Inkscape::Util::Quantity::Convert(1, "in", "mm"), dwInchesY * Inkscape::Util::Quantity::Convert(1, "in", "mm")); GdiComment(hdc, strlen(buff), (BYTE*) buff); } @@ -303,7 +303,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2); - DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * IN_PER_PX * dwDPI) ); + DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI) ); if (style->stroke_linecap.computed == 0) { linecap = PS_ENDCAP_FLAT; @@ -340,7 +340,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo n_dash = style->stroke_dash.n_dash; dash = new DWORD[n_dash]; for (i = 0; i < style->stroke_dash.n_dash; i++) { - dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI); + dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); } } } @@ -543,8 +543,8 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -563,10 +563,10 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -585,14 +585,14 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - p2[X] = (p2[X] * IN_PER_PX * dwDPI); - p3[X] = (p3[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); - p2[Y] = (p2[Y] * IN_PER_PX * dwDPI); - p3[Y] = (p3[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -715,8 +715,8 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -733,10 +733,10 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -753,14 +753,14 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - p2[X] = (p2[X] * IN_PER_PX * dwDPI); - p3[X] = (p3[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); - p2[Y] = (p2[Y] * IN_PER_PX * dwDPI); - p3[Y] = (p3[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -828,7 +828,7 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW)); g_assert(lf != NULL); - lf->lfHeight = -style->font_size.computed * IN_PER_PX * dwDPI; + lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI; lf->lfWidth = 0; lf->lfEscapement = rot; lf->lfOrientation = rot; @@ -877,8 +877,8 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons SetBkMode(hdc, TRANSPARENT); Geom::Point p2 = p * tf; - p2[Geom::X] = (p2[Geom::X] * IN_PER_PX * dwDPI); - p2[Geom::Y] = (p2[Geom::Y] * IN_PER_PX * dwDPI); + p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); LONG const xpos = (LONG) round(p2[Geom::X]); LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]); -- cgit v1.2.3 From 5a15ea1a002fa4638198d50182e6fd5847ee9cf9 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 1 Aug 2013 16:28:56 -0400 Subject: Fixed Windows compile bug. (bzr r12380.1.58) --- src/extension/internal/emf-win32-inout.cpp | 10 ++--- src/extension/internal/emf-win32-print.cpp | 71 +++++++++++++++--------------- 2 files changed, 41 insertions(+), 40 deletions(-) (limited to 'src/extension') diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index 627d78b16..2530af0cc 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -777,18 +777,18 @@ myEnhMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, ENHMETARECORD const * d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left; d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top; - device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); - device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); + device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px"); + device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px"); d->MMX = d->dc[d->level].PixelsInX / 100.0; d->MMY = d->dc[d->level].PixelsInY / 100.0; - d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::Convert(1, "mm", "px"); - d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::Convert(1, "mm", "px"); + d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::convert(1, "mm", "px"); + d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::convert(1, "mm", "px"); // calculate ratio of Inkscape dpi/device dpi if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx) - device_scale = Inkscape::Util::Quantity::Convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; + device_scale = Inkscape::Util::Quantity::convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; tmp_outdef << " width=\"" << d->MMX << "mm\"\n" << diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 8784f4ace..dae97fecf 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -36,6 +36,7 @@ #include "helper/geom.h" #include "helper/geom-curves.h" #include "sp-item.h" +#include "util/units.h" #include "style.h" #include "inkscape-version.h" @@ -127,7 +128,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * if (bbox) d = *bbox; } - d *= Geom::Scale(Inkscape::Util::Quantity::Convert(1, "px", "in")); + d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "in")); float dwInchesX = d.width(); float dwInchesY = d.height(); @@ -194,7 +195,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY); GdiComment(hdc, strlen(buff), (BYTE*) buff); - snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * Inkscape::Util::Quantity::Convert(1, "in", "mm"), dwInchesY * Inkscape::Util::Quantity::Convert(1, "in", "mm")); + snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * Inkscape::Util::Quantity::convert(1, "in", "mm"), dwInchesY * Inkscape::Util::Quantity::convert(1, "in", "mm")); GdiComment(hdc, strlen(buff), (BYTE*) buff); } @@ -303,7 +304,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2); - DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI) ); + DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI) ); if (style->stroke_linecap.computed == 0) { linecap = PS_ENDCAP_FLAT; @@ -340,7 +341,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo n_dash = style->stroke_dash.n_dash; dash = new DWORD[n_dash]; for (i = 0; i < style->stroke_dash.n_dash; i++) { - dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); } } } @@ -543,8 +544,8 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -563,10 +564,10 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -585,14 +586,14 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -715,8 +716,8 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -733,10 +734,10 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -753,14 +754,14 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -828,7 +829,7 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW)); g_assert(lf != NULL); - lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI; + lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI; lf->lfWidth = 0; lf->lfEscapement = rot; lf->lfOrientation = rot; @@ -877,8 +878,8 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons SetBkMode(hdc, TRANSPARENT); Geom::Point p2 = p * tf; - p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); LONG const xpos = (LONG) round(p2[Geom::X]); LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]); -- cgit v1.2.3 From 1a96b84e5e99905288a9531914926d4318a198ca Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sat, 3 Aug 2013 15:24:06 -0400 Subject: pdf import. re-define tiling pattern scaling matrix (Bug 1168908) Fixed bugs: - https://launchpad.net/bugs/1168908 (bzr r12450) --- src/extension/internal/pdfinput/svg-builder.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/extension') diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index 75849f6cc..165dd38fe 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -676,7 +676,25 @@ gchar *SvgBuilder::_createTilingPattern(GfxTilingPattern *tiling_pattern, Inkscape::XML::Node *pattern_node = _xml_doc->createElement("svg:pattern"); // Set pattern transform matrix double *p2u = tiling_pattern->getMatrix(); - Geom::Affine pat_matrix(p2u[0], p2u[1], p2u[2], p2u[3], p2u[4], p2u[5]); + double m[6] = {1, 0, 0, 1, 0, 0}; + double det; + det = ttm[0] * ttm[3] - ttm[1] * ttm[2]; // see LP Bug 1168908 + if (det) { + double ittm[6]; // invert ttm + ittm[0] = ttm[3] / det; + ittm[1] = -ttm[1] / det; + ittm[2] = -ttm[2] / det; + ittm[3] = ttm[0] / det; + ittm[4] = (ttm[2] * ttm[5] - ttm[3] * ttm[4]) / det; + ittm[5] = (ttm[1] * ttm[4] - ttm[0] * ttm[5]) / det; + m[0] = p2u[0] * ittm[0] + p2u[1] * ittm[2]; + m[1] = p2u[0] * ittm[1] + p2u[1] * ittm[3]; + m[2] = p2u[2] * ittm[0] + p2u[3] * ittm[2]; + m[3] = p2u[2] * ittm[1] + p2u[3] * ittm[3]; + m[4] = p2u[4] * ittm[0] + p2u[5] * ittm[2] + ittm[4]; + m[5] = p2u[4] * ittm[1] + p2u[5] * ittm[3] + ittm[5]; + } + Geom::Affine pat_matrix(m[0], m[1], m[2], m[3], m[4], m[5]); gchar *transform_text = sp_svg_transform_write(pat_matrix); pattern_node->setAttribute("patternTransform", transform_text); g_free(transform_text); -- cgit v1.2.3 From c0f2f5606f0884e00f426653168b84b23d26ffb3 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 5 Aug 2013 23:07:35 +0200 Subject: code cleanup (cppcheck) (bzr r12469) --- src/extension/internal/cairo-ps-out.cpp | 12 ++++++------ src/extension/internal/cairo-render-context.cpp | 2 +- src/extension/internal/cairo-renderer-pdf-out.cpp | 6 +++--- src/extension/internal/emf-win32-inout.cpp | 4 ++++ src/extension/internal/emf-win32-print.cpp | 3 +-- src/extension/internal/filter/paint.h | 3 +-- src/extension/internal/pdfinput/pdf-parser.cpp | 11 +++++------ src/extension/internal/pdfinput/svg-builder.cpp | 8 +++----- 8 files changed, 24 insertions(+), 25 deletions(-) (limited to 'src/extension') diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp index 5ce9a21f3..bfbdd8149 100644 --- a/src/extension/internal/cairo-ps-out.cpp +++ b/src/extension/internal/cairo-ps-out.cpp @@ -136,12 +136,12 @@ CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar con if (ext == NULL) return; - const gchar *new_level = NULL; int level = CAIRO_PS_LEVEL_2; try { - new_level = mod->get_param_enum("PSlevel"); - if((new_level != NULL) && (g_ascii_strcasecmp("PS3", new_level) == 0)) + const gchar *new_level = mod->get_param_enum("PSlevel"); + if((new_level != NULL) && (g_ascii_strcasecmp("PS3", new_level) == 0)) { level = CAIRO_PS_LEVEL_3; + } } catch(...) {} bool new_textToPath = FALSE; @@ -225,12 +225,12 @@ CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar co if (ext == NULL) return; - const gchar *new_level = NULL; int level = CAIRO_PS_LEVEL_2; try { - new_level = mod->get_param_enum("PSlevel"); - if((new_level != NULL) && (g_ascii_strcasecmp("PS3", new_level) == 0)) + const gchar *new_level = mod->get_param_enum("PSlevel"); + if((new_level != NULL) && (g_ascii_strcasecmp("PS3", new_level) == 0)) { level = CAIRO_PS_LEVEL_3; + } } catch(...) {} bool new_textToPath = FALSE; diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index d7a560f04..f0461c609 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -1492,7 +1492,7 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, Geom::Affine const &font_ma std::vector const &glyphtext, SPStyle const *style) { // create a cairo_font_face from PangoFont - double size = style->font_size.computed; + double size = style->font_size.computed; /// \fixme why is this variable never used? gpointer fonthash = (gpointer)font; cairo_font_face_t *font_face = (cairo_font_face_t *)g_hash_table_lookup(font_table, fonthash); diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index 6f641fd36..8b2e8bf84 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -136,12 +136,12 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, if (ext == NULL) return; - const gchar *new_level = NULL; int level = 0; try { - new_level = mod->get_param_enum("PDFversion"); - if((new_level != NULL) && (g_ascii_strcasecmp("PDF-1.5", new_level) == 0)) + const gchar *new_level = mod->get_param_enum("PDFversion"); + if((new_level != NULL) && (g_ascii_strcasecmp("PDF-1.5", new_level) == 0)) { level = 1; + } } catch(...) { g_warning("Parameter might not exist"); diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index e9360a0ea..063b1ca88 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -120,6 +120,10 @@ emf_print_document_to_file(SPDocument *doc, gchar const *filename) } mod->base->invoke_print(&context); ret = mod->finish(); + if (ret) { + g_free(oldoutput); + throw Inkscape::Extension::Output::save_failed(); + } /* Release arena */ mod->base->invoke_hide(mod->dkey); mod->base = NULL; diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 2b79fd5a4..e30ab390d 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -242,13 +242,12 @@ unsigned int PrintEmfWin32::comment (Inkscape::Extension::Print * /*module*/, int PrintEmfWin32::create_brush(SPStyle const *style) { - float rgb[3]; - if (style) { float opacity = SP_SCALE24_TO_FLOAT(style->fill_opacity.value); if (opacity <= 0.0) return 1; + float rgb[3]; sp_color_get_rgb_floatv( &style->fill.value.color, rgb ); hbrush = CreateSolidBrush( RGB(255*rgb[0], 255*rgb[1], 255*rgb[2]) ); hbrushOld = (HBRUSH) SelectObject( hdc, hbrush ); diff --git a/src/extension/internal/filter/paint.h b/src/extension/internal/filter/paint.h index d99d1e0e2..941177f39 100644 --- a/src/extension/internal/filter/paint.h +++ b/src/extension/internal/filter/paint.h @@ -999,9 +999,8 @@ PosterizeBasic::get_filter_text (Inkscape::Extension::Extension * ext) transf << "0"; int levels = ext->get_param_int("levels") + 1; - float val = 0.0; for ( int step = 1 ; step <= levels ; step++ ) { - val = (float) step / levels; + const float val = (float) step / levels; transf << " " << val; } transf << " 1"; diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 3be7af34f..4e50f02f6 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -579,14 +579,13 @@ void PdfParser::execOp(Object *cmd, Object args[], int numArgs) { (this->*op->func)(argPtr, numArgs); } -PdfOperator *PdfParser::findOp(char *name) { - int a, b, m, cmp; - - a = -1; - b = numOps; +PdfOperator* PdfParser::findOp(char *name) { + int a = -1; + int b = numOps; + int cmp = -1; // invariant: opTab[a] < name < opTab[b] while (b - a > 1) { - m = (a + b) / 2; + const int m = (a + b) / 2; cmp = strcmp(opTab[m].name, name); if (cmp < 0) a = m; diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index 165dd38fe..dee7d8afb 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -266,14 +266,12 @@ static void svgSetTransform(Inkscape::XML::Node *node, double c0, double c1, * \brief Generates a SVG path string from poppler's data structure */ static gchar *svgInterpretPath(GfxPath *path) { - GfxSubpath *subpath; Inkscape::SVG::PathString pathString; - int i, j; - for ( i = 0 ; i < path->getNumSubpaths() ; ++i ) { - subpath = path->getSubpath(i); + for (int i = 0 ; i < path->getNumSubpaths() ; ++i ) { + GfxSubpath *subpath = path->getSubpath(i); if (subpath->getNumPoints() > 0) { pathString.moveTo(subpath->getX(0), subpath->getY(0)); - j = 1; + int j = 1; while (j < subpath->getNumPoints()) { if (subpath->getCurve(j)) { pathString.curveTo(subpath->getX(j), subpath->getY(j), -- cgit v1.2.3 From 05f008356889de30ff55df1f73030003ed7cc312 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Mon, 12 Aug 2013 16:39:48 +0100 Subject: Allow Object to Path verb from non-GUI (DBus) interface (bzr r12473.1.1) --- src/extension/internal/bluredge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/extension') diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index a3d2fd6e5..3ce537d9f 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -94,7 +94,7 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View new_group->appendChild(new_items[i]); selection->add(new_items[i]); - sp_selected_path_to_curves(static_cast(desktop)); + sp_selected_path_to_curves(selection, static_cast(desktop)); if (offset < 0.0) { /* Doing an inset here folks */ -- cgit v1.2.3 From 350476a133a3965b1d7047d2f0f05bf809b177ba Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 21 Aug 2013 13:01:40 +0200 Subject: better memory leak fix (fixes bug 986271: memory leaks associated with images) Patch by David Mathog, including revert of former fix in rev 11268 (bzr r12482) --- src/extension/internal/emf-win32-print.cpp | 12 ------------ src/extension/internal/emf-win32-print.h | 7 ------- 2 files changed, 19 deletions(-) (limited to 'src/extension') diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 621954f68..92f564078 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -910,18 +910,6 @@ void PrintEmfWin32::init (void) return; } -unsigned int PrintEmfWin32::image(Inkscape::Extension::Print * /* module */, /** not used */ - unsigned char *px, /** array of pixel values, Gdk::Pixbuf bitmap format */ - unsigned int /*w*/, /** width of bitmap */ - unsigned int /*h*/, /** height of bitmap */ - unsigned int /*rs*/, /** row stride (normally w*4) */ - Geom::Affine const & /*tf_ignore*/, /** WRONG affine transform, use the one from m_tr_stack */ - SPStyle const * /*style*/) /** provides indirect link to image object */ -{ - free(px); - return 0; -} - } /* namespace Internal */ } /* namespace Extension */ } /* namespace Inkscape */ diff --git a/src/extension/internal/emf-win32-print.h b/src/extension/internal/emf-win32-print.h index e7bd08477..bbeeeb051 100644 --- a/src/extension/internal/emf-win32-print.h +++ b/src/extension/internal/emf-win32-print.h @@ -50,13 +50,6 @@ class PrintEmfWin32 : public Inkscape::Extension::Implementation::Implementation unsigned int print_pathv (Geom::PathVector const &pathv, const Geom::Affine &transform); bool print_simple_shape (Geom::PathVector const &pathv, const Geom::Affine &transform); - unsigned int image(Inkscape::Extension::Print * /* module */, /** not used */ - unsigned char *px, /** array of pixel values, Gdk::Pixbuf bitmap format */ - unsigned int w, /** width of bitmap */ - unsigned int h, /** height of bitmap */ - unsigned int rs, /** row stride (normally w*4) */ - Geom::Affine const &tf_ignore, /** WRONG affine transform, use the one from m_tr_stack */ - SPStyle const *style); /** provides indirect link to image object */ public: PrintEmfWin32 (void); -- cgit v1.2.3