diff options
| author | Soren Berg <glimmer07@gmail.com> | 2009-07-23 20:01:26 +0000 |
|---|---|---|
| committer | glimmer07 <glimmer07@users.sourceforge.net> | 2009-07-23 20:01:26 +0000 |
| commit | 1198855fabe7ba883482425271bbff3d1e12c37d (patch) | |
| tree | f49e2aecbac0801c61acc6ad8f82b653f19da8a6 /src | |
| parent | Added set_color function. (diff) | |
| download | inkscape-1198855fabe7ba883482425271bbff3d1e12c37d.tar.gz inkscape-1198855fabe7ba883482425271bbff3d1e12c37d.zip | |
Added image import function.
(bzr r8254.1.22)
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/dbus/document-interface.cpp | 42 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.h | 4 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.xml | 29 |
3 files changed, 63 insertions, 12 deletions
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) { diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 413673862..436f6b118 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -93,6 +93,10 @@ document_interface_line (DocumentInterface *object, int x, int y, gboolean document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error); + +gchar * +document_interface_image (DocumentInterface *object, int x, int y, + gchar *filename, GError **error); gchar* document_interface_node (DocumentInterface *object, gchar *svgtype, diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 3ccae9556..c9cd8aa69 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -297,6 +297,35 @@ </doc:description> </doc:doc> </method> + + <method name="image"> + <arg type="i" name="x" direction="in" > + <doc:doc> + <doc:summary>The x coordinate to put the image at.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y" direction="in" > + <doc:doc> + <doc:summary>The y coordinate to put the image at.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="text" direction="in" > + <doc:doc> + <doc:summary>The full path of the image you want.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="object_name" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The name of the new image.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method imports a non-vector image (such as a jpeg, png, etc.) and places it at the given coordinates. The resulting shape has no style or path but can be treated like a rectangle. With and height can be set explicitly (will deform image) or transform strings or <doc:ref type="method" to="document.selection_scale">selection_scale()</doc:ref> can scale it relatively.</doc:para> + </doc:description> + </doc:doc> + </method> <method name="node"> <arg type="s" name="svgtype" direction="in" > |
