From f24f34bd713c7a26fbb6e13c2a44111223950738 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 16:02:09 +0000 Subject: Core Dbus files. Init creates interfaces on Inkscape startup. Application and document interface provide API functions over Dbus. service.in file makes sure Inkscape starts automatically when someone connects to it over Dbus. (bzr r8254.1.3) --- src/extension/dbus/document-interface.cpp | 936 ++++++++++++++++++++++++++++++ 1 file changed, 936 insertions(+) create mode 100644 src/extension/dbus/document-interface.cpp (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp new file mode 100644 index 000000000..94f442865 --- /dev/null +++ b/src/extension/dbus/document-interface.cpp @@ -0,0 +1,936 @@ +#include "document-interface.h" +#include + +#include "verbs.h" +#include "helper/action.h" //sp_action_perform + +#include "inkscape.h" //inkscape_find_desktop_by_dkey, activate desktops + +#include "desktop-handles.h" //sp_desktop_document() +#include "xml/repr.h" //sp_repr_document_new + +#include "sp-object.h" + +#include "document.h" // sp_document_repr_doc + +#include "desktop-style.h" //sp_desktop_get_style + +#include "selection.h" //selection struct +#include "selection-chemistry.h"// lots of selection functions + +#include "sp-ellipse.h" + +#include "layer-fns.h" //LPOS_BELOW + +#include "style.h" //style_write + +/**************************************************************************** + HELPER / SHORTCUT FUNCTIONS +****************************************************************************/ + +const gchar* intToCString(int i) +{ + std::stringstream ss; + ss << i; + return ss.str().c_str(); +} + +SPObject * +get_object_by_name (SPDesktop *desk, gchar *name) +{ + return sp_desktop_document(desk)->getObjectById(name); +} + +const gchar * +get_name_from_object (SPObject * obj) +{ + return obj->repr->attribute("id"); +} + +void +desktop_ensure_active (SPDesktop* desk) { + if (desk != SP_ACTIVE_DESKTOP) + inkscape_activate_desktop (desk); + return; +} + +Inkscape::XML::Node * +document_retrive_node (SPDocument *doc, gchar *name) { + return (doc->getObjectById(name))->repr; +} + +gdouble +selection_get_center_x (Inkscape::Selection *sel){ + NRRect *box = g_new(NRRect, 1);; + box = sel->boundsInDocument(box); + return box->x0 + ((box->x1 - box->x0)/2); +} + +gdouble +selection_get_center_y (Inkscape::Selection *sel){ + NRRect *box = g_new(NRRect, 1);; + box = sel->boundsInDocument(box); + return box->y0 + ((box->y1 - box->y0)/2); +} +//move_to etc +const GSList * +selection_swap(SPDesktop *desk, gchar *name) +{ + Inkscape::Selection *sel = sp_desktop_selection(desk); + const GSList *oldsel = g_slist_copy((GSList *)sel->list()); + + sel->set(get_object_by_name(desk, name)); + return oldsel; +} + +void +selection_restore(SPDesktop *desk, const GSList * oldsel) +{ + Inkscape::Selection *sel = sp_desktop_selection(desk); + sel->setList(oldsel); +} + +Inkscape::XML::Node * +dbus_create_node (SPDesktop *desk, gboolean isrect) +{ + SPDocument * doc = sp_desktop_document (desk); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + gchar *type; + if (isrect) + type = (gchar *)"svg:rect"; + else + type = (gchar *)"svg:path"; + return xml_doc->createElement(type); +} + +gchar * +finish_create_shape (DocumentInterface *object, GError **error, Inkscape::XML::Node *newNode, gchar *desc) +{ + + SPCSSAttr *style = sp_desktop_get_style(object->desk, TRUE); + + if (style) { + newNode->setAttribute("style", sp_repr_css_write_string(style), TRUE); + } + else { + 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(); + + if (object->updates) + sp_document_done(sp_desktop_document(object->desk), 0, (gchar *)desc); + else + document_interface_pause_updates(object, error); + + return strdup(newNode->attribute("id")); +} + +gboolean +dbus_call_verb (DocumentInterface *object, int verbid, GError **error) +{ + SPDesktop *desk2 = object->desk; + + if ( desk2 ) { + Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); + if ( verb ) { + SPAction *action = verb->get_action(desk2); + if ( action ) { + sp_action_perform( action, NULL ); + if (object->updates) { + sp_document_done(sp_desktop_document(desk2), verb->get_code(), g_strdup(verb->get_tip())); + } + return TRUE; + } + } + } + return FALSE; +} + +/**************************************************************************** + DOCUMENT INTERFACE CLASS STUFF +****************************************************************************/ + +G_DEFINE_TYPE(DocumentInterface, document_interface, G_TYPE_OBJECT) + +static void +document_interface_finalize (GObject *object) +{ + G_OBJECT_CLASS (document_interface_parent_class)->finalize (object); +} + + +static void +document_interface_class_init (DocumentInterfaceClass *klass) +{ + GObjectClass *object_class; + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = document_interface_finalize; +} + +static void +document_interface_init (DocumentInterface *object) +{ + object->desk = NULL; +} + + +DocumentInterface * +document_interface_new (void) +{ + return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL); +} + +/**************************************************************************** + MISC FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_delete_all (DocumentInterface *object, GError **error) +{ + sp_edit_clear_all (object->desk); + return TRUE; +} + +void +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(desk2); + if ( action ) { + sp_action_perform( action, NULL ); + if (object->updates) { + sp_document_done(sp_desktop_document(desk2), verb->get_code(), g_strdup(verb->get_tip())); + } + } + } + } +} + + +/**************************************************************************** + CREATION FUNCTIONS +****************************************************************************/ + +gchar* +document_interface_rectangle (DocumentInterface *object, int x, int y, + int width, int height, GError **error) +{ + + + Inkscape::XML::Node *newNode = dbus_create_node(object->desk, TRUE); + 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"); +} + +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, FALSE); + 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"); +} + +gchar* +document_interface_polygon (DocumentInterface *object, 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->desk, FALSE); + newNode->setAttribute("inkscape:flatsided", "true"); + newNode->setAttribute("sodipodi:type", "star"); + sp_repr_set_int(newNode, "sodipodi:cx", cx); + sp_repr_set_int(newNode, "sodipodi:cy", cy); + sp_repr_set_int(newNode, "sodipodi:r1", radius); + sp_repr_set_int(newNode, "sodipodi:r2", radius); + sp_repr_set_int(newNode, "sodipodi:sides", sides); + sp_repr_set_int(newNode, "inkscape:randomized", 0); + sp_repr_set_svg_double(newNode, "sodipodi:arg1", rot); + 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"); +} + +gchar* +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, FALSE); + newNode->setAttribute("inkscape:flatsided", "false"); + newNode->setAttribute("sodipodi:type", "star"); + sp_repr_set_int(newNode, "sodipodi:cx", cx); + sp_repr_set_int(newNode, "sodipodi:cy", cy); + sp_repr_set_int(newNode, "sodipodi:r1", r1); + sp_repr_set_int(newNode, "sodipodi:r2", r2); + sp_repr_set_int(newNode, "sodipodi:sides", sides); + sp_repr_set_int(newNode, "inkscape:randomized", 0); + sp_repr_set_svg_double(newNode, "sodipodi:arg1", arg1); + 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"); +} + +gchar* +document_interface_ellipse (DocumentInterface *object, 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); +} + +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, FALSE); + std::stringstream out; + printf("X2: %d\nY2 %d\n", x2, y2); + out << "m " << x << "," << y << " " << x2 << "," << y2; + printf ("PATH: %s\n", out.str().c_str()); + newNode->setAttribute("d", out.str().c_str()); + return finish_create_shape (object, error, newNode, (gchar *)"create line"); +} + +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, FALSE); + newNode->setAttribute("sodipodi:type", "spiral"); + sp_repr_set_int(newNode, "sodipodi:cx", cx); + sp_repr_set_int(newNode, "sodipodi:cy", cy); + sp_repr_set_int(newNode, "sodipodi:radius", r); + sp_repr_set_int(newNode, "sodipodi:revolution", revolutions); + 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"); + newNode->setAttribute("style", "fill:none"); + return retval; +} + +gchar* +document_interface_text (DocumentInterface *object, gchar *text, GError **error) +{ + return NULL; +} + +gchar* +document_interface_node (DocumentInterface *object, gchar *type, GError **error) +{ + return NULL; +} + +/**************************************************************************** + ENVIORNMENT FUNCTIONS +****************************************************************************/ +gdouble +document_interface_document_get_width (DocumentInterface *object) +{ + return sp_document_width(sp_desktop_document(object->desk)); +} + +gdouble +document_interface_document_get_height (DocumentInterface *object) +{ + return sp_document_height(sp_desktop_document(object->desk)); +} + +gchar * +document_interface_document_get_css (DocumentInterface *object, GError **error) +{ + SPCSSAttr *current = (object->desk)->current; + return sp_repr_css_write_string(current); +} + +gboolean +document_interface_document_merge_css (DocumentInterface *object, + gchar *stylestring, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_document_set_css (DocumentInterface *object, + gchar *stylestring, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_document_resize_to_fit_selection (DocumentInterface *object, + GError **error) +{ + return FALSE; +} + +/**************************************************************************** + OBJECT FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_set_attribute (DocumentInterface *object, char *shape, + char *attribute, char *newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; + + /* ALTERNATIVE + Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + */ + if (newNode) + { + newNode->setAttribute(attribute, newval, TRUE); + return TRUE; + } + return FALSE; +} + +void +document_interface_set_int_attribute (DocumentInterface *object, + char *shape, char *attribute, + int newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; + if (newNode) + sp_repr_set_int (newNode, attribute, newval); +} + + +void +document_interface_set_double_attribute (DocumentInterface *object, + char *shape, char *attribute, + double newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; + if (newNode) + sp_repr_set_svg_double (newNode, attribute, newval); +} + +gchar * +document_interface_get_attribute (DocumentInterface *object, char *shape, + char *attribute, GError **error) +{ + SPDesktop *desk2 = object->desk; + SPDocument * doc = sp_desktop_document (desk2); + + // FIXME: Not sure if this is the most efficient way. + Inkscape::XML::Node *newNode = doc->getObjectById(shape)->repr; + + /* WORKS + Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + */ + if (newNode) + return g_strdup(newNode->attribute(attribute)); + return FALSE; +} + +gboolean +document_interface_move (DocumentInterface *object, gchar *name, gdouble x, + gdouble y, GError **error) +{ + const GSList *oldsel = selection_swap(object->desk, name); + sp_selection_move (object->desk, x, 0 - y); + selection_restore(object->desk, oldsel); + return TRUE; +} + +gboolean +document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, + gdouble y, GError **error) +{ + const GSList *oldsel = selection_swap(object->desk, name); + Inkscape::Selection * sel = sp_desktop_selection(object->desk); + sp_selection_move (object->desk, x - selection_get_center_x(sel), + 0 - (y - selection_get_center_y(sel))); + selection_restore(object->desk, oldsel); + return TRUE; +} + +void +document_interface_object_to_path (DocumentInterface *object, + char *shape, GError **error) +{ + const GSList *oldsel = selection_swap(object->desk, shape); + dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); + selection_restore(object->desk, oldsel); +} + +gboolean +document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) +{ + Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); + if (node == NULL || node->attribute("d") == NULL) { + g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); + return FALSE; + } + gchar *pathstr = strdup(node->attribute("d")); + printf("PATH: %s\n", pathstr); + //gfree (pathstr); + std::istringstream iss(pathstr); + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::ostream_iterator(std::cout, "\n")); + + return TRUE; +} + +gboolean +document_interface_transform (DocumentInterface *object, gchar *shape, + gchar *transformstr, GError **error) +{ + //FIXME: This should merge transformations. + gchar trans[] = "transform"; + document_interface_set_attribute (object, shape, trans, transformstr, error); + return TRUE; +} + +gchar * +document_interface_get_css (DocumentInterface *object, gchar *shape, + GError **error) +{ +return NULL; +} + +gboolean +document_interface_modify_css (DocumentInterface *object, gchar *shape, + gchar *cssattrb, gchar *newval, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_merge_css (DocumentInterface *object, gchar *shape, + gchar *stylestring, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_move_to_layer (DocumentInterface *object, gchar *shape, + gchar *layerstr, GError **error) +{ + return FALSE; +} + +DBUSPoint ** +document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) +{ + return NULL; +} + + +/**************************************************************************** + FILE I/O FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_save (DocumentInterface *object, GError **error){ + return FALSE; +} + +gboolean +document_interface_load (DocumentInterface *object, + gchar *filename, GError **error){ + return FALSE; +} + +gboolean +document_interface_save_as (DocumentInterface *object, + gchar *filename, GError **error){ + return FALSE; +} + +gboolean +document_interface_print (DocumentInterface *object, GError **error){ + return FALSE; +} + +/**************************************************************************** + PROGRAM CONTROL FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_close (DocumentInterface *object, GError **error){ + return dbus_call_verb (object, SP_VERB_FILE_CLOSE_VIEW, error); +} + +gboolean +document_interface_exit (DocumentInterface *object, GError **error){ + return dbus_call_verb (object, SP_VERB_FILE_QUIT, error); +} + +gboolean +document_interface_undo (DocumentInterface *object, GError **error){ + return dbus_call_verb (object, SP_VERB_EDIT_UNDO, error); +} + +gboolean +document_interface_redo (DocumentInterface *object, GError **error){ + return dbus_call_verb (object, SP_VERB_EDIT_REDO, error); +} + + + +/**************************************************************************** + UPDATE FUNCTIONS +****************************************************************************/ + +void +document_interface_pause_updates (DocumentInterface *object, GError **error) +{ + object->updates = FALSE; + sp_desktop_document(object->desk)->root->uflags = FALSE; + sp_desktop_document(object->desk)->root->mflags = FALSE; +} + +void +document_interface_resume_updates (DocumentInterface *object, GError **error) +{ + object->updates = TRUE; + sp_desktop_document(object->desk)->root->uflags = TRUE; + sp_desktop_document(object->desk)->root->mflags = TRUE; + //sp_desktop_document(object->desk)->_updateDocument(); + sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); +} + +void +document_interface_update (DocumentInterface *object, GError **error) +{ + sp_desktop_document(object->desk)->root->uflags = TRUE; + sp_desktop_document(object->desk)->root->mflags = TRUE; + sp_desktop_document(object->desk)->_updateDocument(); + sp_desktop_document(object->desk)->root->uflags = FALSE; + sp_desktop_document(object->desk)->root->mflags = FALSE; + //sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); +} + +/**************************************************************************** + SELECTION FUNCTIONS FIXME: use call_verb where appropriate. +****************************************************************************/ + +gchar ** +document_interface_selection_get (DocumentInterface *object) +{ + Inkscape::Selection * sel = sp_desktop_selection(object->desk); + GSList const *oldsel = sel->list(); + + int size = g_slist_length((GSList *) oldsel); + int i; + printf("premalloc\n"); + gchar **list = (gchar **)malloc(size); + printf("postmalloc\n"); + for(i = 0; i < size; i++) + list[i] = (gchar *)malloc(sizeof(gchar) * 10); + printf("postmalloc2\n"); + i=0; + printf("prealloc\n"); + for (GSList const *iter = oldsel; iter != NULL; iter = iter->next) { + strcpy (list[i], SP_OBJECT(iter->data)->repr->attribute("id")); + i++; + } + printf("postalloc\n"); + for (i=0; idesk); + Inkscape::Selection *selection = sp_desktop_selection(object->desk); + /* WORKS + Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + selection->add(repr2, TRUE); + */ + selection->add(doc->getObjectById(name)); + return TRUE; +} + +gboolean +document_interface_selection_add_list (DocumentInterface *object, + char **names, GError **error) +{ + return FALSE; +} + +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); + selection->set(doc->getObjectById(name)); + return TRUE; +} + +gboolean +document_interface_selection_set_list (DocumentInterface *object, + gchar **names, GError **error) +{ + sp_desktop_selection(object->desk)->clear(); + int i; + for (i=0;((i<30000) && (names[i] != NULL));i++) { + printf("NAME: %s\n", names[i]); + document_interface_selection_add(object, names[i], error); + } + return TRUE; +} + +gboolean +document_interface_selection_rotate (DocumentInterface *object, int angle, GError **error) +{ + Inkscape::Selection *selection = sp_desktop_selection(object->desk); + sp_selection_rotate(selection, angle); + return TRUE; +} + +gboolean +document_interface_selection_delete (DocumentInterface *object, GError **error) +{ + sp_selection_delete (object->desk); + return TRUE; +} + +gboolean +document_interface_selection_clear (DocumentInterface *object, GError **error) +{ + sp_desktop_selection(object->desk)->clear(); + return TRUE; +} + +gboolean +document_interface_select_all (DocumentInterface *object, GError **error) +{ + sp_edit_select_all (object->desk); + return TRUE; +} + +gboolean +document_interface_select_all_in_all_layers(DocumentInterface *object, + GError **error) +{ + sp_edit_select_all_in_all_layers (object->desk); +} + +gboolean +document_interface_selection_box (DocumentInterface *object, int x, int y, + int x2, int y2, gboolean replace, + GError **error) +{ + return FALSE; +} + +gboolean +document_interface_selection_invert (DocumentInterface *object, GError **error) +{ + sp_edit_invert (object->desk); + return TRUE; +} + +gboolean +document_interface_selection_group (DocumentInterface *object, GError **error) +{ + sp_selection_group (object->desk); + return TRUE; +} +gboolean +document_interface_selection_ungroup (DocumentInterface *object, GError **error) +{ + sp_selection_ungroup (object->desk); + return TRUE; +} + +gboolean +document_interface_selection_cut (DocumentInterface *object, GError **error) +{ + sp_selection_cut (object->desk); + return TRUE; +} +gboolean +document_interface_selection_copy (DocumentInterface *object, GError **error) +{ + desktop_ensure_active (object->desk); + sp_selection_copy (); + return TRUE; +} +gboolean +document_interface_selection_paste (DocumentInterface *object, GError **error) +{ + desktop_ensure_active (object->desk); + sp_selection_paste (object->desk, TRUE); + return TRUE; +} + +gboolean +document_interface_selection_scale (DocumentInterface *object, gdouble grow, GError **error) +{ + Inkscape::Selection *selection = sp_desktop_selection(object->desk); + sp_selection_scale (selection, grow); + return TRUE; +} + +gboolean +document_interface_selection_move (DocumentInterface *object, gdouble x, gdouble y, GError **error) +{ + sp_selection_move (object->desk, 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); + + Geom::OptRect sel_bbox = sel->bounds(); + if (sel_bbox) { + //Geom::Point m( (object->desk)->point() - sel_bbox->midpoint() ); + Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) ); + sp_selection_move_relative(sel, m, true); + + } + + //FIXME: dosn't work with transformations + //sp_selection_move (object->desk, x - selection_get_center_x(sel), + // 0 - (y - selection_get_center_y(sel))); + return TRUE; +} + +gboolean +document_interface_selection_move_to_layer (DocumentInterface *object, + gchar *layerstr, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_selection_get_center (DocumentInterface *object) +{ + return FALSE; +} + +gboolean +document_interface_selection_to_path (DocumentInterface *object, GError **error) +{ + return dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); +} + + +gchar * +document_interface_selection_combine (DocumentInterface *object, gchar *cmd, + GError **error) +{ + + if (strcmp(cmd, "union") == 0) + dbus_call_verb (object, SP_VERB_SELECTION_UNION, error); + else if (strcmp(cmd, "intersection") == 0) + dbus_call_verb (object, SP_VERB_SELECTION_INTERSECT, error); + else if (strcmp(cmd, "difference") == 0) + 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 if (strcmp(cmd, "division") == 0) + dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + else + return NULL; + + //FIXME: this WILL cause problems with division + return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); +} + +gboolean +document_interface_selection_change_level (DocumentInterface *object, gchar *cmd, + GError **error) +{ + if (strcmp(cmd, "raise") == 0) + return dbus_call_verb (object, SP_VERB_SELECTION_RAISE, error); + if (strcmp(cmd, "lower") == 0) + return dbus_call_verb (object, 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); + if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0)) + return dbus_call_verb (object, SP_VERB_SELECTION_TO_BACK, error); + return TRUE; +} + +/**************************************************************************** + LAYER FUNCTIONS +****************************************************************************/ + +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); + return g_strdup(get_name_from_object (new_layer)); +} + +gboolean +document_interface_layer_set (DocumentInterface *object, + gchar *layerstr, GError **error) +{ + object->desk->setCurrentLayer (get_object_by_name (object->desk, layerstr)); + return TRUE; +} + +gchar ** +document_interface_layer_get_all (DocumentInterface *object) +{ + return NULL; +} + +gboolean +document_interface_layer_change_level (DocumentInterface *object, + gchar *cmd, GError **error) +{ + if (strcmp(cmd, "raise") == 0) + return dbus_call_verb (object, SP_VERB_LAYER_RAISE, error); + if (strcmp(cmd, "lower") == 0) + return dbus_call_verb (object, 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); + if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0)) + return dbus_call_verb (object, SP_VERB_LAYER_TO_BOTTOM, error); + return TRUE; +} + +gboolean +document_interface_layer_next (DocumentInterface *object, GError **error) +{ + return dbus_call_verb (object, SP_VERB_LAYER_NEXT, error); +} + +gboolean +document_interface_layer_previous (DocumentInterface *object, GError **error) +{ + return dbus_call_verb (object, SP_VERB_LAYER_PREV, error); +} + + + + + + -- cgit v1.2.3 From fc46b3cb436a03d787778e0e462f89e45038b716 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 13 Jul 2009 22:42:41 +0000 Subject: Implemented all the CSS style functions. Worked on some layer functions. (bzr r8254.1.11) --- src/extension/dbus/document-interface.cpp | 62 +++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 8 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 94f442865..f73d319f5 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -365,21 +365,30 @@ gboolean document_interface_document_merge_css (DocumentInterface *object, gchar *stylestring, GError **error) { - 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); + return TRUE; } +//FIXME this actually merges gboolean document_interface_document_set_css (DocumentInterface *object, gchar *stylestring, GError **error) { - 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); + return TRUE; } gboolean document_interface_document_resize_to_fit_selection (DocumentInterface *object, GError **error) { - return FALSE; + dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); + //verb_fit_canvas_to_selection(object->desk); + return TRUE; } /**************************************************************************** @@ -506,28 +515,46 @@ gchar * document_interface_get_css (DocumentInterface *object, gchar *shape, GError **error) { -return NULL; + gchar style[] = "style"; + return document_interface_get_attribute (object, shape, style, error); } gboolean document_interface_modify_css (DocumentInterface *object, gchar *shape, gchar *cssattrb, gchar *newval, GError **error) { - return FALSE; + gchar style[] = "style"; + Inkscape::XML::Node *node = get_object_by_name(object->desk, shape)->repr; + SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); + sp_repr_css_set_property(oldstyle, cssattrb, newval); + node->setAttribute (style, sp_repr_css_write_string (oldstyle), TRUE); + return TRUE; } gboolean document_interface_merge_css (DocumentInterface *object, gchar *shape, gchar *stylestring, GError **error) { - return FALSE; + SPCSSAttr * newstyle = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string (newstyle, stylestring); + + gchar style[] = "style"; + Inkscape::XML::Node *node = get_object_by_name(object->desk, shape)->repr; + SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); + + sp_repr_css_merge(oldstyle, newstyle); + node->setAttribute (style, sp_repr_css_write_string (oldstyle), TRUE); + return TRUE; } gboolean document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) { - return FALSE; + const GSList *oldsel = selection_swap(object->desk, shape); + document_interface_selection_move_to_layer(object, layerstr, error); + selection_restore(object->desk, oldsel); + return TRUE; } DBUSPoint ** @@ -818,11 +845,30 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou return TRUE; } +//FIXME: does not paste in new layer. gboolean document_interface_selection_move_to_layer (DocumentInterface *object, gchar *layerstr, GError **error) { - return FALSE; + SPDesktop * dt = object->desk; + + Inkscape::Selection *selection = sp_desktop_selection(dt); + + // check if something is selected + if (selection->isEmpty()) + return FALSE; + + SPObject *next = get_object_by_name(object->desk, layerstr); + + if (next && (strcmp("layer", (next->repr)->attribute("inkscape:groupmode")) == 0)) { + + sp_selection_cut(dt); + + dt->setCurrentLayer(next); + + sp_selection_paste(dt, TRUE); + } + return TRUE; } gboolean -- cgit v1.2.3 From 103aff597d89ef273a5d9cd12a0148c57f6a6435 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Wed, 15 Jul 2009 17:06:03 +0000 Subject: implemented a number of functions, including save/load functions. Removed the print function because I can see no way of doing it without bringing up a dialog. (bzr r8254.1.12) --- src/extension/dbus/document-interface.cpp | 107 +++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 24 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index f73d319f5..1cdff0133 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -24,6 +24,14 @@ #include "style.h" //style_write +#include "file.h" //IO + +#include "extension/system.h" //IO + +#include "extension/output.h" //IO + +#include "print.h" //IO + /**************************************************************************** HELPER / SHORTCUT FUNCTIONS ****************************************************************************/ @@ -330,13 +338,27 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, gchar* document_interface_text (DocumentInterface *object, gchar *text, GError **error) { + //FIXME: implement. return NULL; } gchar* document_interface_node (DocumentInterface *object, gchar *type, GError **error) { - return NULL; + SPDocument * doc = sp_desktop_document (object->desk); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + + Inkscape::XML::Node *newNode = xml_doc->createElement(type); + + object->desk->currentLayer()->appendChildRepr(newNode); + object->desk->currentLayer()->updateRepr(); + + if (object->updates) + sp_document_done(sp_desktop_document(object->desk), 0, (gchar *)"created empty node"); + else + document_interface_pause_updates(object, error); + + return strdup(newNode->attribute("id")); } /**************************************************************************** @@ -371,14 +393,14 @@ document_interface_document_merge_css (DocumentInterface *object, return TRUE; } -//FIXME this actually merges gboolean document_interface_document_set_css (DocumentInterface *object, gchar *stylestring, GError **error) { SPCSSAttr * style = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string (style, stylestring); - sp_desktop_set_style (object->desk, style); + //Memory leak? + object->desk->current = style; return TRUE; } @@ -387,7 +409,6 @@ document_interface_document_resize_to_fit_selection (DocumentInterface *object, GError **error) { dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); - //verb_fit_canvas_to_selection(object->desk); return TRUE; } @@ -440,7 +461,6 @@ document_interface_get_attribute (DocumentInterface *object, char *shape, SPDesktop *desk2 = object->desk; SPDocument * doc = sp_desktop_document (desk2); - // FIXME: Not sure if this is the most efficient way. Inkscape::XML::Node *newNode = doc->getObjectById(shape)->repr; /* WORKS @@ -560,6 +580,7 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, DBUSPoint ** document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { + //FIXME: implement. return NULL; } @@ -569,48 +590,86 @@ document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape ****************************************************************************/ gboolean -document_interface_save (DocumentInterface *object, GError **error){ +document_interface_save (DocumentInterface *object, GError **error) +{ + SPDocument * doc = sp_desktop_document(object->desk); + printf("1: %s\n2: %s\n3: %s\n", doc->uri, doc->base, doc->name); + if (doc->uri) + return document_interface_save_as (object, doc->uri, error); return FALSE; } gboolean document_interface_load (DocumentInterface *object, - gchar *filename, GError **error){ - return FALSE; + gchar *filename, GError **error) +{ + desktop_ensure_active (object->desk); + const Glib::ustring file(filename); + sp_file_open(file, NULL, TRUE, TRUE); + if (object->updates) + sp_document_done(sp_desktop_document(object->desk), SP_VERB_FILE_OPEN, "Opened File"); + return TRUE; } gboolean document_interface_save_as (DocumentInterface *object, - gchar *filename, GError **error){ - return FALSE; -} + gchar *filename, GError **error) +{ + SPDocument * doc = sp_desktop_document(object->desk); + #ifdef WITH_GNOME_VFS + const Glib::ustring file(filename); + return file_save_remote(doc, file, NULL, TRUE, TRUE); + #endif + if (!doc || strlen(filename)<1) //Safety check + return false; + + try { + Inkscape::Extension::save(NULL, doc, filename, + false, false, true); + } catch (...) { + //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); + return false; + } + //SP_ACTIVE_DESKTOP->event_log->rememberFileSave(); + //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, "Document saved."); + return true; +} +/* gboolean -document_interface_print (DocumentInterface *object, GError **error){ - return FALSE; +document_interface_print_to_file (DocumentInterface *object, GError **error) +{ + SPDocument * doc = sp_desktop_document(object->desk); + sp_print_document_to_file (doc, g_strdup("/home/soren/test.pdf")); + + return TRUE; } - +*/ /**************************************************************************** PROGRAM CONTROL FUNCTIONS ****************************************************************************/ gboolean -document_interface_close (DocumentInterface *object, GError **error){ +document_interface_close (DocumentInterface *object, GError **error) +{ return dbus_call_verb (object, SP_VERB_FILE_CLOSE_VIEW, error); } gboolean -document_interface_exit (DocumentInterface *object, GError **error){ +document_interface_exit (DocumentInterface *object, GError **error) +{ return dbus_call_verb (object, SP_VERB_FILE_QUIT, error); } gboolean -document_interface_undo (DocumentInterface *object, GError **error){ +document_interface_undo (DocumentInterface *object, GError **error) +{ return dbus_call_verb (object, SP_VERB_EDIT_UNDO, error); } gboolean -document_interface_redo (DocumentInterface *object, GError **error){ +document_interface_redo (DocumentInterface *object, GError **error) +{ return dbus_call_verb (object, SP_VERB_EDIT_REDO, error); } @@ -686,7 +745,6 @@ document_interface_selection_add (DocumentInterface *object, char *name, GError { if (name == NULL) return FALSE; - //FIXME: This gets called a lot. Efficient? SPDocument * doc = sp_desktop_document (object->desk); Inkscape::Selection *selection = sp_desktop_selection(object->desk); /* WORKS @@ -701,6 +759,7 @@ gboolean document_interface_selection_add_list (DocumentInterface *object, char **names, GError **error) { + //FIXME: implement. return FALSE; } @@ -717,6 +776,7 @@ gboolean document_interface_selection_set_list (DocumentInterface *object, gchar **names, GError **error) { + //FIXME: broken array passing. sp_desktop_selection(object->desk)->clear(); int i; for (i=0;((i<30000) && (names[i] != NULL));i++) { @@ -760,6 +820,7 @@ document_interface_select_all_in_all_layers(DocumentInterface *object, GError **error) { sp_edit_select_all_in_all_layers (object->desk); + return TRUE; } gboolean @@ -767,6 +828,7 @@ document_interface_selection_box (DocumentInterface *object, int x, int y, int x2, int y2, gboolean replace, GError **error) { + //FIXME: implement. return FALSE; } @@ -836,12 +898,7 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou //Geom::Point m( (object->desk)->point() - sel_bbox->midpoint() ); Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) ); sp_selection_move_relative(sel, m, true); - } - - //FIXME: dosn't work with transformations - //sp_selection_move (object->desk, x - selection_get_center_x(sel), - // 0 - (y - selection_get_center_y(sel))); return TRUE; } @@ -874,6 +931,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, gboolean document_interface_selection_get_center (DocumentInterface *object) { + //FIXME: implement: pass struct. return FALSE; } @@ -945,6 +1003,7 @@ document_interface_layer_set (DocumentInterface *object, gchar ** document_interface_layer_get_all (DocumentInterface *object) { + //FIXME: implement. return NULL; } -- cgit v1.2.3 From c819feae71738f973920724e60029397dd1c92a1 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 16 Jul 2009 16:01:55 +0000 Subject: Added missing (and very important) file. Added get_path method. Added documentation on paths. (bzr r8254.1.13) --- src/extension/dbus/document-interface.cpp | 43 ++++++++++++++----------------- 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 1cdff0133..e3573989a 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -422,8 +422,8 @@ document_interface_set_attribute (DocumentInterface *object, char *shape, { Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; - /* ALTERNATIVE - Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + /* ALTERNATIVE (is this faster?) + Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); */ if (newNode) { @@ -458,14 +458,8 @@ gchar * document_interface_get_attribute (DocumentInterface *object, char *shape, char *attribute, GError **error) { - SPDesktop *desk2 = object->desk; - SPDocument * doc = sp_desktop_document (desk2); - - Inkscape::XML::Node *newNode = doc->getObjectById(shape)->repr; + Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; - /* WORKS - Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); - */ if (newNode) return g_strdup(newNode->attribute(attribute)); return FALSE; @@ -493,16 +487,17 @@ document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, return TRUE; } -void +gboolean document_interface_object_to_path (DocumentInterface *object, char *shape, GError **error) { const GSList *oldsel = selection_swap(object->desk, shape); dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); selection_restore(object->desk, oldsel); + return TRUE; } -gboolean +gchar * document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) { Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); @@ -510,15 +505,7 @@ document_interface_get_path (DocumentInterface *object, char *pathname, GError * g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); return FALSE; } - gchar *pathstr = strdup(node->attribute("d")); - printf("PATH: %s\n", pathstr); - //gfree (pathstr); - std::istringstream iss(pathstr); - std::copy(std::istream_iterator(iss), - std::istream_iterator(), - std::ostream_iterator(std::cout, "\n")); - - return TRUE; + return strdup(node->attribute("d")); } gboolean @@ -580,7 +567,14 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, DBUSPoint ** document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { - //FIXME: implement. + //FIXME: not implemented. + Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); + if (node == NULL || node->attribute("d") == NULL) { + g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); + return FALSE; + } + char * path = strdup(node->attribute("d")); + return NULL; } @@ -712,8 +706,8 @@ document_interface_update (DocumentInterface *object, GError **error) SELECTION FUNCTIONS FIXME: use call_verb where appropriate. ****************************************************************************/ -gchar ** -document_interface_selection_get (DocumentInterface *object) +gboolean +document_interface_selection_get (DocumentInterface *object, GSList const * listy, GError **error) { Inkscape::Selection * sel = sp_desktop_selection(object->desk); GSList const *oldsel = sel->list(); @@ -737,7 +731,8 @@ document_interface_selection_get (DocumentInterface *object) printf("%d = %s\n", i, list[i]); } - return list; + listy = oldsel; + return TRUE; } gboolean -- cgit v1.2.3 From 0c4a64e7df83742bb6d7a17f31985eed9d06ef26 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 16 Jul 2009 16:28:50 +0000 Subject: Whoops, fixed a bug in an incomplete method. (bzr r8254.1.14) --- src/extension/dbus/document-interface.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e3573989a..914303a91 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -567,14 +567,15 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, DBUSPoint ** document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { - //FIXME: not implemented. + //FIXME: Needs lot's of work. +/* Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); if (node == NULL || node->attribute("d") == NULL) { g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); return FALSE; } - char * path = strdup(node->attribute("d")); - + //char * path = strdup(node->attribute("d")); +*/ return NULL; } -- cgit v1.2.3 From 88870910722f4cef3a929b49479d2fa721e4f715 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 20 Jul 2009 20:34:13 +0000 Subject: Fixed selection_get() (bzr r8254.1.15) --- src/extension/dbus/document-interface.cpp | 49 +++++++++++++------------------ 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 914303a91..b9d8848cc 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -671,7 +671,7 @@ document_interface_redo (DocumentInterface *object, GError **error) /**************************************************************************** - UPDATE FUNCTIONS + UPDATE FUNCTIONS FIXME: test update system again. ****************************************************************************/ void @@ -689,6 +689,7 @@ document_interface_resume_updates (DocumentInterface *object, GError **error) sp_desktop_document(object->desk)->root->uflags = TRUE; sp_desktop_document(object->desk)->root->mflags = TRUE; //sp_desktop_document(object->desk)->_updateDocument(); + //FIXME: use better verb than rect. sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); } @@ -708,31 +709,22 @@ document_interface_update (DocumentInterface *object, GError **error) ****************************************************************************/ gboolean -document_interface_selection_get (DocumentInterface *object, GSList const * listy, GError **error) +document_interface_selection_get (DocumentInterface *object, char ***out, GError **error) { Inkscape::Selection * sel = sp_desktop_selection(object->desk); GSList const *oldsel = sel->list(); int size = g_slist_length((GSList *) oldsel); - int i; - printf("premalloc\n"); - gchar **list = (gchar **)malloc(size); - printf("postmalloc\n"); - for(i = 0; i < size; i++) - list[i] = (gchar *)malloc(sizeof(gchar) * 10); - printf("postmalloc2\n"); - i=0; - printf("prealloc\n"); + + *out = g_new0 (char *, size + 1); + + int i = 0; for (GSList const *iter = oldsel; iter != NULL; iter = iter->next) { - strcpy (list[i], SP_OBJECT(iter->data)->repr->attribute("id")); + (*out)[i] = g_strdup(SP_OBJECT(iter->data)->repr->attribute("id")); i++; } - printf("postalloc\n"); - for (i=0; idesk); Inkscape::Selection *selection = sp_desktop_selection(object->desk); - /* WORKS - Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); - selection->add(repr2, TRUE); - */ - selection->add(doc->getObjectById(name)); + + selection->add(get_object_by_name(object->desk, name)); return TRUE; } @@ -755,8 +743,12 @@ gboolean document_interface_selection_add_list (DocumentInterface *object, char **names, GError **error) { - //FIXME: implement. - return FALSE; + int i; + for (i=0;names[i] != NULL;i++) { + //printf("NAME: %s\n", names[i]); + document_interface_selection_add(object, names[i], error); + } + return TRUE; } gboolean @@ -772,11 +764,10 @@ gboolean document_interface_selection_set_list (DocumentInterface *object, gchar **names, GError **error) { - //FIXME: broken array passing. sp_desktop_selection(object->desk)->clear(); int i; - for (i=0;((i<30000) && (names[i] != NULL));i++) { - printf("NAME: %s\n", names[i]); + for (i=0;names[i] != NULL;i++) { + //printf("NAME: %s\n", names[i]); document_interface_selection_add(object, names[i], error); } return TRUE; -- cgit v1.2.3 From 40d5732d5a327c51e04c6aaab97725d0d61b2327 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 20 Jul 2009 22:55:35 +0000 Subject: Fixed selection_get_center and selection_combine. Added selection_divide. (bzr r8254.1.16) --- src/extension/dbus/document-interface.cpp | 37 +++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index b9d8848cc..a939064e1 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -745,7 +745,6 @@ document_interface_selection_add_list (DocumentInterface *object, { int i; for (i=0;names[i] != NULL;i++) { - //printf("NAME: %s\n", names[i]); document_interface_selection_add(object, names[i], error); } return TRUE; @@ -767,7 +766,6 @@ document_interface_selection_set_list (DocumentInterface *object, sp_desktop_selection(object->desk)->clear(); int i; for (i=0;names[i] != NULL;i++) { - //printf("NAME: %s\n", names[i]); document_interface_selection_add(object, names[i], error); } return TRUE; @@ -882,7 +880,6 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou Geom::OptRect sel_bbox = sel->bounds(); if (sel_bbox) { - //Geom::Point m( (object->desk)->point() - sel_bbox->midpoint() ); Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) ); sp_selection_move_relative(sel, m, true); } @@ -915,11 +912,23 @@ document_interface_selection_move_to_layer (DocumentInterface *object, return TRUE; } -gboolean +GArray * document_interface_selection_get_center (DocumentInterface *object) { - //FIXME: implement: pass struct. - return FALSE; + Inkscape::Selection * sel = sp_desktop_selection(object->desk); + + if (sel) + { + gdouble x = selection_get_center_x(sel); + gdouble y = selection_get_center_y(sel); + GArray * intArr = g_array_new (TRUE, TRUE, sizeof(double)); + + g_array_append_val (intArr, x); + g_array_append_val (intArr, y); + return intArr; + } + + return NULL; } gboolean @@ -933,7 +942,6 @@ gchar * document_interface_selection_combine (DocumentInterface *object, gchar *cmd, GError **error) { - if (strcmp(cmd, "union") == 0) dbus_call_verb (object, SP_VERB_SELECTION_UNION, error); else if (strcmp(cmd, "intersection") == 0) @@ -947,8 +955,19 @@ document_interface_selection_combine (DocumentInterface *object, gchar *cmd, else return NULL; - //FIXME: this WILL cause problems with division - return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); + if (sp_desktop_selection(object->desk)->singleRepr() != NULL) + return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); + + //Division will have a list of things selected, should have it's own function. + return NULL; +} + +gboolean +document_interface_selection_divide (DocumentInterface *object, char ***out, GError **error) +{ + dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + + return document_interface_selection_get (object, out, error); } gboolean -- cgit v1.2.3 From c30b66d5e5f875384b4fa13f93ceb6bea8054830 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Tue, 21 Jul 2009 01:48:22 +0000 Subject: Worked on text, now works with limited capability. Started work on node_get_coordinates. (bzr r8254.1.17) --- src/extension/dbus/document-interface.cpp | 40 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index a939064e1..a28bb92fa 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -32,6 +32,11 @@ #include "print.h" //IO +#include "live_effects/parameter/text.h" //text +#include "display/canvas-text.h" //text + +#include "2geom/svg-path-parser.h" //get_node_coordinates + /**************************************************************************** HELPER / SHORTCUT FUNCTIONS ****************************************************************************/ @@ -335,11 +340,17 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, return retval; } -gchar* -document_interface_text (DocumentInterface *object, gchar *text, GError **error) +gboolean +document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) { - //FIXME: implement. - return NULL; + //FIXME: Not selectable. + + SPDesktop *desktop = object->desk; + SPCanvasText * canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, text); + sp_canvastext_set_coords (canvas_text, x, y); + + return TRUE; } gchar* @@ -564,18 +575,19 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, return TRUE; } -DBUSPoint ** +GArray * document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { //FIXME: Needs lot's of work. -/* - Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); - if (node == NULL || node->attribute("d") == NULL) { - g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); + + Inkscape::XML::Node *shapenode = document_retrive_node (sp_desktop_document (object->desk), shape); + if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } - //char * path = strdup(node->attribute("d")); -*/ + const char * path = strdup(shapenode->attribute("d")); + printf("PATH: %s\n", path); + + Geom::parse_svg_path (path); return NULL; } @@ -705,7 +717,7 @@ document_interface_update (DocumentInterface *object, GError **error) } /**************************************************************************** - SELECTION FUNCTIONS FIXME: use call_verb where appropriate. + SELECTION FUNCTIONS FIXME: use call_verb where appropriate (once update system is tested.) ****************************************************************************/ gboolean @@ -950,15 +962,11 @@ 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 if (strcmp(cmd, "division") == 0) - dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); else return NULL; if (sp_desktop_selection(object->desk)->singleRepr() != NULL) return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); - - //Division will have a list of things selected, should have it's own function. return NULL; } -- cgit v1.2.3 From f09b3a57c8a6259ef82db7be0786ff2959874a24 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Tue, 21 Jul 2009 17:50:12 +0000 Subject: worked on path parsing. (bzr r8254.1.18) --- src/extension/dbus/document-interface.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index a28bb92fa..9a900e0ee 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -52,6 +52,9 @@ SPObject * get_object_by_name (SPDesktop *desk, gchar *name) { return sp_desktop_document(desk)->getObjectById(name); + /* ALTERNATIVE (is this faster if only repr is needed?) + Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); + */ } const gchar * @@ -584,7 +587,7 @@ document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } - const char * path = strdup(shapenode->attribute("d")); + char * path = strdup(shapenode->attribute("d")); printf("PATH: %s\n", path); Geom::parse_svg_path (path); -- cgit v1.2.3 From 4caca0b9edefb8470c058fdfed95ff50e0324499 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Wed, 22 Jul 2009 06:22:59 +0000 Subject: Fixed GErrors. Added many GErrors, especially for unfound objects. transfered many functions to using verbs instead of the function the verb calls to make error reporting easier. (bzr r8254.1.19) --- src/extension/dbus/document-interface.cpp | 285 ++++++++++++++++++++++-------- 1 file changed, 211 insertions(+), 74 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 9a900e0ee..664655f0e 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -35,7 +35,7 @@ #include "live_effects/parameter/text.h" //text #include "display/canvas-text.h" //text -#include "2geom/svg-path-parser.h" //get_node_coordinates +//#include "2geom/svg-path-parser.h" //get_node_coordinates /**************************************************************************** HELPER / SHORTCUT FUNCTIONS @@ -48,19 +48,48 @@ const gchar* intToCString(int i) return ss.str().c_str(); } -SPObject * -get_object_by_name (SPDesktop *desk, gchar *name) +Inkscape::XML::Node * +get_repr_by_name (SPDesktop *desk, gchar *name, GError **error) { - return sp_desktop_document(desk)->getObjectById(name); /* ALTERNATIVE (is this faster if only repr is needed?) - Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); + Inkscape::XML::Node *node = sp_repr_lookup_name((doc->root)->repr, name); */ + Inkscape::XML::Node * node = sp_desktop_document(desk)->getObjectById(name)->repr; + if (!node) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name); + return NULL; + } + return node; +} + +SPObject * +get_object_by_name (SPDesktop *desk, gchar *name, GError **error) +{ + SPObject * obj = sp_desktop_document(desk)->getObjectById(name); + if (!obj) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name); + return NULL; + } + return obj; +} + +gboolean +dbus_check_string (gchar *string, GError ** error, gchar * errorstr) +{ + if (string == NULL) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "%s", errorstr); + return FALSE; + } + return TRUE; } const gchar * get_name_from_object (SPObject * obj) { - return obj->repr->attribute("id"); + return obj->repr->attribute("id"); } void @@ -70,11 +99,6 @@ desktop_ensure_active (SPDesktop* desk) { return; } -Inkscape::XML::Node * -document_retrive_node (SPDocument *doc, gchar *name) { - return (doc->getObjectById(name))->repr; -} - gdouble selection_get_center_x (Inkscape::Selection *sel){ NRRect *box = g_new(NRRect, 1);; @@ -90,12 +114,12 @@ selection_get_center_y (Inkscape::Selection *sel){ } //move_to etc const GSList * -selection_swap(SPDesktop *desk, gchar *name) +selection_swap(SPDesktop *desk, 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)); + sel->set(get_object_by_name(desk, name, error)); return oldsel; } @@ -147,7 +171,8 @@ 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 ) { @@ -161,6 +186,7 @@ dbus_call_verb (DocumentInterface *object, int verbid, GError **error) } } } + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb failed to execute"); return FALSE; } @@ -198,6 +224,42 @@ document_interface_new (void) return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL); } +GQuark +inkscape_error_quark (void) +{ + static GQuark quark = 0; + if (!quark) + quark = g_quark_from_static_string ("inkscape_error"); + + return quark; +} + +/* This should really be standard. */ +#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } + +GType +inkscape_error_get_type (void) +{ + static GType etype = 0; + + if (etype == 0) + { + static const GEnumValue values[] = + { + + ENUM_ENTRY (INKSCAPE_ERROR_SELECTION, "Incompatible_Selection"), + ENUM_ENTRY (INKSCAPE_ERROR_OBJECT, "Incompatible_Object"), + ENUM_ENTRY (INKSCAPE_ERROR_VERB, "Failed_Verb"), + ENUM_ENTRY (INKSCAPE_ERROR_OTHER, "Generic_Error"), + { 0, 0, 0 } + }; + + etype = g_enum_register_static ("InkscapeError", values); + } + + return etype; +} + /**************************************************************************** MISC FUNCTIONS ****************************************************************************/ @@ -209,7 +271,7 @@ document_interface_delete_all (DocumentInterface *object, GError **error) return TRUE; } -void +gboolean document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error) { SPDesktop *desk2 = object->desk; @@ -226,6 +288,8 @@ document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError * } } } + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb '%s' failed to execute or was not found.", verbid); + return FALSE; } @@ -422,7 +486,7 @@ gboolean document_interface_document_resize_to_fit_selection (DocumentInterface *object, GError **error) { - dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); + return dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); return TRUE; } @@ -434,56 +498,72 @@ gboolean document_interface_set_attribute (DocumentInterface *object, char *shape, char *attribute, char *newval, GError **error) { - Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; + Inkscape::XML::Node *newNode = get_repr_by_name(object->desk, shape, error); /* ALTERNATIVE (is this faster?) Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); */ - if (newNode) - { - newNode->setAttribute(attribute, newval, TRUE); - return TRUE; - } - return FALSE; + if (!dbus_check_string(newval, error, "New value string was empty.")) + return FALSE; + + if (!newNode) + return FALSE; + + newNode->setAttribute(attribute, newval, TRUE); + return TRUE; } -void +gboolean document_interface_set_int_attribute (DocumentInterface *object, char *shape, char *attribute, int newval, GError **error) { - Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; - if (newNode) - sp_repr_set_int (newNode, attribute, newval); + Inkscape::XML::Node *newNode = get_repr_by_name (object->desk, shape, error); + if (!newNode) + return FALSE; + + sp_repr_set_int (newNode, attribute, newval); + return TRUE; } -void +gboolean document_interface_set_double_attribute (DocumentInterface *object, char *shape, char *attribute, double newval, GError **error) { - Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; - if (newNode) - sp_repr_set_svg_double (newNode, attribute, newval); + Inkscape::XML::Node *newNode = get_repr_by_name (object->desk, shape, error); + + if (!dbus_check_string (attribute, error, "New value string was empty.")) + return FALSE; + if (!newNode) + return FALSE; + + sp_repr_set_svg_double (newNode, attribute, newval); + return TRUE; } gchar * document_interface_get_attribute (DocumentInterface *object, char *shape, char *attribute, GError **error) { - Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; + Inkscape::XML::Node *newNode = get_repr_by_name(object->desk, shape, error); - if (newNode) - return g_strdup(newNode->attribute(attribute)); - return FALSE; + if (!dbus_check_string (attribute, error, "Attribute name empty.")) + return NULL; + if (!newNode) + return NULL; + + return g_strdup(newNode->attribute(attribute)); } gboolean document_interface_move (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->desk, name); + const GSList *oldsel = selection_swap(object->desk, name, error); + if (!oldsel) + return FALSE; sp_selection_move (object->desk, x, 0 - y); selection_restore(object->desk, oldsel); return TRUE; @@ -493,7 +573,9 @@ gboolean document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->desk, name); + const GSList *oldsel = selection_swap(object->desk, 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), 0 - (y - selection_get_center_y(sel))); @@ -505,7 +587,9 @@ gboolean document_interface_object_to_path (DocumentInterface *object, char *shape, GError **error) { - const GSList *oldsel = selection_swap(object->desk, shape); + const GSList *oldsel = selection_swap(object->desk, shape, error); + if (!oldsel) + return FALSE; dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); selection_restore(object->desk, oldsel); return TRUE; @@ -514,10 +598,15 @@ document_interface_object_to_path (DocumentInterface *object, gchar * document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) { - Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); - if (node == NULL || node->attribute("d") == NULL) { - g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); - return FALSE; + Inkscape::XML::Node *node = get_repr_by_name(object->desk, pathname, error); + + if (!node) + return NULL; + + if (node->attribute("d") == NULL) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object is not a path."); + return NULL; } return strdup(node->attribute("d")); } @@ -544,8 +633,15 @@ gboolean document_interface_modify_css (DocumentInterface *object, 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_object_by_name(object->desk, shape)->repr; + Inkscape::XML::Node *node = get_repr_by_name(object->desk, shape, error); + + if (!dbus_check_string (cssattrb, error, "Attribute string empty.")) + return FALSE; + if (!node) + return FALSE; + SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); sp_repr_css_set_property(oldstyle, cssattrb, newval); node->setAttribute (style, sp_repr_css_write_string (oldstyle), TRUE); @@ -556,11 +652,18 @@ gboolean document_interface_merge_css (DocumentInterface *object, gchar *shape, gchar *stylestring, GError **error) { + gchar style[] = "style"; + + Inkscape::XML::Node *node = get_repr_by_name(object->desk, shape, error); + + if (!dbus_check_string (stylestring, error, "Style string empty.")) + return FALSE; + if (!node) + return FALSE; + SPCSSAttr * newstyle = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string (newstyle, stylestring); - gchar style[] = "style"; - Inkscape::XML::Node *node = get_object_by_name(object->desk, shape)->repr; SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); sp_repr_css_merge(oldstyle, newstyle); @@ -572,7 +675,10 @@ gboolean document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) { - const GSList *oldsel = selection_swap(object->desk, shape); + const GSList *oldsel = selection_swap(object->desk, shape, error); + if (!oldsel) + return FALSE; + document_interface_selection_move_to_layer(object, layerstr, error); selection_restore(object->desk, oldsel); return TRUE; @@ -582,8 +688,8 @@ GArray * document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { //FIXME: Needs lot's of work. - - Inkscape::XML::Node *shapenode = document_retrive_node (sp_desktop_document (object->desk), shape); +/* + Inkscape::XML::Node *shapenode = get_repr_by_name (object->desk, shape, error); if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } @@ -592,6 +698,7 @@ document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape Geom::parse_svg_path (path); return NULL; + */ } @@ -645,6 +752,16 @@ document_interface_save_as (DocumentInterface *object, //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, "Document saved."); return true; } + +gboolean +document_interface_mark_as_unmodified (DocumentInterface *object, GError **error) +{ + SPDocument * doc = sp_desktop_document(object->desk); + if (doc) + doc->modified_since_save = FALSE; + return TRUE; +} + /* gboolean document_interface_print_to_file (DocumentInterface *object, GError **error) @@ -686,7 +803,10 @@ document_interface_redo (DocumentInterface *object, GError **error) /**************************************************************************** - UPDATE FUNCTIONS FIXME: test update system again. + UPDATE FUNCTIONS + FIXME: This would work better by adding a flag to SPDesktop to prevent + updating but that would be very intrusive so for now there is a workaround. + Need to make sure it plays well with verbs because they are used so much. ****************************************************************************/ void @@ -746,11 +866,13 @@ document_interface_selection_get (DocumentInterface *object, char ***out, GError gboolean document_interface_selection_add (DocumentInterface *object, char *name, GError **error) { - if (name == NULL) + SPObject * obj = get_object_by_name(object->desk, name, error); + if (!obj) return FALSE; + Inkscape::Selection *selection = sp_desktop_selection(object->desk); - selection->add(get_object_by_name(object->desk, name)); + selection->add(obj); return TRUE; } @@ -797,8 +919,8 @@ document_interface_selection_rotate (DocumentInterface *object, int angle, GErro gboolean document_interface_selection_delete (DocumentInterface *object, GError **error) { - sp_selection_delete (object->desk); - return TRUE; + //sp_selection_delete (object->desk); + return dbus_call_verb (object, SP_VERB_EDIT_DELETE, error); } gboolean @@ -811,16 +933,16 @@ document_interface_selection_clear (DocumentInterface *object, GError **error) gboolean document_interface_select_all (DocumentInterface *object, GError **error) { - sp_edit_select_all (object->desk); - return TRUE; + //sp_edit_select_all (object->desk); + return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL, error); } gboolean document_interface_select_all_in_all_layers(DocumentInterface *object, GError **error) { - sp_edit_select_all_in_all_layers (object->desk); - return TRUE; + //sp_edit_select_all_in_all_layers (object->desk); + return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error); } gboolean @@ -835,48 +957,55 @@ document_interface_selection_box (DocumentInterface *object, int x, int y, gboolean document_interface_selection_invert (DocumentInterface *object, GError **error) { - sp_edit_invert (object->desk); - return TRUE; + //sp_edit_invert (object->desk); + return dbus_call_verb (object, SP_VERB_EDIT_INVERT, error); } gboolean document_interface_selection_group (DocumentInterface *object, GError **error) { - sp_selection_group (object->desk); - return TRUE; + //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 TRUE; + //sp_selection_ungroup (object->desk); + return dbus_call_verb (object, SP_VERB_SELECTION_UNGROUP, error); } gboolean document_interface_selection_cut (DocumentInterface *object, GError **error) { - sp_selection_cut (object->desk); - return TRUE; + //desktop_ensure_active (object->desk); + //sp_selection_cut (object->desk); + 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 (); - return TRUE; + //desktop_ensure_active (object->desk); + //sp_selection_copy (); + return dbus_call_verb (object, SP_VERB_EDIT_COPY, error); } + gboolean document_interface_selection_paste (DocumentInterface *object, GError **error) { - desktop_ensure_active (object->desk); - sp_selection_paste (object->desk, TRUE); - return TRUE; + //desktop_ensure_active (object->desk); + //sp_selection_paste (object->desk, TRUE); + return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); } gboolean document_interface_selection_scale (DocumentInterface *object, gdouble grow, GError **error) { Inkscape::Selection *selection = sp_desktop_selection(object->desk); + if (!selection) + { + return FALSE; + } sp_selection_scale (selection, grow); return TRUE; } @@ -914,9 +1043,12 @@ document_interface_selection_move_to_layer (DocumentInterface *object, if (selection->isEmpty()) return FALSE; - SPObject *next = get_object_by_name(object->desk, layerstr); + SPObject *next = get_object_by_name(object->desk, layerstr, error); + + if (!next) + return FALSE; - if (next && (strcmp("layer", (next->repr)->attribute("inkscape:groupmode")) == 0)) { + if (strcmp("layer", (next->repr)->attribute("inkscape:groupmode")) == 0) { sp_selection_cut(dt); @@ -1013,7 +1145,12 @@ gboolean document_interface_layer_set (DocumentInterface *object, gchar *layerstr, GError **error) { - object->desk->setCurrentLayer (get_object_by_name (object->desk, layerstr)); + SPObject * obj = get_object_by_name (object->desk, layerstr, error); + + if (!obj) + return FALSE; + + object->desk->setCurrentLayer (obj); return TRUE; } -- cgit v1.2.3 From 9a8f192eab6f5ee7591be8ce25c48fe142809663 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Wed, 22 Jul 2009 22:40:00 +0000 Subject: Experimental pause updating scheme. (bzr r8254.1.20) --- src/extension/dbus/document-interface.cpp | 49 +++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 664655f0e..76eeec509 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -161,8 +161,8 @@ finish_create_shape (DocumentInterface *object, GError **error, Inkscape::XML::N if (object->updates) sp_document_done(sp_desktop_document(object->desk), 0, (gchar *)desc); - else - document_interface_pause_updates(object, error); + //else + //document_interface_pause_updates(object, error); return strdup(newNode->attribute("id")); } @@ -178,10 +178,13 @@ dbus_call_verb (DocumentInterface *object, int verbid, GError **error) if ( verb ) { SPAction *action = verb->get_action(desk2); if ( action ) { + //if (!object->updates) + //document_interface_pause_updates (object, error); sp_action_perform( action, NULL ); - if (object->updates) { + if (object->updates) sp_document_done(sp_desktop_document(desk2), verb->get_code(), g_strdup(verb->get_tip())); - } + //if (!object->updates) + //document_interface_pause_updates (object, error); return TRUE; } } @@ -433,8 +436,8 @@ document_interface_node (DocumentInterface *object, gchar *type, GError **error) if (object->updates) sp_document_done(sp_desktop_document(object->desk), 0, (gchar *)"created empty node"); - else - document_interface_pause_updates(object, error); + //else + //document_interface_pause_updates(object, error); return strdup(newNode->attribute("id")); } @@ -699,6 +702,7 @@ document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape Geom::parse_svg_path (path); return NULL; */ + return NULL; } @@ -813,16 +817,22 @@ void document_interface_pause_updates (DocumentInterface *object, GError **error) { object->updates = FALSE; - sp_desktop_document(object->desk)->root->uflags = FALSE; - sp_desktop_document(object->desk)->root->mflags = 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; } void document_interface_resume_updates (DocumentInterface *object, GError **error) { object->updates = TRUE; - sp_desktop_document(object->desk)->root->uflags = TRUE; - sp_desktop_document(object->desk)->root->mflags = 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(); //FIXME: use better verb than rect. sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); @@ -833,7 +843,9 @@ document_interface_update (DocumentInterface *object, GError **error) { sp_desktop_document(object->desk)->root->uflags = TRUE; sp_desktop_document(object->desk)->root->mflags = TRUE; + object->desk->enableInteraction(); sp_desktop_document(object->desk)->_updateDocument(); + object->desk->disableInteraction(); sp_desktop_document(object->desk)->root->uflags = FALSE; sp_desktop_document(object->desk)->root->mflags = FALSE; //sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions"); @@ -989,12 +1001,23 @@ document_interface_selection_copy (DocumentInterface *object, GError **error) //sp_selection_copy (); return dbus_call_verb (object, SP_VERB_EDIT_COPY, error); } - +/* +gboolean +document_interface_selection_paste (DocumentInterface *object, GError **error) +{ + desktop_ensure_active (object->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) { - //desktop_ensure_active (object->desk); - //sp_selection_paste (object->desk, TRUE); return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error); } -- cgit v1.2.3 From 3924d56a36693270a4e543f076c653f9ceaec355 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 23 Jul 2009 16:41:13 +0000 Subject: Added set_color function. (bzr r8254.1.21) --- src/extension/dbus/document-interface.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 76eeec509..53674790a 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -76,7 +76,7 @@ get_object_by_name (SPDesktop *desk, gchar *name, GError **error) } gboolean -dbus_check_string (gchar *string, GError ** error, gchar * errorstr) +dbus_check_string (gchar *string, GError ** error, const gchar * errorstr) { if (string == NULL) { @@ -674,6 +674,28 @@ document_interface_merge_css (DocumentInterface *object, gchar *shape, return TRUE; } +gboolean +document_interface_set_color (DocumentInterface *object, gchar *shape, + int r, int g, int b, gboolean fill, GError **error) +{ + gchar style[15]; + if (r<0 || r>255 || g<0 || g>255 || b<0 || b>255) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Given (%d,%d,%d). All values must be between 0-255 inclusive.", r, g, b); + return FALSE; + } + + if (fill) + snprintf(style, 15, "fill:#%.2x%.2x%.2x", r, g, b); + else + 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_merge_css (object, shape, style, error); +} + gboolean document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) -- cgit v1.2.3 From 1198855fabe7ba883482425271bbff3d1e12c37d Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 23 Jul 2009 20:01:26 +0000 Subject: Added image import function. (bzr r8254.1.22) --- src/extension/dbus/document-interface.cpp | 42 ++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 53674790a..e0cf6a38b 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -131,15 +131,11 @@ selection_restore(SPDesktop *desk, const GSList * oldsel) } Inkscape::XML::Node * -dbus_create_node (SPDesktop *desk, gboolean isrect) +dbus_create_node (SPDesktop *desk, const gchar *type) { SPDocument * doc = sp_desktop_document (desk); Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); - gchar *type; - if (isrect) - type = (gchar *)"svg:rect"; - else - type = (gchar *)"svg:path"; + return xml_doc->createElement(type); } @@ -306,7 +302,7 @@ document_interface_rectangle (DocumentInterface *object, int x, int y, { - Inkscape::XML::Node *newNode = dbus_create_node(object->desk, TRUE); + Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "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); @@ -318,7 +314,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, FALSE); + Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); newNode->setAttribute("sodipodi:type", "arc"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -333,7 +329,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, FALSE); + Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); newNode->setAttribute("inkscape:flatsided", "true"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -354,7 +350,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, FALSE); + Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); newNode->setAttribute("inkscape:flatsided", "false"); newNode->setAttribute("sodipodi:type", "star"); sp_repr_set_int(newNode, "sodipodi:cx", cx); @@ -383,7 +379,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, FALSE); + Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); std::stringstream out; printf("X2: %d\nY2 %d\n", x2, y2); out << "m " << x << "," << y << " " << x2 << "," << y2; @@ -396,7 +392,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, FALSE); + Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path"); newNode->setAttribute("sodipodi:type", "spiral"); sp_repr_set_int(newNode, "sodipodi:cx", cx); sp_repr_set_int(newNode, "sodipodi:cy", cy); @@ -423,6 +419,28 @@ document_interface_text (DocumentInterface *object, int x, int y, gchar *text, G return TRUE; } +gchar * +document_interface_image (DocumentInterface *object, 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->desk, "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(); + + if (object->updates) + sp_document_done(sp_desktop_document(object->desk), 0, "Imported bitmap."); + + //g_free(uri); + return strdup(newNode->attribute("id")); +} + gchar* document_interface_node (DocumentInterface *object, gchar *type, GError **error) { -- cgit v1.2.3 From f49ab91f16c96e3e4ed84ea021b54946e7c08006 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 13 Aug 2009 20:53:03 +0000 Subject: Made wrapper functions non static. Added lots of documentation. (bzr r8254.1.24) --- src/extension/dbus/document-interface.cpp | 96 +++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 10 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e0cf6a38b..e7af7096c 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -1,3 +1,20 @@ +/* + * This is where the implementation of the DBus based document API lives. + * All the methods in here (except in the helper section) are + * designed to be called remotly via DBus. application-interface.cpp + * has the methods used to connect to the bus and get a document instance. + * + * Documentation for these methods is in document-interface.xml + * which is the "gold standard" as to how the interface should work. + * + * Authors: + * Soren Berg + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #include "document-interface.h" #include @@ -41,13 +58,16 @@ HELPER / SHORTCUT FUNCTIONS ****************************************************************************/ -const gchar* intToCString(int i) -{ - std::stringstream ss; - ss << i; - return ss.str().c_str(); -} - +/* + * This function or the one below it translates the user input for an object + * into Inkscapes internal representation. It is called by almost every + * method so it should be as fast as possible. + * + * (eg turns "rect2234" to an SPObject or Inkscape::XML::Node) + * + * If the internal representation changes (No more 'id' attributes) this is the + * place to adjust things. + */ Inkscape::XML::Node * get_repr_by_name (SPDesktop *desk, gchar *name, GError **error) { @@ -63,6 +83,9 @@ get_repr_by_name (SPDesktop *desk, gchar *name, GError **error) return node; } +/* + * See comment for get_repr_by_name, above. + */ SPObject * get_object_by_name (SPDesktop *desk, gchar *name, GError **error) { @@ -75,6 +98,11 @@ get_object_by_name (SPDesktop *desk, gchar *name, GError **error) return obj; } +/* + * Tests for NULL strings and throws an appropriate error. + * Every method that takes a string parameter (other than the + * name of an object, that's tested seperatly) should call this. + */ gboolean dbus_check_string (gchar *string, GError ** error, const gchar * errorstr) { @@ -86,12 +114,19 @@ dbus_check_string (gchar *string, GError ** error, const gchar * errorstr) return TRUE; } +/* + * This is used to return object values to the user + */ const gchar * get_name_from_object (SPObject * obj) { return obj->repr->attribute("id"); } +/* + * Some verbs (cut, paste) only work on the active layer. + * This makes sure that the document that is about to recive a command is active. + */ void desktop_ensure_active (SPDesktop* desk) { if (desk != SP_ACTIVE_DESKTOP) @@ -112,7 +147,21 @@ selection_get_center_y (Inkscape::Selection *sel){ box = sel->boundsInDocument(box); return box->y0 + ((box->y1 - box->y0)/2); } -//move_to etc + +/* + * This function is used along with selection_restore to + * take advantage of functionality provided by a selection + * for a single object. + * + * It saves the current selection and sets the selection to + * the object specified. Any selection verb can be used on the + * object and then selection_restore is called, restoring the + * original selection. + * + * This should be mostly transparent to the user who need never + * know we never bothered to implement it seperatly. Although + * they might see the selection box flicker if used in a loop. + */ const GSList * selection_swap(SPDesktop *desk, gchar *name, GError **error) { @@ -123,6 +172,9 @@ selection_swap(SPDesktop *desk, gchar *name, GError **error) return oldsel; } +/* + * See selection_swap, above + */ void selection_restore(SPDesktop *desk, const GSList * oldsel) { @@ -130,6 +182,9 @@ selection_restore(SPDesktop *desk, const GSList * oldsel) sel->setList(oldsel); } +/* + * Shortcut for creating a Node. + */ Inkscape::XML::Node * dbus_create_node (SPDesktop *desk, const gchar *type) { @@ -139,6 +194,13 @@ dbus_create_node (SPDesktop *desk, const gchar *type) return xml_doc->createElement(type); } +/* + * Called by the shape creation functions. Gets the default style for the doc + * or sets it arbitrarily if none. + * + * 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) { @@ -163,6 +225,14 @@ finish_create_shape (DocumentInterface *object, GError **error, Inkscape::XML::N return strdup(newNode->attribute("id")); } +/* + * This is the code used internally to call all the verbs. + * + * It handles error reporting and update pausing (which needs some work.) + * This is a good place to improve efficiency as it is called a lot. + * + * document_interface_call_verb is similar but is called by the user. + */ gboolean dbus_call_verb (DocumentInterface *object, int verbid, GError **error) { @@ -223,6 +293,11 @@ document_interface_new (void) return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL); } +/* + * Error stuff... + * + * To add a new error type, edit here and in the .h InkscapeError enum. + */ GQuark inkscape_error_quark (void) { @@ -233,7 +308,6 @@ inkscape_error_quark (void) return quark; } -/* This should really be standard. */ #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } GType @@ -409,7 +483,7 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, gboolean document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) { - //FIXME: Not selectable. + //FIXME: Not selectable (aka broken). Needs to be rewritten completely. SPDesktop *desktop = object->desk; SPCanvasText * canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), ""); @@ -1094,6 +1168,8 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou } //FIXME: does not paste in new layer. +// 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, gchar *layerstr, GError **error) -- cgit v1.2.3 From f8c188ba29f18db8bf7af03ed8f80841f613bbc0 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 18:52:11 +0000 Subject: More documentation. (bzr r8254.1.32) --- src/extension/dbus/document-interface.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e7af7096c..05dd2925e 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -449,6 +449,7 @@ document_interface_ellipse (DocumentInterface *object, int x, int y, return document_interface_ellipse_center (object, x+rx, y+ry, rx, ry, error); } +/* FIXME: makes line but gets one endpoint wrong.*/ gchar* document_interface_line (DocumentInterface *object, int x, int y, int x2, int y2, GError **error) -- cgit v1.2.3 From aa3973adee525143989826b16d47c48c8d737cef Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 19:05:00 +0000 Subject: Fixed document_interface_line (Warning: I don't know why it works this way, it just does.) (bzr r8254.1.33) --- src/extension/dbus/document-interface.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 05dd2925e..ff691bab6 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -449,16 +449,14 @@ document_interface_ellipse (DocumentInterface *object, int x, int y, return document_interface_ellipse_center (object, x+rx, y+ry, rx, ry, error); } -/* FIXME: makes line but gets one endpoint wrong.*/ 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"); std::stringstream out; - printf("X2: %d\nY2 %d\n", x2, y2); - out << "m " << x << "," << y << " " << x2 << "," << y2; - printf ("PATH: %s\n", out.str().c_str()); + // 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"); } -- cgit v1.2.3 From 5c45322163136ff2390a441ecf95dcf2c73f01b3 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 19:23:12 +0000 Subject: Fixed spirals. (bzr r8254.1.34) --- src/extension/dbus/document-interface.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index ff691bab6..e2d7a41a2 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -475,7 +475,10 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, 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"); - newNode->setAttribute("style", "fill:none"); + //Makes sure there is no fill for spirals by default. + gchar* newString = g_strconcat(newNode->attribute("style"), ";fill:none", NULL); + newNode->setAttribute("style", newString); + g_free(newString); return retval; } -- cgit v1.2.3 From 1b5d271f226e3eeb2011d8762cc000e8a02eda1b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 00:23:23 -0600 Subject: Updating interface to add save type (bzr r8254.1.43) --- src/extension/dbus/document-interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/extension/dbus/document-interface.cpp') diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e2d7a41a2..b8b0c2ade 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -862,7 +862,7 @@ document_interface_save_as (DocumentInterface *object, try { Inkscape::Extension::save(NULL, doc, filename, - false, false, true); + false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } catch (...) { //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); return false; -- cgit v1.2.3