diff options
Diffstat (limited to '')
23 files changed, 6748 insertions, 0 deletions
diff --git a/src/extension/dbus/CMakeLists.txt b/src/extension/dbus/CMakeLists.txt new file mode 100644 index 0000000..f189180 --- /dev/null +++ b/src/extension/dbus/CMakeLists.txt @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +if(WITH_DBUS) +include_directories(${CMAKE_BINARY_DIR}/src/extension/dbus) +set(dbus_SRC "") + list(APPEND dbus_SRC + application-interface.cpp + dbus-init.cpp + document-interface.cpp + ) + add_custom_target(inkscape_dbus + DEPENDS ${CMAKE_BINARY_DIR}/src/extension/dbus/application-server-glue.h ${CMAKE_BINARY_DIR}/src/extension/dbus/document-server-glue.h ${CMAKE_BINARY_DIR}/src/extension/dbus/document-client-glue.h + ) + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/src/extension/dbus/application-server-glue.h ${CMAKE_BINARY_DIR}/src/extension/dbus/document-server-glue.h ${CMAKE_BINARY_DIR}/src/extension/dbus/document-client-glue.h + DEPENDS ${CMAKE_SOURCE_DIR}/src/extension/dbus/application-interface.xml ${CMAKE_SOURCE_DIR}/src/extension/dbus/document-interface.xml + COMMAND dbus-binding-tool --mode=glib-server --output=${CMAKE_BINARY_DIR}/src/extension/dbus/application-server-glue.h --prefix=application_interface ${CMAKE_SOURCE_DIR}/src/extension/dbus/application-interface.xml + COMMAND dbus-binding-tool --mode=glib-server --output=${CMAKE_BINARY_DIR}/src/extension/dbus/document-server-glue.h --prefix=document_interface ${CMAKE_SOURCE_DIR}/src/extension/dbus/document-interface.xml + COMMAND dbus-binding-tool --mode=glib-client --output=${CMAKE_BINARY_DIR}/src/extension/dbus/document-client-glue.h --prefix=document_interface ${CMAKE_SOURCE_DIR}/src/extension/dbus/document-interface.xml + ) + set_source_files_properties( + ${CMAKE_BINARY_DIR}/src/extension/dbus/application-server-glue.h + PROPERTIES GENERATED TRUE) + set_source_files_properties( + ${CMAKE_BINARY_DIR}/src/extension/dbus/document-server-glue.h + PROPERTIES GENERATED TRUE) + set_source_files_properties( + ${CMAKE_BINARY_DIR}/src/extension/dbus/document-client-glue.h + PROPERTIES GENERATED TRUE) +add_inkscape_source("${dbus_SRC}") +endif() diff --git a/src/extension/dbus/Notes.txt b/src/extension/dbus/Notes.txt new file mode 100644 index 0000000..25c3f35 --- /dev/null +++ b/src/extension/dbus/Notes.txt @@ -0,0 +1,79 @@ +INTRO: +For people that are interested in improving the DBus API here is a +intro to how everything is laid out. + +First read the documentation for a general idea of how the different interfaces +fit together and how Dbus is used in this application. + +Here are short descriptions of the relevant files: + +document-interface.cpp: This has most of the "meat" of the interface, this is where +most functions are implemented. + +application-interface.cpp: This is where the application interface is implemented. + +(document/application)-interface.xml: These files are the master record of the interfaces. +All of the documentation is generated from these files as is a lot of glue code. +Any changes MUST be reflected here. + +dbus-init.cpp: This is where the interface is exposed when Inkscape starts up. +Here is where the names given to the various interfaces are set. The application interface is constant but the document interfaces are generated on the fly. + +org.inkscape.service.in: This sets where DBus looks for the Inkscape executable +if it is not running when someone tries to connect. + +pytester.py: A python script that tests a lot of dbus functions. + +doc/builddocs.sh: builds documentation out of the XML files and some others. + +config.xsl, dbus-introspect-docs.dtd, spec-to-docbook.xsl, docbook.css: I borrowed +these files, they set how the documentation looks, I have no idea how to edit them. + +doc/inkscapeDbusRef.xml: This is the top level file for laying out the documentation, +it also includes the introduction. + +doc/inkscapeDbusTerms.xml: This contains the terms sections of the documentation. +Also the overview and all the tutorials. + +*.ref.xml: These are intermediate files, do not edit. + +wrapper/inkscape-dbus-wrapper.c: This is actually completely separate from inkscape. +It has a wrapper for each function in the document interface and includes the +client generated bindings. It is used to create a shared object that will allow +people to use the interface without even knowing anything about Dbus. + +BUGS: + *Inkscape crashes if widow is closed while code is running, + need better error handling. + + *Pause updates needs work. + + *Default style for new shapes is occasionally strange. + + *The following methods are broken: + -document_interface_selection_move_to_layer + + *The following are not implemented: + -document_interface_layer_get_all + -document_interface_selection_box + -document_interface_get_node_coordinates + + *The following do not behave like the documentation: + -document_interface_transform + -document_interface_text + +EFFICIENCY: + *Need better way to retrieve objects by name. + Switch to GQuark codes for object retrieval? + + *Rethink how often activate_desktop needs to be called. + +FEATURES: + *Find out more about extension API. + *API compatibility for plugins? + +CLEANUP: + + + + diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp new file mode 100644 index 0000000..1b4be69 --- /dev/null +++ b/src/extension/dbus/application-interface.cpp @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This is where the implementation of the DBus based application API lives. + * All the methods in here are designed to be called remotly via DBus. + * document-interface.cpp has all of the actual manipulation methods. + * This interface is just for creating new document interfaces. + * + * Documentation for these methods is in application-interface.xml + * which is the "gold standard" as to how the interface should work. + * + * Authors: + * Soren Berg <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "application-interface.h" +#include <string.h> +#include "dbus-init.h" +#include "file.h" +#include "inkscape.h" + +G_DEFINE_TYPE(ApplicationInterface, application_interface, G_TYPE_OBJECT) + +static void +application_interface_finalize (GObject *object) +{ + G_OBJECT_CLASS (application_interface_parent_class)->finalize (object); +} + + +static void +application_interface_class_init (ApplicationInterfaceClass *klass) +{ + GObjectClass *object_class; + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = application_interface_finalize; +} + +static void +application_interface_init (ApplicationInterface *app_interface) +{ + dbus_g_error_domain_register (INKSCAPE_ERROR, + NULL, + INKSCAPE_TYPE_ERROR); +} + +static bool +ensure_desktop_valid(GError **error) +{ + if (!INKSCAPE.use_gui()) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires a GUI"); + return false; + } + return true; +} + +static bool +ensure_desktop_not_present(GError **error) +{ + if (INKSCAPE.use_gui()) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Application interface action requires non-GUI (command line) mode"); + return false; + } + return true; +} + +ApplicationInterface * +application_interface_new (void) +{ + return (ApplicationInterface*)g_object_new (TYPE_APPLICATION_INTERFACE, NULL); +} + +/* + * Error stuff... + * + * To add a new error type, edit here and in the .h InkscapeError enum. + */ +GQuark +inkscape_error_quark (void) +{ + static GQuark quark = 0; + if (!quark) + quark = g_quark_from_static_string ("inkscape_error"); + + return quark; +} + +#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; +} + +/**************************************************************************** + DESKTOP FUNCTIONS +****************************************************************************/ + +gchar* +application_interface_desktop_new (ApplicationInterface *app_interface, + GError **error) +{ + g_return_val_if_fail(ensure_desktop_valid(error), NULL); + return (gchar*)Inkscape::Extension::Dbus::init_desktop(); +} + +gchar** +application_interface_get_desktop_list (ApplicationInterface *app_interface) +{ + return NULL; +} + +gchar* +application_interface_get_active_desktop (ApplicationInterface *app_interface, + GError **error) +{ + return NULL; +} + +gboolean +application_interface_set_active_desktop (ApplicationInterface *app_interface, + gchar* document_name, + GError **error) +{ + return TRUE; +} + +gboolean +application_interface_desktop_close_all (ApplicationInterface *app_interface, + GError **error) +{ + return TRUE; +} + +gboolean +application_interface_exit (ApplicationInterface *app_interface, GError **error) +{ + sp_file_exit(); + return TRUE; +} + +/**************************************************************************** + DOCUMENT FUNCTIONS +****************************************************************************/ + +gchar* application_interface_document_new (ApplicationInterface *app_interface, + GError **error) +{ + g_return_val_if_fail(ensure_desktop_not_present(error), NULL); + return (gchar*)Inkscape::Extension::Dbus::init_document(); +} + +gchar* +application_interface_get_active_document(ApplicationInterface *app_interface, + GError **error) +{ + gchar *result = (gchar*)Inkscape::Extension::Dbus::init_active_document(); + if (!result) { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "No active document"); + } + return result; +} + +gchar** +application_interface_get_document_list (ApplicationInterface *app_interface) +{ + return NULL; +} + +gboolean +application_interface_document_close_all (ApplicationInterface *app_interface, + GError **error) +{ + return TRUE; +} + +/* INTERESTING FUNCTIONS + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + g_assert(desktop != NULL); + + SPDocument *doc = desktop->getDocument(); + g_assert(doc != NULL); + + Inkscape::XML::Node *repr = doc->getReprRoot(); + g_assert(repr != NULL); +*/ + diff --git a/src/extension/dbus/application-interface.h b/src/extension/dbus/application-interface.h new file mode 100644 index 0000000..9e97585 --- /dev/null +++ b/src/extension/dbus/application-interface.h @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This is where the implementation of the DBus based application API lives. + * All the methods in here are designed to be called remotly via DBus. + * document-interface.cpp has all of the actual manipulation methods. + * This interface is just for creating new document interfaces. + * + * Documentation for these methods is in application-interface.xml + * which is the "gold standard" as to how the interface should work. + * + * Authors: + * Soren Berg <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_ +#define INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_ + +#include <glib.h> +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-bindings.h> +#include <dbus/dbus-glib-lowlevel.h> + +#define DBUS_APPLICATION_INTERFACE_PATH "/org/inkscape/application" + +#define TYPE_APPLICATION_INTERFACE (application_interface_get_type ()) +#define APPLICATION_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_APPLICATION_INTERFACE, ApplicationInterface)) +#define APPLICATION_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APPLICATION_INTERFACE, ApplicationInterfaceClass)) +#define IS_APPLICATION_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TYPE_APPLICATION_INTERFACE)) +#define IS_APPLICATION_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APPLICATION_INTERFACE)) +#define APPLICATION_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APPLICATION_INTERFACE, ApplicationInterfaceClass)) + +G_BEGIN_DECLS + +typedef struct _ApplicationInterface ApplicationInterface; +typedef struct _ApplicationInterfaceClass ApplicationInterfaceClass; + +struct _ApplicationInterface { + GObject parent; +}; + +struct _ApplicationInterfaceClass { + GObjectClass parent; +}; + + +enum InkscapeError +{ + INKSCAPE_ERROR_SELECTION, + INKSCAPE_ERROR_OBJECT, + INKSCAPE_ERROR_VERB, + INKSCAPE_ERROR_OTHER +}; + + + +#define INKSCAPE_ERROR (inkscape_error_quark ()) +#define INKSCAPE_TYPE_ERROR (inkscape_error_get_type ()) + +GQuark inkscape_error_quark (void); +GType inkscape_error_get_type (void); + +/**************************************************************************** + DESKTOP FUNCTIONS +****************************************************************************/ + +gchar* +application_interface_desktop_new (ApplicationInterface *app_interface, + GError **error); + +gchar** +application_interface_get_desktop_list (ApplicationInterface *app_interface); + +gchar* +application_interface_get_active_desktop (ApplicationInterface *app_interface, + GError **error); + +gboolean +application_interface_set_active_desktop (ApplicationInterface *app_interface, + gchar* document_name, + GError **error); + +gboolean +application_interface_desktop_close_all (ApplicationInterface *app_interface, + GError **error); + +gboolean +application_interface_exit (ApplicationInterface *app_interface, GError **error); + +/**************************************************************************** + DOCUMENT FUNCTIONS +****************************************************************************/ + +gchar* +application_interface_document_new (ApplicationInterface *app_interface, + GError **error); + +gchar* +application_interface_get_active_document(ApplicationInterface *app_interface, + GError **error); + +gchar** +application_interface_get_document_list (ApplicationInterface *app_interface); + +gboolean +application_interface_document_close_all (ApplicationInterface *app_interface, + GError **error); + + +/**************************************************************************** + SETUP +****************************************************************************/ + +ApplicationInterface *application_interface_new (void); +GType application_interface_get_type (void); + + +G_END_DECLS + +#endif // INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_ diff --git a/src/extension/dbus/application-interface.xml b/src/extension/dbus/application-interface.xml new file mode 100644 index 0000000..05513cb --- /dev/null +++ b/src/extension/dbus/application-interface.xml @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- SPDX-License-Identifier: GPL-2.0-or-later --> +<!-- + * This is the master description of the DBus application interface. + * The interface is mostly just for creating new document instances. + * + * This file is used to generate both glue code and documentation. + * The methods are in the same order as the .cpp/.h and the sections are labeled. + * + * Any change to method prototypes in application-interface.cpp MUST be reflected here. + * + * This file is the proverbial gold standard for the application interface. + * + * Authors: + * Soren Berg <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. +--> +<node name="/org/inkscape/application" + xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd" +> + <interface name="org.inkscape.application"> + + <!-- DESKTOP FUNCTIONS --> + <method name="desktop_new"> + <arg type="s" name="desktop_name" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>This string can be used to connect to the new interface that was created.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Create a new document interface and return its location. Only call this when Inkscape is running in GUI mode.</doc:para> + </doc:description> + </doc:doc> + </method> + <method name="get_desktop_list"> + <arg type="as" name="document_list" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>A list of interfaces being provided by Inkscape.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>List all the interfaces that it is possible to connect to. TODO: not implemented.</doc:para> + </doc:description> + </doc:doc> + </method> + <method name="desktop_close_all"> + <doc:doc> + <doc:description> + <doc:para>Close all document interfaces without saving. TODO: not implemented.</doc:para> + </doc:description> + </doc:doc> + </method> + <method name="exit"> + <doc:doc> + <doc:description> + <doc:para>Exit Inkscape without saving. Fairly straightforward.</doc:para> + </doc:description> + </doc:doc> + </method> + + <!-- DOCUMENT FUNCTIONS --> + <method name="document_new"> + <arg type="s" name="document_name" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>This string can be used to connect to the new interface that was created.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Originally, there were going to be two interfaces. A desktop and a document. Desktops would be used when the user wanted to see the result of their code and documents would be used when less overhead was desired. Unfortunately as more and more of the code can to rely on the desktop and it's associated support code (including selections and verbs) the document interface was looking more and more limited. Ultimately I decided to just go with the desktop interface since I didn't have a compelling reason for keeping the other one and having two similar interfaces could be very confusing. The desktop interface inherited the document name because I believe it's more familiar to people.</doc:para> + <doc:para>Perhaps it would be best to have an option as to whether or not to create a window and fail with a good error message when they call a function that requires one. Or have a second interface for different use cases but have it be completely different, rather than a subset of the first if there are use cases that support it.</doc:para> + <doc:para>UPDATE: 3rd July 2013, Eric Greveson: After having done some initial work to attempt to decouple Inkscape "verbs" from desktops, it is now possible to run a limited subset of actions in command-line mode (with a selection model and document, but no desktop). I believe that the "single document interface" approach, with some functions that may require a GUI, is the better path, and so document interfaces without a desktop are now possible. Most functions still require the desktop to work, though, with the notable exception of selection methods and Boolean operations.</doc:para> + <doc:para>As a result, this function should ONLY be called when using Inkscape in command-line mode. Use "desktop_new" instead if running in GUI mode.</doc:para> + </doc:description> + </doc:doc> + </method> + <method name="get_active_document"> + <arg type="s" name="document_name" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>This string can be used to connect to the current active document.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Get the location of the current active document (e.g. when running in console mode, when desktops are not available).</doc:para> + </doc:description> + </doc:doc> + </method> + </interface> +</node> diff --git a/src/extension/dbus/builddocs.sh b/src/extension/dbus/builddocs.sh new file mode 100644 index 0000000..dbe3d6e --- /dev/null +++ b/src/extension/dbus/builddocs.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +xsltproc doc/spec-to-docbook.xsl application-interface.xml > doc/org.inkscape.application.ref.xml && +xsltproc doc/spec-to-docbook.xsl document-interface.xml > doc/org.inkscape.document.ref.xml && +xsltproc doc/spec-to-docbook.xsl proposed-interface.xml > doc/org.inkscape.proposed.ref.xml && +xmlto --skip-validation xhtml-nochunks -o doc -m doc/config.xsl doc/inkscapeDbusRef.xml && +firefox doc/inkscapeDbusRef.html + diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp new file mode 100644 index 0000000..c83caac --- /dev/null +++ b/src/extension/dbus/dbus-init.cpp @@ -0,0 +1,235 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * This is where Inkscape connects to the DBus when it starts and + * registers the main interface. + * + * Also where new interfaces are registered when a new document is created. + * (Not called directly by application-interface but called indirectly.) + * + * Authors: + * Soren Berg <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include <dbus/dbus-glib.h> +// this is required so that giomm headers won't barf +#undef DBUS_MESSAGE_TYPE_INVALID +#include "dbus-init.h" + +#include "application-interface.h" +#include "application-server-glue.h" + +#include "document-interface.h" +#include "document-server-glue.h" + +#include "inkscape.h" +#include "document.h" +#include "desktop.h" +#include "file.h" +#include "verbs.h" +#include "helper/action.h" + +#include <algorithm> +#include <iostream> +#include <sstream> + + +namespace +{ + // This stores the bus name to use for this app instance. By default, it + // will be set to org.inkscape. However, users may provide other names by + // setting command-line parameters when starting Inkscape, so that more + // than one instance of Inkscape may be used by external scripts. + gchar *instance_bus_name = NULL; +} + +namespace Inkscape { +namespace Extension { +namespace Dbus { + +/* PRIVATE get a connection to the session bus */ +DBusGConnection * +dbus_get_connection() { + GError *error = NULL; + DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (error) { + fprintf(stderr, "Failed to get connection"); + return NULL; + } + else + return connection; +} + +/* PRIVATE create a proxy object for a bus.*/ +DBusGProxy * +dbus_get_proxy(DBusGConnection *connection) { + return dbus_g_proxy_new_for_name (connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); +} + +/* PRIVATE register an object on a bus */ +static gpointer +dbus_register_object (DBusGConnection *connection, + DBusGProxy *proxy, + GType object_type, + const DBusGObjectInfo *info, + const gchar *path) +{ + GObject *object = (GObject*)g_object_new (object_type, NULL); + dbus_g_object_type_install_info (object_type, info); + dbus_g_connection_register_g_object (connection, path, object); + return object; +} + +/* + * PRIVATE register a document interface for the document in the given ActionContext, if none exists. + * Return the DBus path to the interface (something like /org/inkscape/document_0). + * Note that while a DocumentInterface could be used either for a document with no desktop, or a + * document with a desktop, this function is only used for creating interfaces in the former case. + * Desktop-associated DocumentInterfaces are named /org/inkscape/desktop_0, etc. + * FIXME: This state of affairs probably needs tidying up at some point in the future. + */ +static gchar * +dbus_register_document(Inkscape::ActionContext const & target) +{ + SPDocument *doc = target.getDocument(); + g_assert(doc != NULL); + + // Document name is not suitable for DBus name, as it might contain invalid chars + std::string name("/org/inkscape/document_"); + std::stringstream ss; + ss << doc->serial(); + name.append(ss.str()); + + DBusGConnection *connection = dbus_get_connection(); + DBusGProxy *proxy = dbus_get_proxy(connection); + + // Has the document already been registered? + if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { + // No - register it + DocumentInterface *doc_interface = (DocumentInterface*) dbus_register_object (connection, + proxy, + TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, + name.c_str()); + + // Set the document info for this interface + doc_interface->target = target; + } + return strdup(name.c_str()); +} + +/* Initialize a Dbus service */ +void +init (void) +{ + if (instance_bus_name == NULL) { + // Set the bus name to the default + instance_bus_name = strdup("org.inkscape"); + } + + guint result; + GError *error = NULL; + DBusGConnection *connection; + DBusGProxy *proxy; + connection = dbus_get_connection(); + proxy = dbus_get_proxy(connection); + org_freedesktop_DBus_request_name (proxy, + instance_bus_name, + DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); + //create interface for application + dbus_register_object (connection, + proxy, + TYPE_APPLICATION_INTERFACE, + &dbus_glib_application_interface_object_info, + DBUS_APPLICATION_INTERFACE_PATH); +} + +gchar * +init_document (void) +{ + // This is for command-line use only + g_assert(!INKSCAPE.use_gui()); + + // Create a blank document and get its selection model etc in an ActionContext + SPDocument *doc = SPDocument::createNewDoc(NULL, 1, TRUE); + INKSCAPE.add_document(doc); + return dbus_register_document(INKSCAPE.action_context_for_document(doc)); +} + +gchar * +init_active_document() +{ + SPDocument *doc = INKSCAPE.active_document(); + if (!doc) { + return NULL; + } + + return dbus_register_document(INKSCAPE.active_action_context()); +} + +gchar * +dbus_init_desktop_interface (SPDesktop * dt) +{ + DBusGConnection *connection; + DBusGProxy *proxy; + + std::string name("/org/inkscape/desktop_"); + std::stringstream out; + out << dt->dkey; + name.append(out.str()); + + //printf("DKEY: %d\n, NUMBER %d\n NAME: %s\n", dt->dkey, dt->number, name.c_str()); + + connection = dbus_get_connection(); + proxy = dbus_get_proxy(connection); + + if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { + DocumentInterface *doc_interface = (DocumentInterface*) dbus_register_object (connection, + proxy, + TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, + name.c_str()); + + // Set the document info for this interface + doc_interface->target = Inkscape::ActionContext(dt); + doc_interface->updates = TRUE; + dt->dbus_document_interface=doc_interface; + } + return strdup(name.c_str()); +} + +gchar * +init_desktop (void) { + //this function will create a new desktop and call + //dbus_init_desktop_interface. + SPDesktop * dt = sp_file_new_default(); + + std::string name("/org/inkscape/desktop_"); + std::stringstream out; + out << dt->dkey; + name.append(out.str()); + return strdup(name.c_str()); +} + +void +dbus_set_bus_name(gchar const * bus_name) +{ + g_assert(bus_name != NULL); + g_assert(instance_bus_name == NULL); + instance_bus_name = strdup(bus_name); +} + +gchar * +dbus_get_bus_name() +{ + g_assert(instance_bus_name != NULL); + return instance_bus_name; +} + +} } } /* namespace Inkscape::Extension::Dbus */ diff --git a/src/extension/dbus/dbus-init.h b/src/extension/dbus/dbus-init.h new file mode 100644 index 0000000..54a2819 --- /dev/null +++ b/src/extension/dbus/dbus-init.h @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Authors: + * Soren Berg <glimmer07@gmail.com> + * + * Copyright (C) 2009 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_EXTENSION_DBUS_INIT_H__ +#define INKSCAPE_EXTENSION_DBUS_INIT_H__ + +class SPDesktop; + +namespace Inkscape { +namespace Extension { +namespace Dbus { + +/** \brief Dbus stuff. For registering objects on the bus. */ + +void init (void); + +gchar * init_document (void); + +gchar * init_active_document (); + +gchar * init_desktop (void); + +gchar * dbus_init_desktop_interface (SPDesktop * dt); + +/** Set the bus name to use. Default is "org.inkscape". + This function should only be called once, before init(), if a non-default + bus name is required. */ +void dbus_set_bus_name(gchar const * bus_name); + +/** Get the bus name for this instance. Default is "org.inkscape". + This function should only be called after init(). + The returned gchar * is owned by this module and should not be freed. */ +gchar * dbus_get_bus_name(); + +} } } /* namespace Dbus, Extension, Inkscape */ + +#endif /* INKSCAPE_EXTENSION_DBUS_INIT_H__ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/dbus/doc/config.xsl b/src/extension/dbus/doc/config.xsl new file mode 100644 index 0000000..09cf8de --- /dev/null +++ b/src/extension/dbus/doc/config.xsl @@ -0,0 +1,8 @@ +<?xml version='1.0'?> +<!-- SPDX-License-Identifier: GPL-2.0-or-later --> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format" + version="1.0"> + <xsl:param name="html.stylesheet" select="'docbook.css'"/> +</xsl:stylesheet> + diff --git a/src/extension/dbus/doc/dbus-introspect-docs.dtd b/src/extension/dbus/doc/dbus-introspect-docs.dtd new file mode 100644 index 0000000..3355d4d --- /dev/null +++ b/src/extension/dbus/doc/dbus-introspect-docs.dtd @@ -0,0 +1,34 @@ +<!-- DTD for D-Bus Introspection Documentation --> +<!-- SPDX-License-Identifier: GPL-2.0-or-later --> + +<!ELEMENT doc (summary?,description?,errors?,permission?,since?,deprecated,seealso?)> + +<!ELEMENT summary (#PCDATA|ref)*> +<!ELEMENT description (#PCDATA|para|example)*> +<!ELEMENT errors (error)*> +<!ELEMENT permission (#PCDATA|ref|para)*> +<!ELEMENT since EMPTY> +<!ATTLIST since version CDATA #REQUIRED> +<!ELEMENT deprecated (#PCDATA|ref)> +<!ATTLIST deprecated version CDATA #REQUIRED> +<!ATTLIST deprecated instead CDATA #REQUIRED> +<!ELEMENT seealso (ref+)> + +<!ELEMENT error (#PCDATA|para)*> +<!ATTLIST error name CDATA #REQUIRED> +<!ELEMENT para (#PCDATA|example|code|list|ref)*> +<!ELEMENT example (#PCDATA|para|code|ref)*> +<!ATTLIST language (c|glib|python|shell) #REQUIRED> +<!ATTLIST title CDATA #IMPLIED> +<!ELEMENT list (item*)> +<!ATTLIST list type (bullet|number) #REQUIRED> +<!ELEMENT item (term|definition)*> +<!ELEMENT term (#PCDATA|ref)*> +<!ELEMENT definition (#PCDATA|para)*> + +<!ELEMENT code (#PCDATA)> +<!ATTLIST code lang CDATA #IMPLIED> +<!ELEMENT ref CDATA> +<!ATTLIST ref type (parameter|arg|signal|method|interface) #REQUIRED> +<!ATTLIST ref to CDATA #REQUIRED> + diff --git a/src/extension/dbus/doc/docbook.css b/src/extension/dbus/doc/docbook.css new file mode 100644 index 0000000..0a1b7ee --- /dev/null +++ b/src/extension/dbus/doc/docbook.css @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +body +{ + font-family: sans-serif; +} +h1.title +{ +} +.permission +{ + color: #ee0000; + text-decoration: underline; +} +.synopsis, .classsynopsis +{ + background: #eeeeee; + border: solid 1px #aaaaaa; + padding: 0.5em; +} +.programlisting +{ + background: #eeeeff; + border: solid 1px #aaaaff; + padding: 0.5em; +} +.variablelist +{ + padding: 4px; + margin-left: 3em; +} +.variablelist td:first-child +{ + vertical-align: top; +} +td.shortcuts +{ + color: #770000; + font-size: 80%; +} +div.refnamediv +{ + margin-top: 2em; +} +div.toc +{ + border: 2em; +} +a +{ + text-decoration: none; +} +a:hover +{ + text-decoration: underline; + color: #FF0000; +} + +div.table table +{ + border-collapse: collapse; + border-spacing: 0px; + border-style: solid; + border-color: #777777; + border-width: 1px; +} + +div.table table td, div.table table th +{ + border-style: solid; + border-color: #777777; + border-width: 1px; + padding: 3px; + vertical-align: top; +} + +div.table table th +{ + background-color: #eeeeee; +} + diff --git a/src/extension/dbus/doc/inkscapeDbusRef.xml b/src/extension/dbus/doc/inkscapeDbusRef.xml new file mode 100644 index 0000000..6b5d578 --- /dev/null +++ b/src/extension/dbus/doc/inkscapeDbusRef.xml @@ -0,0 +1,81 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [ +<!ENTITY dbus-Application SYSTEM "org.inkscape.application.ref.xml"> +<!ENTITY dbus-Document SYSTEM "org.inkscape.document.ref.xml"> +<!ENTITY dbus-Proposed SYSTEM "org.inkscape.proposed.ref.xml"> +<!ENTITY Terms SYSTEM "inkscapeDbusTerms.xml"> + +]> + +<book id="index"> + <bookinfo> + <title>Inkscape Dbus Documentation</title> + <releaseinfo>Version 0.0</releaseinfo> + <date>7 July, 2009</date> + <authorgroup> + <author> + <firstname>Soren</firstname> + <surname>Berg</surname> + <affiliation> + <address> + <email>glimmer07@gmail.com</email> + </address> + </affiliation> + </author> + </authorgroup> + </bookinfo> + + <preface> + <title>Introduction</title> + <para> +This is the documentation for scripting Inkscape using Dbus. This framework was developed to let users quickly and easily write scripts to create or manipulate images in a variety of languages. Once the API has stabilized there will also be a C library that encapsulates the Dbus functionality. + </para> + <para> +The guiding principles behind the design of this API were: + </para> + <para> +<emphasis>Easy to use:</emphasis> Use of insider terms was limited where possible, and many functions have been simplified to provide a easy entry point for beginning users. Ideally one should not need any experience with Inkscape or even vector graphics to begin using the interface. At the same time, functions that can call arbitrary verbs or manipulate nodes and their attributes directly give knowledgeable users some flexibility. + </para> + <para> +<emphasis>Interactive:</emphasis> Since Dbus ties in with the main loop, users can mix scripting and mouse driven actions seamlessly. This allows for some unique uses but more importantly makes it easier for people to learn the API since they can play around with it in a scripting console, or even a simple python shell. + </para> + <para> +<emphasis>Responsive:</emphasis> Since one of the advantages of scripting is the ability to repeat actions many times with great precision it is obvious that the system would have to be fairly fast. The amount of overhead has been limited where possible and functions have been tested for speed. A system to pause updates and only refresh the display after a large number of operations have been completed, ensures that even very complicated renders will not take too long. + </para> + </preface> + + <part> + <title>Concepts</title> + + &Terms; + + </part> + + <part> + <title>Reference</title> + + <reference id="dbus-reference"> + <title>D-Bus API Reference</title> + + <partintro> + <para> + Inkscape provides a D-Bus API for programs to interactively script vector graphics. + </para> + <para> + This API is not yet stable and is likely to change in the future. + </para> + </partintro> + + &dbus-Application; + &dbus-Document; + &dbus-Proposed; + + </reference> + </part> + + <index> + <title>Index</title> + </index> + +</book> + diff --git a/src/extension/dbus/doc/inkscapeDbusTerms.xml b/src/extension/dbus/doc/inkscapeDbusTerms.xml new file mode 100644 index 0000000..45f2d63 --- /dev/null +++ b/src/extension/dbus/doc/inkscapeDbusTerms.xml @@ -0,0 +1,142 @@ +<chapter id="connecting"> + <title>Connecting to the API</title> + + <sect1> + <title>Overview</title> + <para> +There are really two Dbus interfaces provided by Inkscape. One is the application interface, which is constant, and allows one to control the Inkscape application as a whole and create new documents or windows. The second is the document interface. A document interface is automatically generated for every open window, and the commands sent to that interface will affect that particular window. + </para> + <para> +So the basic way of connecting goes like this: Connect to the session bus. Connect to the application interface. Request a new document. Connect to the newly created document interface using the name returned in the last step. Manipulate the document however you want (load files, create shapes, save, etc.) After the connection example there is a shortcut that will shorten this process somewhat in certain circumstances. + </para> + </sect1> + <sect1> + <title>Connection example</title> + <para> +Here is a basic example of connecting to the Bus and getting a new document. (In python for now because it's easy to read.) + </para> + <informalexample language="python" title="simple example"> + <programlisting> +import dbus + +#get the session bus. +bus = dbus.SessionBus() + +#get the object for the application. +inkapp = bus.get_object('org.inkscape', + '/org/inkscape/application') + +#request a new desktop. +desk2 = inkapp.desktop_new(dbus_interface='org.inkscape.application') + +#get the object for that desktop. +inkdoc1 = bus.get_object('org.inkscape', desk2) + +#tell it what interface it is using so we don't have to type it for every method. +doc1 = dbus.Interface(inkdoc1, dbus_interface="org.inkscape.document") + +#use! +doc1.rectangle (0,0,100,100) + </programlisting> + </informalexample> + </sect1> + + <sect1> + <title>Shortcut</title> + <para> +Here is a quicker way if you don't need multiple documents open at once. Since Inkscape starts automatically, and it always creates a blank document we can just connect to that. + </para> + <warning><para> +WARNING: This may not always work, it also might connect you to a document that is in use if Inkscape was already running. Only recommended for testing/experimenting. + </para></warning> + <informalexample language="python" title="simple example"> + <programlisting> +import dbus + +#get the session bus. +bus = dbus.SessionBus() + +#get object +inkdoc1 = bus.get_object('org.inkscape', '/org/inkscape/desktop_0') + +#get interface +doc1 = dbus.Interface(inkdoc1, dbus_interface="org.inkscape.document") + +#ta-da +doc1.rectangle (0,0,100,100) + </programlisting> + </informalexample> + </sect1> + +</chapter> + +<chapter id="terms"> + <title>Terminology</title> + + <anchor id="Coordinate System"/> + <sect1> + <title>Coordinate System</title> + <para> +The coordinate system used by this API may be different than what you are used to (although it is standard in the computer graphics industry.) Simply put the origin (0,0) is in the upper left hand corner of the document. X increases to the right and Y increases downwards. Therefore everything with positive coordinates is in the document. + </para> + <para> +For example: (100,100) would be just below and to the right of the top left corner of the document. + </para> + </sect1> + + <anchor id="Selections"/> + <sect1> + <title>Selections</title> + <para> +Selections are extremely useful ways of managing groups of objects and applying effects to all of them at once. Since much of Inkscapes core functionality is built around manipulating selections they are the key to much of this APIs utility. Manipulate the list of selected objects with <link linkend="document.selection_set">selection_set()</link>, <link linkend="document.selection_add">selection_add()</link>, and <link linkend="document.selection_box">selection_box()</link> and then call whatever selection function you need. + </para> + </sect1> + + <anchor id="Groups"/> + <sect1> + <title>Groups</title> + <para> +Groups are collections of objects that are treated as a single object. Groups have their own id and can be passed to any function that accepts an object, though some will not have any effect (groups ignore style for instance.) Groups can be transformed and occupy a single level in their layer. Objects within a group can still be modified using their ids, but this will not have any affect on the other group members. Functions like move_to may not work as expected if used on an object that is part of a group that has a transformation applied. + </para> + </sect1> + + <anchor id="Layers and Levels"/> + <sect1> + <title>Layers and Levels</title> + <para> +The basic idea is that things on top cover up things beneath them. The potentially confusing part is that Inkscape implements this in two ways: layers and levels. Levels are what order objects are in within a single layer. So the highest level object is still below all of the objects in the layer above it. <link linkend="document.layer_change_level">layer_change_level()</link> changes the order of layers and <link linkend="document.selection_change_level">selection_change_level()</link> changes the order of objects within a layer. + </para> + <para> +Changing the level of a selection also deserves some explanation. The <link linkend="document.selection_change_level">selection_change_level()</link> function can work in two ways. It can be absolute, "to_top" and "to_bottom" work like you'd expect, sending the entire selection to the top or bottom of that layer. But it can also be relative. "raise" and "lower" only work if there is another shape overlapping above or beneath the selection at the moment. Also if you have two objects selected and they are both occluded by a third, raising the selection once will only raise the first object in the selection above the third object. In other words selections don't move as a group. + </para> + </sect1> + + <anchor id="Style Strings"/> + <sect1> + <title>Style Strings</title> + <para> +Style strings look something like this: "fill:#ff0000;fill-opacity:1;stroke:#0000ff;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none". It is a string of key value pairs that determines the style of a particular object. Style strings affect most objects. They can be set all at once or specific key value pairs can be added one by one. Style strings can also be merged, with the new string replacing key/value pairs that it contains and leaving the rest as they were. One could also think of it as the new string taking any attributes it does not have and adopting them from the old string. + </para> + </sect1> + + <anchor id="Paths"/> + <sect1> + <title>Paths</title> + <para> +A path is a string representing a series of points, and how the line curves between the points. It looks something like this: "m 351.42857,296.64789 a 54.285713,87.14286 0 1 1 -108.57143,0 54.285713,87.14286 0 1 1 108.57143,0 z" and is usually found as an attribute of a shape with the label "d". All shapes except rectangles have this "d" attribute. + </para> + <para> +Just because a shape has a path does not mean it IS a path however. A path object has no attributes except the path and a style. Calling <link linkend="document.object_to_path">object_to_path()</link> will convert any object to a path, stripping away any other attributes except id and style which stay the same. This will not change the visual appearance but you will no longer be able to use shape handles or affect it by changing any attributes except for "style", "d", and "transform". Some functions may require paths. + </para> + </sect1> + + <anchor id="Nodes"/> + <sect1> + <title>Nodes</title> + <para> +To be written. + </para> + </sect1> + +</chapter> + diff --git a/src/extension/dbus/doc/spec-to-docbook.xsl b/src/extension/dbus/doc/spec-to-docbook.xsl new file mode 100644 index 0000000..5282167 --- /dev/null +++ b/src/extension/dbus/doc/spec-to-docbook.xsl @@ -0,0 +1,545 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +<?xml version='1.0'?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd" + exclude-result-prefixes="doc"> +<!-- + Convert D-Bus Glib xml into DocBook refentries + Copyright (C) 2007 William Jon McCann + Released under GNU GPL v2+, read the file 'COPYING' for more information. +--> +<xsl:output method="xml" indent="yes" encoding="UTF-8"/> + +<xsl:template match="/"> + +<xsl:variable name="interface" select="//interface/@name"/> +<xsl:variable name="basename"> + <xsl:call-template name="interface-basename"> + <xsl:with-param name="str" select="$interface"/> + </xsl:call-template> +</xsl:variable> + +<refentry><xsl:attribute name="id"><xsl:value-of select="$basename"/></xsl:attribute> + <refmeta> + <refentrytitle role="top_of_page"><xsl:value-of select="//interface/@name"/></refentrytitle> + </refmeta> + + <refnamediv> + <refname><xsl:value-of select="//interface/@name"/></refname> + <refpurpose><xsl:value-of select="$basename"/> interface</refpurpose> + </refnamediv> + + <refsynopsisdiv role="synopsis"> + <title role="synopsis.title">Methods</title> + <synopsis> + <xsl:call-template name="methods-synopsis"> + <xsl:with-param name="basename" select="$basename"/> + </xsl:call-template> + </synopsis> + </refsynopsisdiv> + + <xsl:choose> + <xsl:when test="count(///signal) > 0"> + <refsect1 role="signal_proto"> + <title role="signal_proto.title">Signals</title> + <synopsis> + <xsl:call-template name="signals-synopsis"> + <xsl:with-param name="basename" select="$basename"/> + </xsl:call-template> + </synopsis> + </refsect1> + </xsl:when> + </xsl:choose> + + <refsect1 role="impl_interfaces"> + <title role="impl_interfaces.title">Implemented Interfaces</title> + <para> + Objects implementing <xsl:value-of select="$interface"/> also implements + org.freedesktop.DBus.Introspectable, + org.freedesktop.DBus.Properties + </para> + </refsect1> + + <xsl:choose> + <xsl:when test="count(///property) > 0"> + <refsect1 role="properties"> + <title role="properties.title">Properties</title> + <synopsis> + <xsl:call-template name="properties-synopsis"> + <xsl:with-param name="basename" select="$basename"/> + </xsl:call-template> + </synopsis> + </refsect1> + </xsl:when> + </xsl:choose> + + <refsect1 role="desc"> + <title role="desc.title">Description</title> + <para> + <xsl:apply-templates select="//interface/doc:doc"/> + </para> + </refsect1> + + <refsect1 role="details"> + <title role="details.title">Details</title> + <xsl:call-template name="method-details"> + <xsl:with-param name="basename" select="$basename"/> + </xsl:call-template> + </refsect1> + + <xsl:choose> + <xsl:when test="count(///signal) > 0"> + <refsect1 role="signals"> + <title role="signals.title">Signal Details</title> + <xsl:call-template name="signal-details"> + <xsl:with-param name="basename" select="$basename"/> + </xsl:call-template> + </refsect1> + </xsl:when> + </xsl:choose> + + <xsl:choose> + <xsl:when test="count(///property) > 0"> + <refsect1 role="property_details"> + <title role="property_details.title">Property Details</title> + <xsl:call-template name="property-details"> + <xsl:with-param name="basename" select="$basename"/> + </xsl:call-template> + </refsect1> + </xsl:when> + </xsl:choose> + +</refentry> +</xsl:template> + + +<xsl:template name="property-doc"> + <xsl:apply-templates select="doc:doc/doc:description"/> + + <variablelist role="params"> + <xsl:for-each select="arg"> +<varlistentry><term><parameter><xsl:value-of select="@name"/></parameter>:</term> +<listitem><simpara><xsl:value-of select="doc:doc/doc:summary"/></simpara></listitem> +</varlistentry> + </xsl:for-each> + </variablelist> + + <xsl:apply-templates select="doc:doc/doc:since"/> + <xsl:apply-templates select="doc:doc/doc:deprecated"/> + <xsl:apply-templates select="doc:doc/doc:permission"/> + <xsl:apply-templates select="doc:doc/doc:seealso"/> +</xsl:template> + + +<xsl:template name="property-details"> + <xsl:param name="basename"/> + <xsl:variable name="longest"> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="@name"/> + </xsl:call-template> + </xsl:variable> + <xsl:for-each select="///property"> + <refsect2> + <title><anchor role="function"><xsl:attribute name="id"><xsl:value-of select="$basename"/>:<xsl:value-of select="@name"/></xsl:attribute></anchor>The "<xsl:value-of select="@name"/>" property</title> +<indexterm><primary><xsl:value-of select="@name"/></primary><secondary><xsl:value-of select="$basename"/></secondary></indexterm> +<programlisting>'<xsl:value-of select="@name"/>'<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="2"/></xsl:call-template> +<xsl:call-template name="property-args"><xsl:with-param name="indent" select="string-length(@name) + 2"/></xsl:call-template></programlisting> + </refsect2> + + <xsl:call-template name="property-doc"/> + + </xsl:for-each> +</xsl:template> + +<xsl:template name="signal-doc"> + <xsl:apply-templates select="doc:doc/doc:description"/> + + <variablelist role="params"> + <xsl:for-each select="arg"> +<varlistentry><term><parameter><xsl:value-of select="@name"/></parameter>:</term> +<listitem><simpara><xsl:value-of select="doc:doc/doc:summary"/></simpara></listitem> +</varlistentry> + </xsl:for-each> + </variablelist> + + <xsl:apply-templates select="doc:doc/doc:since"/> + <xsl:apply-templates select="doc:doc/doc:deprecated"/> + <xsl:apply-templates select="doc:doc/doc:permission"/> + <xsl:apply-templates select="doc:doc/doc:seealso"/> +</xsl:template> + +<xsl:template name="signal-details"> + <xsl:param name="basename"/> + <xsl:variable name="longest"> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="@name"/> + </xsl:call-template> + </xsl:variable> + <xsl:for-each select="///signal"> + <refsect2> + <title><anchor role="function"><xsl:attribute name="id"><xsl:value-of select="$basename"/>::<xsl:value-of select="@name"/></xsl:attribute></anchor>The <xsl:value-of select="@name"/> signal</title> +<indexterm><primary><xsl:value-of select="@name"/></primary><secondary><xsl:value-of select="$basename"/></secondary></indexterm> +<programlisting><xsl:value-of select="@name"/> (<xsl:call-template name="signal-args"><xsl:with-param name="indent" select="string-length(@name) + 2"/><xsl:with-param name="prefix" select="."/></xsl:call-template>)</programlisting> + </refsect2> + + <xsl:call-template name="signal-doc"/> + + </xsl:for-each> +</xsl:template> + +<xsl:template match="doc:code"> +<programlisting> +<xsl:apply-templates /> +</programlisting> +</xsl:template> + +<xsl:template match="doc:tt"> + <literal> + <xsl:apply-templates /> + </literal> +</xsl:template> + +<xsl:template match="doc:i"> + <emphasis> + <xsl:apply-templates /> + </emphasis> +</xsl:template> + +<xsl:template match="doc:b"> + <emphasis role="bold"> + <xsl:apply-templates /> + </emphasis> +</xsl:template> + +<xsl:template match="doc:ulink"> + <ulink> + <xsl:attribute name="url"><xsl:value-of select="@url"/></xsl:attribute> + <xsl:value-of select="."/> + </ulink> +</xsl:template> + +<xsl:template match="doc:summary"> + <xsl:apply-templates /> +</xsl:template> + +<xsl:template match="doc:example"> +<informalexample> +<xsl:apply-templates /> +</informalexample> +</xsl:template> + +<xsl:template name="listitems-do-term"> + <xsl:param name="str"/> + <xsl:choose> + <xsl:when test="string-length($str) > 0"> + <emphasis role="bold"><xsl:value-of select="$str"/>: </emphasis> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template name="do-listitems"> + <xsl:for-each select="doc:item"> + <listitem> + <xsl:call-template name="listitems-do-term"><xsl:with-param name="str" select="doc:term"/></xsl:call-template> + <xsl:apply-templates select="doc:definition"/> + </listitem> + </xsl:for-each> +</xsl:template> + +<xsl:template match="doc:list"> + <para> + <xsl:choose> + <xsl:when test="contains(@type,'number')"> + <orderedlist> + <xsl:call-template name="do-listitems"/> + </orderedlist> + </xsl:when> + <xsl:otherwise> + <itemizedlist> + <xsl:call-template name="do-listitems"/> + </itemizedlist> + </xsl:otherwise> + </xsl:choose> + </para> +</xsl:template> + +<xsl:template match="doc:para"> +<para> +<xsl:apply-templates /> +</para> +</xsl:template> + +<xsl:template match="doc:description"> +<xsl:apply-templates /> +</xsl:template> + +<xsl:template match="doc:since"> +<para role="since">Since <xsl:value-of select="@version"/> +</para> +</xsl:template> + +<xsl:template match="doc:deprecated"> + <xsl:variable name="name" select="../../@name"/> + <xsl:variable name="parent"> + <xsl:call-template name="interface-basename"> + <xsl:with-param name="str" select="../../../@name"/>/> + </xsl:call-template> + </xsl:variable> + + <xsl:variable name="type" select="name(../..)"/> + + <para role="deprecated"> + <warning><para><literal><xsl:value-of select="$name"/></literal> is deprecated since version <xsl:value-of select="@version"/> and should not be used in newly-written code. Use + + <xsl:variable name="to"> + <xsl:choose> + <xsl:when test="contains($type,'property')"> + <xsl:value-of select="$parent"/>:<xsl:value-of select="@instead"/> + </xsl:when> + <xsl:when test="contains($type,'signal')"> + <xsl:value-of select="$parent"/>::<xsl:value-of select="@instead"/> + </xsl:when> + <xsl:when test="contains($type,'method')"> + <xsl:value-of select="$parent"/>.<xsl:value-of select="@instead"/> + </xsl:when> + <xsl:when test="contains($type,'interface')"> + <xsl:value-of select="@instead"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="@instead"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + + <xsl:call-template name="create-link"> + <xsl:with-param name="type" select="$type"/> + <xsl:with-param name="to" select="$to"/> + <xsl:with-param name="val" select="@instead"/> + </xsl:call-template> +instead.</para></warning> +</para> +</xsl:template> + +<xsl:template match="doc:permission"> +<para role="permission"> +<xsl:apply-templates /> +</para> +</xsl:template> + +<xsl:template match="doc:errors"> +<para role="errors"> +<xsl:apply-templates /> +</para> +</xsl:template> + +<xsl:template match="doc:seealso"> +<para> +See also: +<xsl:apply-templates /> + +</para> +</xsl:template> + +<xsl:template name="create-link"> + <xsl:param name="type"/> + <xsl:param name="to"/> + <xsl:param name="val"/> + + <xsl:choose> + <xsl:when test="contains($type,'property')"> + <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><literal><xsl:value-of select="$val"/></literal></link> + </xsl:when> + <xsl:when test="contains($type,'signal')"> + <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><literal><xsl:value-of select="$val"/></literal></link> + </xsl:when> + <xsl:when test="contains($type,'method')"> + <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><function><xsl:value-of select="$val"/></function></link> + </xsl:when> + <xsl:when test="contains($type,'interface')"> + <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><xsl:value-of select="$val"/></link> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template match="doc:ref"> + <xsl:call-template name="create-link"> + <xsl:with-param name="type" select="@type"/> + <xsl:with-param name="to" select="@to"/> + <xsl:with-param name="val" select="."/> + </xsl:call-template> +</xsl:template> + +<xsl:template name="method-doc"> + <xsl:apply-templates select="doc:doc/doc:description"/> + + <variablelist role="params"> + <xsl:for-each select="arg"> +<varlistentry><term><parameter><xsl:value-of select="@name"/></parameter>:</term> +<listitem><simpara><xsl:apply-templates select="doc:doc/doc:summary"/></simpara></listitem> +</varlistentry> + </xsl:for-each> + </variablelist> + + <xsl:apply-templates select="doc:doc/doc:since"/> + <xsl:apply-templates select="doc:doc/doc:deprecated"/> + + <xsl:choose> + <xsl:when test="count(doc:doc/doc:errors) > 0"> + <refsect3> + <title>Errors</title> + <variablelist role="errors"> + <xsl:for-each select="doc:doc/doc:errors/doc:error"> + <varlistentry> + <term><parameter><xsl:value-of select="@name"/></parameter>:</term> + <listitem><simpara><xsl:apply-templates select="."/></simpara></listitem> + </varlistentry> + </xsl:for-each> + </variablelist> + </refsect3> + </xsl:when> + </xsl:choose> + + <xsl:choose> + <xsl:when test="count(doc:doc/doc:permission) > 0"> + <refsect3> + <title>Permissions</title> + <xsl:apply-templates select="doc:doc/doc:permission"/> + </refsect3> + </xsl:when> + </xsl:choose> + + <xsl:apply-templates select="doc:doc/doc:seealso"/> +</xsl:template> + +<xsl:template name="method-details"> + <xsl:param name="basename"/> + <xsl:variable name="longest"> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="@name"/> + </xsl:call-template> + </xsl:variable> + <xsl:for-each select="///method"> + <refsect2> + <title><anchor role="function"><xsl:attribute name="id"><xsl:value-of select="$basename"/>.<xsl:value-of select="@name"/></xsl:attribute></anchor><xsl:value-of select="@name"/> ()</title> +<indexterm><primary><xsl:value-of select="@name"/></primary><secondary><xsl:value-of select="$basename"/></secondary></indexterm> +<programlisting><xsl:value-of select="@name"/> (<xsl:call-template name="method-args"><xsl:with-param name="indent" select="string-length(@name) + 2"/><xsl:with-param name="prefix" select="."/></xsl:call-template>)</programlisting> + </refsect2> + + <xsl:call-template name="method-doc"/> + + </xsl:for-each> +</xsl:template> + + +<xsl:template name="properties-synopsis"> + <xsl:param name="basename"/> + <xsl:variable name="longest"> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="///property/@name"/> + </xsl:call-template> + </xsl:variable> + <xsl:for-each select="///property"> +<link><xsl:attribute name="linkend"><xsl:value-of select="$basename"/>:<xsl:value-of select="@name"/></xsl:attribute>'<xsl:value-of select="@name"/>'</link><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@name) + 1"/></xsl:call-template> <xsl:call-template name="property-args"><xsl:with-param name="indent" select="$longest + 2"/></xsl:call-template> +</xsl:for-each> +</xsl:template> + + +<xsl:template name="signals-synopsis"> + <xsl:param name="basename"/> + <xsl:variable name="longest"> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="///signal/@name"/> + </xsl:call-template> + </xsl:variable> + <xsl:for-each select="///signal"> +<link><xsl:attribute name="linkend"><xsl:value-of select="$basename"/>::<xsl:value-of select="@name"/></xsl:attribute><xsl:value-of select="@name"/></link><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@name) + 1"/></xsl:call-template>(<xsl:call-template name="signal-args"><xsl:with-param name="indent" select="$longest + 2"/><xsl:with-param name="prefix" select="///signal"/></xsl:call-template>) +</xsl:for-each> +</xsl:template> + + +<xsl:template name="methods-synopsis"> + <xsl:param name="basename"/> + <xsl:variable name="longest"> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="///method/@name"/> + </xsl:call-template> + </xsl:variable> + <xsl:for-each select="///method"> +<link><xsl:attribute name="linkend"><xsl:value-of select="$basename"/>.<xsl:value-of select="@name"/></xsl:attribute><xsl:value-of select="@name"/></link><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@name) + 1"/></xsl:call-template>(<xsl:call-template name="method-args"><xsl:with-param name="indent" select="$longest + 2"/><xsl:with-param name="prefix" select="///method"/></xsl:call-template>) +</xsl:for-each> +</xsl:template> + + +<xsl:template name="method-args"><xsl:param name="indent"/><xsl:param name="prefix"/><xsl:variable name="longest"><xsl:call-template name="find-longest"><xsl:with-param name="set" select="$prefix/arg/@type"/></xsl:call-template></xsl:variable><xsl:for-each select="arg"><xsl:value-of select="@direction"/> +<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="4 - string-length(@direction)"/></xsl:call-template>'<xsl:value-of select="@type"/>'<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@type) + 1"/></xsl:call-template> +<xsl:value-of select="@name"/><xsl:if test="not(position() = last())">, +<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$indent"/></xsl:call-template></xsl:if> +</xsl:for-each> +</xsl:template> + + +<xsl:template name="signal-args"><xsl:param name="indent"/><xsl:param name="prefix"/><xsl:variable name="longest"><xsl:call-template name="find-longest"><xsl:with-param name="set" select="$prefix/arg/@type"/></xsl:call-template></xsl:variable><xsl:for-each select="arg">'<xsl:value-of select="@type"/>'<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@type) + 1"/></xsl:call-template> +<xsl:value-of select="@name"/><xsl:if test="not(position() = last())">, +<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$indent"/></xsl:call-template></xsl:if> +</xsl:for-each> +</xsl:template> + + +<xsl:template name="property-args"><xsl:param name="indent"/> +<xsl:value-of select="@access"/><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="9 - string-length(@access) + 1"/></xsl:call-template>'<xsl:value-of select="@type"/>' +</xsl:template> + + +<xsl:template name="pad-spaces"> + <xsl:param name="width"/> + <xsl:variable name="spaces" select="' '" ></xsl:variable> + <xsl:value-of select="substring($spaces,1,$width)"/> +</xsl:template> + + +<xsl:template name="find-longest"> + <xsl:param name="set"/> + <xsl:param name="index" select="1"/> + <xsl:param name="longest" select="0"/> + + <xsl:choose> + <xsl:when test="$index > count($set)"> + <!--finished looking--> + <xsl:value-of select="$longest"/> + </xsl:when> + <xsl:when test="string-length($set[$index])>$longest"> + <!--found new longest--> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="$set"/> + <xsl:with-param name="index" select="$index + 1"/> + <xsl:with-param name="longest" select="string-length($set[$index])"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <!--this isn't any longer--> + <xsl:call-template name="find-longest"> + <xsl:with-param name="set" select="$set"/> + <xsl:with-param name="index" select="$index + 1"/> + <xsl:with-param name="longest" select="$longest"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + + +<xsl:template name="interface-basename"> + <xsl:param name="str"/> + <xsl:choose> + <xsl:when test="contains($str,'.')"> + <xsl:call-template name="interface-basename"> + <xsl:with-param name="str" select="substring-after($str,'.')"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$str"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet> + diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp new file mode 100644 index 0000000..2384c50 --- /dev/null +++ b/src/extension/dbus/document-interface.cpp @@ -0,0 +1,1484 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * 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 remotely 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 <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include <glib.h> +#include <string.h> + +#include <dbus/dbus-glib.h> + +//#include "2geom/svg-path-parser.h" //get_node_coordinates +#include "inkscape-application.h" // create_window() + +#include "application-interface.h" +#include "desktop-style.h" //sp_desktop_get_style +#include "desktop.h" +#include "document-interface.h" +#include "document-undo.h" +#include "document.h" // getReprDoc() +#include "file.h" //IO +#include "inkscape.h" //inkscape_find_desktop_by_dkey, activate desktops +#include "layer-fns.h" //LPOS_BELOW +#include "layer-model.h" +#include "print.h" //IO +#include "selection-chemistry.h"// lots of selection functions +#include "selection.h" //selection struct +#include "style.h" //style_write +#include "text-editing.h" +#include "verbs.h" + +#include "helper/action-context.h" +#include "helper/action.h" //sp_action_perform + +#include "display/canvas-text.h" //text +#include "display/sp-canvas.h" //text + +#include "extension/output.h" //IO +#include "extension/system.h" //IO + +#include "live_effects/parameter/text.h" //text + +#include "object/sp-ellipse.h" +#include "object/sp-object.h" +#include "object/sp-root.h" + +#include "util/units.h" + +#include "xml/repr.h" //sp_repr_document_new + +#if 0 +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> +#endif + + enum + { + OBJECT_MOVED_SIGNAL, + LAST_SIGNAL + }; + + static guint signals[LAST_SIGNAL] = { 0 }; + + +/**************************************************************************** + HELPER / SHORTCUT FUNCTIONS +****************************************************************************/ + +/* + * 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 (SPDocument *doc, gchar *name, GError **error) +{ + /* ALTERNATIVE (is this faster if only repr is needed?) + Inkscape::XML::Node *node = sp_repr_lookup_name((doc->root)->repr, name); + */ + SPObject * obj = doc->getObjectById(name); + if (!obj) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name); + return NULL; + } + return obj->getRepr(); +} + +/* + * See comment for get_repr_by_name, above. + */ +SPObject * +get_object_by_name (SPDocument *doc, gchar *name, GError **error) +{ + SPObject * obj = doc->getObjectById(name); + if (!obj) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name); + return NULL; + } + 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 separately) should call this. + */ +gboolean +dbus_check_string (gchar *string, GError ** error, const gchar * errorstr) +{ + if (string == NULL) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "%s", errorstr); + return FALSE; + } + return TRUE; +} + +/* + * This is used to return object values to the user + */ +const gchar * +get_name_from_object (SPObject * obj) +{ + return obj->getRepr()->attribute("id"); +} + +/* + * Some verbs (cut, paste) only work on the active layer. + * This makes sure that the document that is about to receive a command is active. + */ +void +desktop_ensure_active (SPDesktop* desk) { + if (desk != SP_ACTIVE_DESKTOP) + INKSCAPE.activate_desktop (desk); + return; +} + +gdouble +selection_get_center_x (Inkscape::Selection *sel){ + Geom::OptRect box = sel->documentBounds(SPItem::GEOMETRIC_BBOX); + return box ? box->midpoint()[Geom::X] : 0; +} + +gdouble +selection_get_center_y (Inkscape::Selection *sel){ + Geom::OptRect box = sel->documentBounds(SPItem::GEOMETRIC_BBOX); + return box ? box->midpoint()[Geom::Y] : 0; +} + +/* + * 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 separately. Although + * they might see the selection box flicker if used in a loop. + */ +std::vector<SPObject*> +selection_swap(Inkscape::Selection *sel, gchar *name, GError **error) +{ + std::vector<SPObject*> oldsel = std::vector<SPObject*>(sel->objects().begin(), sel->objects().end()); + + sel->set(get_object_by_name(sel->layers()->getDocument(), name, error)); + return oldsel; +} + +/* + * See selection_swap, above + */ +void +selection_restore(Inkscape::Selection *sel, std::vector<SPObject*> oldsel) +{ + // ... setList used to work here + sel->clear(); + sel->add(oldsel.begin(), oldsel.end()); +} + +/* + * Shortcut for creating a Node. + */ +Inkscape::XML::Node * +dbus_create_node (SPDocument *doc, const gchar *type) +{ + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + + 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 *doc_interface, GError ** /*error*/, Inkscape::XML::Node *newNode, gchar *desc) +{ + SPCSSAttr *style = NULL; + if (doc_interface->target.getDesktop()) { + style = sp_desktop_get_style(doc_interface->target.getDesktop(), TRUE); + } + if (style) { + Glib::ustring str; + sp_repr_css_write_string(style, str); + newNode->setAttributeOrRemoveIfEmpty("style", str); + } + else { + newNode->setAttribute("style", "fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none", true); + } + + doc_interface->target.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + doc_interface->target.getSelection()->layers()->currentLayer()->updateRepr(); + + if (doc_interface->updates) { + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), 0, (gchar *)desc); + } + + 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 *doc_interface, int verbid, GError **error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + if ( desk ) { + desktop_ensure_active (desk); + } + Inkscape::Verb *verb = Inkscape::Verb::get( verbid ); + if ( verb ) { + SPAction *action = verb->get_action(doc_interface->target); + if ( action ) { + sp_action_perform( action, NULL ); + if (doc_interface->updates) + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), verb->get_code(), verb->get_tip()); + return TRUE; + } + } + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb failed to execute"); + return FALSE; +} + +/* + * Check that the desktop is not NULL. If it is NULL, set the error to a useful message. + */ +bool +ensure_desktop_valid(SPDesktop* desk, GError **error) +{ + if (desk) { + return true; + } + + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Document interface action requires a GUI"); + return false; +} + +/**************************************************************************** + DOCUMENT INTERFACE CLASS STUFF +****************************************************************************/ + +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; + signals[OBJECT_MOVED_SIGNAL] = + g_signal_new ("object_moved", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); +} + +static void +document_interface_init (DocumentInterface *doc_interface) +{ + doc_interface->target = Inkscape::ActionContext(); +} + + +DocumentInterface * +document_interface_new (void) +{ + return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL); +} + + + +/**************************************************************************** + MISC FUNCTIONS +****************************************************************************/ + +gboolean document_interface_delete_all(DocumentInterface *doc_interface, GError ** /*error*/) +{ + sp_edit_clear_all(doc_interface->target.getSelection()); + return TRUE; +} + +gboolean +document_interface_call_verb (DocumentInterface *doc_interface, gchar *verbid, GError **error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + if ( desk ) { + desktop_ensure_active (desk); + } + Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid ); + if ( verb ) { + SPAction *action = verb->get_action(doc_interface->target); + if ( action ) { + sp_action_perform( action, NULL ); + if (doc_interface->updates) { + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), verb->get_code(), verb->get_tip()); + } + return TRUE; + } + } + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb '%s' failed to execute or was not found.", verbid); + return FALSE; +} + + +/**************************************************************************** + CREATION FUNCTIONS +****************************************************************************/ + +gchar* +document_interface_rectangle (DocumentInterface *doc_interface, int x, int y, + int width, int height, GError **error) +{ + + + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:rect"); + sp_repr_set_int(newNode, "x", x); //could also use newNode->setAttribute() + sp_repr_set_int(newNode, "y", y); + sp_repr_set_int(newNode, "width", width); + sp_repr_set_int(newNode, "height", height); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create rectangle"); +} + +gchar* +document_interface_ellipse_center (DocumentInterface *doc_interface, int cx, int cy, + int rx, int ry, GError **error) +{ + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); + newNode->setAttribute("sodipodi:type", "arc"); + sp_repr_set_int(newNode, "sodipodi:cx", cx); + sp_repr_set_int(newNode, "sodipodi:cy", cy); + sp_repr_set_int(newNode, "sodipodi:rx", rx); + sp_repr_set_int(newNode, "sodipodi:ry", ry); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create circle"); +} + +gchar* +document_interface_polygon (DocumentInterface *doc_interface, int cx, int cy, + int radius, int rotation, int sides, + GError **error) +{ + gdouble rot = ((rotation / 180.0) * M_PI) - M_PI_2; + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); + newNode->setAttribute("inkscape:flatsided", "true"); + newNode->setAttribute("sodipodi:type", "star"); + sp_repr_set_int(newNode, "sodipodi:cx", cx); + 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 (doc_interface, error, newNode, (gchar *)"create polygon"); +} + +gchar* +document_interface_star (DocumentInterface *doc_interface, int cx, int cy, + int r1, int r2, int sides, gdouble rounded, + gdouble arg1, gdouble arg2, GError **error) +{ + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); + 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 (doc_interface, error, newNode, (gchar *)"create star"); +} + +gchar* +document_interface_ellipse (DocumentInterface *doc_interface, int x, int y, + int width, int height, GError **error) +{ + int rx = width/2; + int ry = height/2; + return document_interface_ellipse_center (doc_interface, x+rx, y+ry, rx, ry, error); +} + +gchar* +document_interface_line (DocumentInterface *doc_interface, int x, int y, + int x2, int y2, GError **error) +{ + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); + std::stringstream out; + // Not sure why this works. + out << "m " << x << "," << y << " " << x2 - x << "," << y2 - y; + newNode->setAttribute("d", out.str()); + return finish_create_shape (doc_interface, error, newNode, (gchar *)"create line"); +} + +gchar* +document_interface_spiral (DocumentInterface *doc_interface, int cx, int cy, + int r, int revolutions, GError **error) +{ + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:path"); + newNode->setAttribute("sodipodi:type", "spiral"); + sp_repr_set_int(newNode, "sodipodi:cx", cx); + sp_repr_set_int(newNode, "sodipodi:cy", cy); + 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 (doc_interface, error, newNode, (gchar *)"create spiral"); + //Makes sure there is no fill for spirals by default. + gchar* newString = g_strconcat(newNode->attribute("style"), ";fill:none", NULL); + newNode->setAttribute("style", newString); + g_free(newString); + return retval; +} + +gchar* +document_interface_text (DocumentInterface *doc_interface, int x, int y, gchar *text, GError **error) +{ + + Inkscape::XML::Node *text_node = dbus_create_node(doc_interface->target.getDocument(), "svg:text"); + sp_repr_set_int(text_node, "x", x); + sp_repr_set_int(text_node, "y", y); + //just a workaround so i can get an spitem from the name + gchar *name = finish_create_shape (doc_interface, error, text_node, (gchar *)"create text"); + + SPItem* text_obj=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + sp_te_set_repr_text_multiline(text_obj, text); + + return name; +} + +gchar * +document_interface_image (DocumentInterface *doc_interface, int x, int y, gchar *filename, GError **error) +{ + gchar * uri = g_filename_to_uri (filename, FALSE, error); + if (!uri) + return FALSE; + + Inkscape::XML::Node *newNode = dbus_create_node(doc_interface->target.getDocument(), "svg:image"); + sp_repr_set_int(newNode, "x", x); + sp_repr_set_int(newNode, "y", y); + newNode->setAttribute("xlink:href", uri); + + doc_interface->target.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + doc_interface->target.getSelection()->layers()->currentLayer()->updateRepr(); + + if (doc_interface->updates) + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), 0, "Imported bitmap."); + + //g_free(uri); + return strdup(newNode->attribute("id")); +} + +gchar *document_interface_node(DocumentInterface *doc_interface, gchar *type, GError ** /*error*/) +{ + SPDocument * doc = doc_interface->target.getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + + Inkscape::XML::Node *newNode = xml_doc->createElement(type); + + doc_interface->target.getSelection()->layers()->currentLayer()->appendChildRepr(newNode); + doc_interface->target.getSelection()->layers()->currentLayer()->updateRepr(); + + if (doc_interface->updates) { + Inkscape::DocumentUndo::done(doc, 0, (gchar *)"created empty node"); + } + + return strdup(newNode->attribute("id")); +} + +/**************************************************************************** + ENVIRONMENT FUNCTIONS +****************************************************************************/ +gdouble +document_interface_document_get_width (DocumentInterface *doc_interface) +{ + return doc_interface->target.getDocument()->getWidth().value("px"); +} + +gdouble +document_interface_document_get_height (DocumentInterface *doc_interface) +{ + return doc_interface->target.getDocument()->getHeight().value("px"); +} + +gchar *document_interface_document_get_css(DocumentInterface *doc_interface, GError ** error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), NULL); + SPCSSAttr *current = desk->current; + Glib::ustring str; + sp_repr_css_write_string(current, str); + return (str.empty() ? NULL : g_strdup (str.c_str())); +} + +gboolean document_interface_document_merge_css(DocumentInterface *doc_interface, + gchar *stylestring, GError ** error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); + SPCSSAttr * style = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(style, stylestring); + sp_desktop_set_style(desk, style); + return TRUE; +} + +gboolean document_interface_document_set_css(DocumentInterface *doc_interface, + gchar *stylestring, GError ** error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); + SPCSSAttr * style = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string (style, stylestring); + //Memory leak? + desk->current = style; + return TRUE; +} + +gboolean +document_interface_document_resize_to_fit_selection (DocumentInterface *doc_interface, + GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_FIT_CANVAS_TO_SELECTION, error); +} + +gboolean +document_interface_document_set_display_area (DocumentInterface *doc_interface, + double x0, + double y0, + double x1, + double y1, + double border, + GError **error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); + desk->set_display_area (Geom::Rect( Geom::Point(x0,y0), Geom::Point(x1,y1)), border, false ); + return TRUE; +} + + +GArray * +document_interface_document_get_display_area (DocumentInterface *doc_interface) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + if (!desk) { + return NULL; + } + Geom::Rect const d = desk->get_display_area(); + + GArray * dArr = g_array_new (TRUE, TRUE, sizeof(double)); + + double x0 = d.min()[Geom::X]; + double y0 = d.min()[Geom::Y]; + double x1 = d.max()[Geom::X]; + double y1 = d.max()[Geom::Y]; + g_array_append_val (dArr, x0); // + g_array_append_val (dArr, y0); + g_array_append_val (dArr, x1); + g_array_append_val (dArr, y1); + return dArr; + +} + + +/**************************************************************************** + OBJECT FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_set_attribute (DocumentInterface *doc_interface, char *shape, + char *attribute, char *newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_repr_by_name(doc_interface->target.getDocument(), shape, error); + + /* ALTERNATIVE (is this faster?) + Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); + */ + if (!dbus_check_string(newval, error, "New value string was empty.")) + return FALSE; + + if (!newNode) + return FALSE; + + newNode->setAttribute(attribute, newval, true); + return TRUE; +} + +gboolean +document_interface_set_int_attribute (DocumentInterface *doc_interface, + char *shape, char *attribute, + int newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_repr_by_name (doc_interface->target.getDocument(), shape, error); + if (!newNode) + return FALSE; + + sp_repr_set_int (newNode, attribute, newval); + return TRUE; +} + + +gboolean +document_interface_set_double_attribute (DocumentInterface *doc_interface, + char *shape, char *attribute, + double newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_repr_by_name (doc_interface->target.getDocument(), shape, error); + + if (!dbus_check_string (attribute, error, "New value string was empty.")) + return FALSE; + if (!newNode) + return FALSE; + + sp_repr_set_svg_double (newNode, attribute, newval); + return TRUE; +} + +gchar * +document_interface_get_attribute (DocumentInterface *doc_interface, char *shape, + char *attribute, GError **error) +{ + Inkscape::XML::Node *newNode = get_repr_by_name(doc_interface->target.getDocument(), shape, error); + + if (!dbus_check_string (attribute, error, "Attribute name empty.")) + return NULL; + if (!newNode) + return NULL; + + return g_strdup(newNode->attribute(attribute)); +} + +gboolean +document_interface_move (DocumentInterface *doc_interface, gchar *name, gdouble x, + gdouble y, GError **error) +{ + std::vector<SPObject*> oldsel = selection_swap(doc_interface->target.getSelection(), name, error); + if (oldsel.empty()) + return FALSE; + doc_interface->target.getSelection()->move(x, 0 - y); + selection_restore(doc_interface->target.getSelection(), oldsel); + return TRUE; +} + +gboolean +document_interface_move_to (DocumentInterface *doc_interface, gchar *name, gdouble x, + gdouble y, GError **error) +{ + std::vector<SPObject*> oldsel = selection_swap(doc_interface->target.getSelection(), name, error); + if (oldsel.empty()) + return FALSE; + Inkscape::Selection * sel = doc_interface->target.getSelection(); + doc_interface->target.getSelection()->move(x - selection_get_center_x(sel), + 0 - (y - selection_get_center_y(sel))); + selection_restore(doc_interface->target.getSelection(), oldsel); + return TRUE; +} + +gboolean +document_interface_object_to_path (DocumentInterface *doc_interface, + char *shape, GError **error) +{ + std::vector<SPObject*> oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); + if (oldsel.empty()) + return FALSE; + dbus_call_verb (doc_interface, SP_VERB_OBJECT_TO_CURVE, error); + selection_restore(doc_interface->target.getSelection(), oldsel); + return TRUE; +} + +gchar * +document_interface_get_path (DocumentInterface *doc_interface, char *pathname, GError **error) +{ + Inkscape::XML::Node *node = get_repr_by_name(doc_interface->target.getDocument(), 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")); +} + +gboolean +document_interface_transform (DocumentInterface *doc_interface, gchar *shape, + gchar *transformstr, GError **error) +{ + //FIXME: This should merge transformations. + gchar trans[] = "transform"; + document_interface_set_attribute (doc_interface, shape, trans, transformstr, error); + return TRUE; +} + +gchar * +document_interface_get_css (DocumentInterface *doc_interface, gchar *shape, + GError **error) +{ + gchar style[] = "style"; + return document_interface_get_attribute (doc_interface, shape, style, error); +} + +gboolean +document_interface_modify_css (DocumentInterface *doc_interface, gchar *shape, + gchar *cssattrb, gchar *newval, GError **error) +{ + // Doesn't like non-variable strings for some reason. + gchar style[] = "style"; + Inkscape::XML::Node *node = get_repr_by_name(doc_interface->target.getDocument(), 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); + Glib::ustring str; + sp_repr_css_write_string (oldstyle, str); + node->setAttributeOrRemoveIfEmpty (style, str); + return TRUE; +} + +gboolean +document_interface_merge_css (DocumentInterface *doc_interface, gchar *shape, + gchar *stylestring, GError **error) +{ + gchar style[] = "style"; + + Inkscape::XML::Node *node = get_repr_by_name(doc_interface->target.getDocument(), shape, error); + + if (!dbus_check_string (stylestring, error, "Style string empty.")) + return FALSE; + if (!node) + return FALSE; + + SPCSSAttr * newstyle = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string (newstyle, stylestring); + + SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); + + sp_repr_css_merge(oldstyle, newstyle); + Glib::ustring str; + sp_repr_css_write_string (oldstyle, str); + node->setAttributeOrRemoveIfEmpty (style, str); + + return TRUE; +} + +gboolean +document_interface_set_color (DocumentInterface *doc_interface, 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 (doc_interface, style, error); + + return document_interface_merge_css (doc_interface, shape, style, error); +} + +gboolean +document_interface_move_to_layer (DocumentInterface *doc_interface, gchar *shape, + gchar *layerstr, GError **error) +{ + std::vector<SPObject*> oldsel = selection_swap(doc_interface->target.getSelection(), shape, error); + if (oldsel.empty()) + return FALSE; + + document_interface_selection_move_to_layer(doc_interface, layerstr, error); + selection_restore(doc_interface->target.getSelection(), oldsel); + return TRUE; +} + +GArray *document_interface_get_node_coordinates(DocumentInterface * /*doc_interface*/, gchar * /*shape*/) +{ + //FIXME: Needs lot's of work. +/* + Inkscape::XML::Node *shapenode = get_repr_by_name (doc_interface->target.getDocument(), shape, error); + if (shapenode == NULL || shapenode->attribute("d") == NULL) { + return FALSE; + } + char * path = strdup(shapenode->attribute("d")); + printf("PATH: %s\n", path); + + Geom::parse_svg_path (path); + return NULL; + */ + return NULL; +} + + +gboolean +document_interface_set_text (DocumentInterface *doc_interface, gchar *name, gchar *text, GError **error) +{ + + SPItem* text_obj=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + //TODO verify object type + if (!text_obj) + return FALSE; + sp_te_set_repr_text_multiline(text_obj, text); + return TRUE; + +} + + + +gboolean +document_interface_text_apply_style (DocumentInterface *doc_interface, gchar *name, + int start_pos, int end_pos, gchar *style, gchar *styleval, + GError **error) +{ + + SPItem* text_obj=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + + //void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPCSSAttr const *css) + //TODO verify object type + if (!text_obj) + return FALSE; + Inkscape::Text::Layout const *layout = te_get_layout(text_obj); + Inkscape::Text::Layout::iterator start = layout->charIndexToIterator (start_pos); + Inkscape::Text::Layout::iterator end = layout->charIndexToIterator (end_pos); + + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property(css, style, styleval); + + sp_te_apply_style(text_obj, + start, + end, + css); + return TRUE; + +} + + +/**************************************************************************** + FILE I/O FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_save (DocumentInterface *doc_interface, GError **error) +{ + SPDocument * doc = doc_interface->target.getDocument(); + printf("1: %s\n2: %s\n3: %s\n", doc->getDocumentURI(), doc->getDocumentBase(), doc->getDocumentName()); + if (doc->getDocumentURI()) + return document_interface_save_as (doc_interface, doc->getDocumentURI(), error); + return FALSE; +} + +gboolean document_interface_load(DocumentInterface *doc_interface, + gchar *filename, GError ** /*error*/) +{ + if (!filename) { + return false; + } + + SPDesktop *desk = doc_interface->target.getDesktop(); + if (desk) { + desktop_ensure_active(desk); + } + + Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(filename); + + ConcreteInkscapeApplication<Gtk::Application>* app = &(ConcreteInkscapeApplication<Gtk::Application>::get_instance()); + + app->create_window(file); + + if (doc_interface->updates) { + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), SP_VERB_FILE_OPEN, "Opened File"); + } + return TRUE; +} + +gchar * +document_interface_import (DocumentInterface *doc_interface, + gchar *filename, GError **error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + if (desk) { + desktop_ensure_active(desk); + } + const Glib::ustring file(filename); + SPDocument * doc = doc_interface->target.getDocument(); + + SPObject *new_obj = NULL; + new_obj = file_import(doc, file, NULL); + return strdup(new_obj->getRepr()->attribute("id")); +} + +gboolean +document_interface_save_as (DocumentInterface *doc_interface, + const gchar *filename, GError **error) +{ + // FIXME: Isn't there a verb we can use for this instead? + SPDocument * doc = doc_interface->target.getDocument(); + + if (!doc || strlen(filename)<1) { //Safety check + return false; + } + + try { + Inkscape::Extension::save(NULL, doc, filename, + false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); + } catch (...) { + // FIXME: catch ... is not usually a great idea, why is it needed here? + return false; + } + + return true; +} + +gboolean document_interface_mark_as_unmodified(DocumentInterface *doc_interface, GError ** /*error*/) +{ + SPDocument * doc = doc_interface->target.getDocument(); + if (doc) { + doc->setModifiedSinceSave(FALSE); + } + return TRUE; +} + +/* +gboolean +document_interface_print_to_file (DocumentInterface *doc_interface, GError **error) +{ + SPDocument * doc = doc_interface->target.getDocument(); + sp_print_document_to_file (doc, g_strdup("/home/soren/test.pdf")); + + return TRUE; +} +*/ +/**************************************************************************** + PROGRAM CONTROL FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_close (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_FILE_CLOSE_VIEW, error); +} + +gboolean +document_interface_exit (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_FILE_QUIT, error); +} + +gboolean +document_interface_undo (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_EDIT_UNDO, error); +} + +gboolean +document_interface_redo (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_EDIT_REDO, error); +} + + + +/**************************************************************************** + 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 document_interface_pause_updates(DocumentInterface *doc_interface, GError ** error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); + doc_interface->updates = FALSE; + desk->canvas->_drawing_disabled = 1; +} + +void document_interface_resume_updates(DocumentInterface *doc_interface, GError ** error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); + doc_interface->updates = TRUE; + desk->canvas->_drawing_disabled = 0; + //FIXME: use better verb than rect. + Inkscape::DocumentUndo::done(doc_interface->target.getDocument(), SP_VERB_CONTEXT_RECT, "Multiple actions"); +} + +void document_interface_update(DocumentInterface *doc_interface, GError ** error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_if_fail(ensure_desktop_valid(desk, error)); + SPDocument *doc = doc_interface->target.getDocument(); + doc->getRoot()->uflags = TRUE; + doc->getRoot()->mflags = TRUE; + desk->enableInteraction(); + doc->ensureUpToDate(); + desk->disableInteraction(); + doc->getRoot()->uflags = FALSE; + doc->getRoot()->mflags = FALSE; + //Inkscape::DocumentUndo::done(doc, SP_VERB_CONTEXT_RECT, "Multiple actions"); +} + +/**************************************************************************** + SELECTION FUNCTIONS FIXME: use call_verb where appropriate (once update system is tested.) +****************************************************************************/ + +gboolean document_interface_selection_get(DocumentInterface *doc_interface, char ***out, GError ** /*error*/) +{ + Inkscape::Selection * sel = doc_interface->target.getSelection(); + auto oldsel = sel->objects(); + + int size = oldsel.size(); + + *out = g_new0 (char *, size + 1); + + int i = 0; + for (auto iter = oldsel.begin(); iter != oldsel.end(); ++iter) { + (*out)[i] = g_strdup((*iter)->getId()); + i++; + } + (*out)[i] = NULL; + + return TRUE; +} + +gboolean +document_interface_selection_add (DocumentInterface *doc_interface, char *name, GError **error) +{ + SPObject * obj = get_object_by_name(doc_interface->target.getDocument(), name, error); + if (!obj) + return FALSE; + + Inkscape::Selection *selection = doc_interface->target.getSelection(); + + selection->add(obj); + return TRUE; +} + +gboolean +document_interface_selection_add_list (DocumentInterface *doc_interface, + char **names, GError **error) +{ + int i; + for (i=0;names[i] != NULL;i++) { + document_interface_selection_add(doc_interface, names[i], error); + } + return TRUE; +} + +gboolean document_interface_selection_set(DocumentInterface *doc_interface, char *name, GError ** /*error*/) +{ + SPDocument * doc = doc_interface->target.getDocument(); + Inkscape::Selection *selection = doc_interface->target.getSelection(); + selection->set(doc->getObjectById(name)); + return TRUE; +} + +gboolean +document_interface_selection_set_list (DocumentInterface *doc_interface, + gchar **names, GError **error) +{ + doc_interface->target.getSelection()->clear(); + int i; + for (i=0;names[i] != NULL;i++) { + document_interface_selection_add(doc_interface, names[i], error); + } + return TRUE; +} + +gboolean document_interface_selection_rotate(DocumentInterface *doc_interface, int angle, GError ** /*error*/) +{ + Inkscape::Selection *selection = doc_interface->target.getSelection(); + selection->rotate(angle); + return TRUE; +} + +gboolean +document_interface_selection_delete (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_EDIT_DELETE, error); +} + +gboolean document_interface_selection_clear(DocumentInterface *doc_interface, GError ** /*error*/) +{ + doc_interface->target.getSelection()->clear(); + return TRUE; +} + +gboolean +document_interface_select_all (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_EDIT_SELECT_ALL, error); +} + +gboolean +document_interface_select_all_in_all_layers(DocumentInterface *doc_interface, + GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error); +} + +gboolean document_interface_selection_box(DocumentInterface * /*doc_interface*/, int /*x*/, int /*y*/, + int /*x2*/, int /*y2*/, gboolean /*replace*/, + GError ** /*error*/) +{ + //FIXME: implement. + return FALSE; +} + +gboolean +document_interface_selection_invert (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_EDIT_INVERT, error); +} + +gboolean +document_interface_selection_group (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_GROUP, error); +} +gboolean +document_interface_selection_ungroup (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_UNGROUP, error); +} + +gboolean +document_interface_selection_cut (DocumentInterface *doc_interface, GError **error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_CUT, error); +} + +gboolean +document_interface_selection_copy (DocumentInterface *doc_interface, GError **error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_COPY, error); +} + +gboolean +document_interface_selection_paste (DocumentInterface *doc_interface, GError **error) +{ + SPDesktop *desk = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(desk, error), FALSE); + return dbus_call_verb (doc_interface, SP_VERB_EDIT_PASTE, error); +} + +gboolean document_interface_selection_scale(DocumentInterface *doc_interface, gdouble grow, GError ** /*error*/) +{ + Inkscape::Selection *selection = doc_interface->target.getSelection(); + if (!selection) + { + return FALSE; + } + selection->scale(grow); + return TRUE; +} + +gboolean document_interface_selection_move(DocumentInterface *doc_interface, gdouble x, gdouble y, GError ** /*error*/) +{ + doc_interface->target.getSelection()->move(x, 0 - y); //switching coordinate systems. + return TRUE; +} + +gboolean document_interface_selection_move_to(DocumentInterface *doc_interface, gdouble x, gdouble y, GError ** /*error*/) +{ + Inkscape::Selection * sel = doc_interface->target.getSelection(); + + Geom::OptRect sel_bbox = sel->visualBounds(); + if (sel_bbox) { + Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) ); + sel->moveRelative(m, true); + } + return TRUE; +} + +//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 *doc_interface, + gchar *layerstr, GError **error) +{ + SPDesktop *dt = doc_interface->target.getDesktop(); + g_return_val_if_fail(ensure_desktop_valid(dt, error), FALSE); + + Inkscape::Selection *selection = doc_interface->target.getSelection(); + + // check if something is selected + if (selection->isEmpty()) + return FALSE; + + SPObject *next = get_object_by_name(doc_interface->target.getDocument(), layerstr, error); + + if (!next) + return FALSE; + + if (strcmp("layer", (next->getRepr())->attribute("inkscape:groupmode")) == 0) { + + dt->selection->cut(); + + doc_interface->target.getSelection()->layers()->setCurrentLayer(next); + + sp_selection_paste(dt, TRUE); + } + return TRUE; +} + +GArray * +document_interface_selection_get_center (DocumentInterface *doc_interface) +{ + Inkscape::Selection * sel = doc_interface->target.getSelection(); + + 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 +document_interface_selection_to_path (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_OBJECT_TO_CURVE, error); +} + + +gboolean +document_interface_selection_combine (DocumentInterface *doc_interface, gchar *cmd, char ***newpaths, + GError **error) +{ + if (strcmp(cmd, "union") == 0) + dbus_call_verb (doc_interface, SP_VERB_SELECTION_UNION, error); + else if (strcmp(cmd, "intersection") == 0) + dbus_call_verb (doc_interface, SP_VERB_SELECTION_INTERSECT, error); + else if (strcmp(cmd, "difference") == 0) + dbus_call_verb (doc_interface, SP_VERB_SELECTION_DIFF, error); + else if (strcmp(cmd, "exclusion") == 0) + dbus_call_verb (doc_interface, SP_VERB_SELECTION_SYMDIFF, error); + else if (strcmp(cmd, "division") == 0) + dbus_call_verb (doc_interface, SP_VERB_SELECTION_CUT, error); + else { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Operation command not recognised"); + return FALSE; + } + + return document_interface_selection_get (doc_interface, newpaths, error); +} + +gboolean +document_interface_selection_change_level (DocumentInterface *doc_interface, gchar *cmd, + GError **error) +{ + if (strcmp(cmd, "raise") == 0) + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_RAISE, error); + if (strcmp(cmd, "lower") == 0) + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_LOWER, error); + if ((strcmp(cmd, "to_top") == 0) || (strcmp(cmd, "to_front") == 0)) + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_TO_FRONT, error); + if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0)) + return dbus_call_verb (doc_interface, SP_VERB_SELECTION_TO_BACK, error); + return TRUE; +} + +/**************************************************************************** + LAYER FUNCTIONS +****************************************************************************/ + +gchar *document_interface_layer_new(DocumentInterface *doc_interface, GError ** /*error*/) +{ + Inkscape::LayerModel * layers = doc_interface->target.getSelection()->layers(); + SPObject *new_layer = Inkscape::create_layer(layers->currentRoot(), layers->currentLayer(), Inkscape::LPOS_BELOW); + layers->setCurrentLayer(new_layer); + return g_strdup(get_name_from_object(new_layer)); +} + +gboolean +document_interface_layer_set (DocumentInterface *doc_interface, + gchar *layerstr, GError **error) +{ + SPObject * obj = get_object_by_name (doc_interface->target.getDocument(), layerstr, error); + + if (!obj) + return FALSE; + + doc_interface->target.getSelection()->layers()->setCurrentLayer (obj); + return TRUE; +} + +gchar **document_interface_layer_get_all(DocumentInterface * /*doc_interface*/) +{ + //FIXME: implement. + return NULL; +} + +gboolean +document_interface_layer_change_level (DocumentInterface *doc_interface, + gchar *cmd, GError **error) +{ + if (strcmp(cmd, "raise") == 0) + return dbus_call_verb (doc_interface, SP_VERB_LAYER_RAISE, error); + if (strcmp(cmd, "lower") == 0) + return dbus_call_verb (doc_interface, SP_VERB_LAYER_LOWER, error); + if ((strcmp(cmd, "to_top") == 0) || (strcmp(cmd, "to_front") == 0)) + return dbus_call_verb (doc_interface, SP_VERB_LAYER_TO_TOP, error); + if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0)) + return dbus_call_verb (doc_interface, SP_VERB_LAYER_TO_BOTTOM, error); + return TRUE; +} + +gboolean +document_interface_layer_next (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_LAYER_NEXT, error); +} + +gboolean +document_interface_layer_previous (DocumentInterface *doc_interface, GError **error) +{ + return dbus_call_verb (doc_interface, SP_VERB_LAYER_PREV, error); +} + + +//////////////signals + + +DocumentInterface *fugly; +gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) +{ + if (!item) return TRUE; + g_signal_emit (desk->dbus_document_interface, signals[OBJECT_MOVED_SIGNAL], 0, item->getId()); + return TRUE; +} + +//////////tree + + +gboolean +document_interface_get_children (DocumentInterface *doc_interface, char *name, char ***out, GError **error) +{ + SPItem* parent=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + std::vector<SPObject*> children = parent->childList(false); + + int size = children.size(); + + *out = g_new0 (char *, size + 1); + + int i = 0; + for (std::vector<SPObject*>::iterator iter = children.begin(), e = children.end(); iter != e; ++iter) { + (*out)[i] = g_strdup((*iter)->getId()); + i++; + } + (*out)[i] = NULL; + + return TRUE; +} + + +gchar* +document_interface_get_parent (DocumentInterface *doc_interface, char *name, GError **error) +{ + SPItem*node=(SPItem* )get_object_by_name(doc_interface->target.getDocument(), name, error); + + SPObject* parent=node->parent; + + return g_strdup(parent->getRepr()->attribute("id")); + +} + +#if 0 +//just pseudo code +gboolean +document_interface_get_xpath (DocumentInterface *doc_interface, char *xpath_expression, char ***out, GError **error){ + SPDocument * doc = doc_interface->target.getDocument(); + Inkscape::XML::Document *repr = doc->getReprDoc(); + + xmlXPathObjectPtr xpathObj; + xmlXPathContextPtr xpathCtx; + xpathCtx = xmlXPathNewContext(repr);//XmlDocPtr + xpathObj = xmlXPathEvalExpression(xmlCharStrdup(xpath_expression), xpathCtx); + + //xpathresult result = xpatheval(repr, xpath_selection); + //convert result to a string array we can return via dbus + return TRUE; +} +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h new file mode 100644 index 0000000..ed31513 --- /dev/null +++ b/src/extension/dbus/document-interface.h @@ -0,0 +1,421 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * 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 <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ +#define INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ + +#include <glib.h> +#include <dbus/dbus-glib.h> +#include <dbus/dbus-glib-bindings.h> +#include <dbus/dbus-glib-lowlevel.h> + +// this is required so that giomm headers won't barf +#undef DBUS_MESSAGE_TYPE_INVALID +#undef DBUS_MESSAGE_TYPE_METHOD_CALL +#undef DBUS_MESSAGE_TYPE_METHOD_RETURN +#undef DBUS_MESSAGE_TYPE_ERROR +#undef DBUS_MESSAGE_TYPE_SIGNAL + +#include "helper/action-context.h" + +class SPDesktop; +class SPItem; + +#define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ()) +#define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface)) +#define DOCUMENT_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass)) +#define IS_DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TYPE_DOCUMENT_INTERFACE)) +#define IS_DOCUMENT_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_INTERFACE)) +#define DOCUMENT_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass)) + +G_BEGIN_DECLS + +typedef struct _DocumentInterface DocumentInterface; +typedef struct _DocumentInterfaceClass DocumentInterfaceClass; + +struct _DocumentInterface { + GObject parent; + Inkscape::ActionContext target; ///< stores information about which document, selection, desktop etc this interface is linked to + gboolean updates; +}; + +struct _DocumentInterfaceClass { + GObjectClass parent; +}; + + + +struct DBUSPoint { + int x; + int y; +}; +/**************************************************************************** + MISC FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_delete_all (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_call_verb (DocumentInterface *doc_interface, + gchar *verbid, GError **error); + +/**************************************************************************** + CREATION FUNCTIONS +****************************************************************************/ + +gchar* +document_interface_rectangle (DocumentInterface *doc_interface, int x, int y, + int width, int height, GError **error); + +gchar* +document_interface_ellipse (DocumentInterface *doc_interface, int x, int y, + int width, int height, GError **error); + +gchar* +document_interface_polygon (DocumentInterface *doc_interface, int cx, int cy, + int radius, int rotation, int sides, + GError **error); + +gchar* +document_interface_star (DocumentInterface *doc_interface, int cx, int cy, + int r1, int r2, int sides, gdouble rounded, + gdouble arg1, gdouble arg2, GError **error); + +gchar* +document_interface_spiral (DocumentInterface *doc_interface, int cx, int cy, + int r, int revolutions, GError **error); + +gchar* +document_interface_line (DocumentInterface *doc_interface, int x, int y, + int x2, int y2, GError **error); + +gchar* +document_interface_text (DocumentInterface *doc_interface, int x, int y, + gchar *text, GError **error); +gboolean +document_interface_set_text (DocumentInterface *doc_interface, gchar *name, + gchar *text, GError **error); +gboolean +document_interface_text_apply_style (DocumentInterface *doc_interface, gchar *name, + int start_pos, int end_pos, gchar *style, gchar *styleval, + GError **error); + +gchar * +document_interface_image (DocumentInterface *doc_interface, int x, int y, + gchar *filename, GError **error); + +gchar* +document_interface_node (DocumentInterface *doc_interface, gchar *svgtype, + GError **error); + + +/**************************************************************************** + ENVIRONMENT FUNCTIONS +****************************************************************************/ +gdouble +document_interface_document_get_width (DocumentInterface *doc_interface); + +gdouble +document_interface_document_get_height (DocumentInterface *doc_interface); + +gchar * +document_interface_document_get_css (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_document_merge_css (DocumentInterface *doc_interface, + gchar *stylestring, GError **error); + +gboolean +document_interface_document_set_css (DocumentInterface *doc_interface, + gchar *stylestring, GError **error); + +gboolean +document_interface_document_resize_to_fit_selection (DocumentInterface *doc_interface, + GError **error); +gboolean +document_interface_document_set_display_area (DocumentInterface *doc_interface, + double x0, + double y0, + double x1, + double y1, + double border, + GError **error); +GArray * +document_interface_document_get_display_area (DocumentInterface *doc_interface); + +/**************************************************************************** + OBJECT FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_set_attribute (DocumentInterface *doc_interface, + char *shape, char *attribute, + char *newval, GError **error); + +gboolean +document_interface_set_int_attribute (DocumentInterface *doc_interface, + char *shape, char *attribute, + int newval, GError **error); + +gboolean +document_interface_set_double_attribute (DocumentInterface *doc_interface, + char *shape, char *attribute, + double newval, GError **error); + +gchar * +document_interface_get_attribute (DocumentInterface *doc_interface, + char *shape, char *attribute, GError **error); + +gboolean +document_interface_move (DocumentInterface *doc_interface, gchar *name, + gdouble x, gdouble y, GError **error); + +gboolean +document_interface_move_to (DocumentInterface *doc_interface, gchar *name, + gdouble x, gdouble y, GError **error); + +gboolean +document_interface_object_to_path (DocumentInterface *doc_interface, + char *shape, GError **error); + +gchar * +document_interface_get_path (DocumentInterface *doc_interface, + char *pathname, GError **error); + +gboolean +document_interface_transform (DocumentInterface *doc_interface, gchar *shape, + gchar *transformstr, GError **error); + +gchar * +document_interface_get_css (DocumentInterface *doc_interface, gchar *shape, + GError **error); + +gboolean +document_interface_modify_css (DocumentInterface *doc_interface, gchar *shape, + gchar *cssattrb, gchar *newval, GError **error); + +gboolean +document_interface_merge_css (DocumentInterface *doc_interface, gchar *shape, + gchar *stylestring, GError **error); + +gboolean +document_interface_set_color (DocumentInterface *doc_interface, gchar *shape, + int r, int g, int b, gboolean fill, GError **error); + +gboolean +document_interface_move_to_layer (DocumentInterface *doc_interface, gchar *shape, + gchar *layerstr, GError **error); + + +GArray * +document_interface_get_node_coordinates (DocumentInterface *doc_interface, gchar *shape); + +/**************************************************************************** + FILE I/O FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_save (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_load (DocumentInterface *doc_interface, + gchar *filename, GError **error); + +gboolean +document_interface_save_as (DocumentInterface *doc_interface, + const gchar *filename, GError **error); + +gboolean +document_interface_mark_as_unmodified (DocumentInterface *doc_interface, GError **error); +/* +gboolean +document_interface_print_to_file (DocumentInterface *doc_interface, GError **error); +*/ + +/**************************************************************************** + PROGRAM CONTROL FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_close (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_exit (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_undo (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_redo (DocumentInterface *doc_interface, GError **error); + + +/**************************************************************************** + UPDATE FUNCTIONS +****************************************************************************/ +void +document_interface_pause_updates (DocumentInterface *doc_interface, GError **error); + +void +document_interface_resume_updates (DocumentInterface *doc_interface, GError **error); + +void +document_interface_update (DocumentInterface *doc_interface, GError **error); + +/**************************************************************************** + SELECTION FUNCTIONS +****************************************************************************/ +gboolean +document_interface_selection_get (DocumentInterface *doc_interface, char ***out, GError **error); + +gboolean +document_interface_selection_add (DocumentInterface *doc_interface, + char *name, GError **error); + +gboolean +document_interface_selection_add_list (DocumentInterface *doc_interface, + char **names, GError **error); + +gboolean +document_interface_selection_set (DocumentInterface *doc_interface, + char *name, GError **error); + +gboolean +document_interface_selection_set_list (DocumentInterface *doc_interface, + gchar **names, GError **error); + +gboolean +document_interface_selection_rotate (DocumentInterface *doc_interface, + int angle, GError **error); + +gboolean +document_interface_selection_delete(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_clear(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_select_all(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_select_all_in_all_layers(DocumentInterface *doc_interface, + GError **error); + +gboolean +document_interface_selection_box (DocumentInterface *doc_interface, int x, int y, + int x2, int y2, gboolean replace, + GError **error); + +gboolean +document_interface_selection_invert (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_group(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_ungroup(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_cut(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_copy(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_paste(DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_scale (DocumentInterface *doc_interface, + gdouble grow, GError **error); + +gboolean +document_interface_selection_move (DocumentInterface *doc_interface, gdouble x, + gdouble y, GError **error); + +gboolean +document_interface_selection_move_to (DocumentInterface *doc_interface, gdouble x, + gdouble y, GError **error); + +gboolean +document_interface_selection_move_to_layer (DocumentInterface *doc_interface, + gchar *layerstr, GError **error); + +GArray * +document_interface_selection_get_center (DocumentInterface *doc_interface); + +gboolean +document_interface_selection_to_path (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_selection_combine (DocumentInterface *doc_interface, gchar *cmd, char ***newpaths, + GError **error); + +gboolean +document_interface_selection_change_level (DocumentInterface *doc_interface, gchar *cmd, + GError **error); + +/**************************************************************************** + LAYER FUNCTIONS +****************************************************************************/ + +gchar * +document_interface_layer_new (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_layer_set (DocumentInterface *doc_interface, + gchar *layerstr, GError **error); + +gchar ** +document_interface_layer_get_all (DocumentInterface *doc_interface); + +gboolean +document_interface_layer_change_level (DocumentInterface *doc_interface, + gchar *cmd, GError **error); + +gboolean +document_interface_layer_next (DocumentInterface *doc_interface, GError **error); + +gboolean +document_interface_layer_previous (DocumentInterface *doc_interface, GError **error); + + + + + + + + +DocumentInterface *document_interface_new (void); +GType document_interface_get_type (void); + +extern DocumentInterface *fugly; +gboolean dbus_send_ping (SPDesktop* desk, SPItem *item); + +gboolean +document_interface_get_children (DocumentInterface *doc_interface, char *name, char ***out, GError **error); + +gchar* +document_interface_get_parent (DocumentInterface *doc_interface, char *name, GError **error); + +gchar* +document_interface_import (DocumentInterface *doc_interface, + gchar *filename, GError **error); + +G_END_DECLS + +#endif // INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml new file mode 100644 index 0000000..4524cba --- /dev/null +++ b/src/extension/dbus/document-interface.xml @@ -0,0 +1,1530 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- SPDX-License-Identifier: GPL-2.0-or-later --> +<!-- + * This is the master description of the DBus document interface. + * + * This file is used to generate both glue code and documentation. + * The methods are in the same order as the .cpp/.h and the sections are labeled. + * + * Any change to method prototypes in document-interface.cpp MUST be reflected here. + * + * This file is the proverbial gold standard for the document interface. + * + * Authors: + * Soren Berg <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. +--> + + +<node name="/org/inkscape/document" + xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd" +> +c + <interface name="org.inkscape.document"> + + <!-- MISC FUNCTIONS --> + + <method name="delete_all" > + </method> + + <method name="call_verb"> + <arg type="s" name="verbid" direction="in"> + <doc:doc> + <doc:summary>The string id of a verb. For example: "EditSelectAll".</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method allows you to call any Inkscape verb using it's associated string. Every button and menu item has an associated verb, so this allows access to some extra functionality if one is willing to do the prerequisite research. The list of verbs can be found at:</doc:para> + </doc:description> + </doc:doc> + </method> + + <!-- CREATION FUNCTIONS --> + + <method name="rectangle"> + <arg type="i" name="x" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the top left corner of the rectangle.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the top left corner of the rectangle.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="width" direction="in" > + <doc:doc> + <doc:summary>Width of the rectangle.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="height" direction="in" > + <doc:doc> + <doc:summary>Height of the rectangle.</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 rectangle.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method creates a rectangle in the current layer using the current document style.</doc:para> + <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para> + <doc:para>Additional variables include:</doc:para> + <doc:para>cx and cy: set these anywhere from zero to half the width or height respectively of the rectangle to give it rounded corners.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="ellipse"> + <arg type="i" name="x" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the top left corner of the ellipse.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the top left corner of the ellipse.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="width" direction="in" > + <doc:doc> + <doc:summary>Width of the ellipse.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="height" direction="in" > + <doc:doc> + <doc:summary>Height of the ellipse.</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 ellipse.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method creates a ellipse in the current layer using the current document style.</doc:para> + <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para> + <doc:para>Additional variables include:</doc:para> + <doc:para>"sodipodi:start" and "sodipodi:end": set these between 0 and Pi to create wedges or Pacman like shapes.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="polygon"> + <arg type="i" name="cx" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the center of the polygon.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="cy" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the center of the polygon.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="radius" direction="in" > + <doc:doc> + <doc:summary>Radius from the center to one of the points.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="rotation" direction="in" > + <doc:doc> + <doc:summary>Angle in degrees to rotate. 0 will have the first point pointing straight up.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="sides" direction="in" > + <doc:doc> + <doc:summary>Number of sides of the polygon.</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 polygon.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method creates a polygon in the current layer using the current document style.</doc:para> + <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para> + <doc:para>Note: this is actually a <doc:ref type="method" to="document.star">star</doc:ref> with "sodipodi:flatsided" set to true, which causes it to ignore the arg2 and r2 values.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="star"> + <arg type="i" name="cx" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the center of the star.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="cy" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the center of the star.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="r1" direction="in" > + <doc:doc> + <doc:summary>distance from the center for the first point.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="r2" direction="in" > + <doc:doc> + <doc:summary>distance from the center for the second point.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="arg1" direction="in" > + <doc:doc> + <doc:summary>Angle in radians for the first point. 0 is 90 degrees to the right of straight up.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="arg2" direction="in" > + <doc:doc> + <doc:summary>Angle in radians for the second point. 0 is 90 degrees to the right of straight up.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="sides" direction="in" > + <doc:doc> + <doc:summary>Number of times to repeat the points around the star.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="rounded" direction="in" > + <doc:doc> + <doc:summary>How rounded to make the star. 0 to 1 recommended for moderate to medium curves. 10 for extreme curves.</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 star.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method creates a star in the current layer using the current document style.</doc:para> + <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para> + <doc:para>Stars are quite complicated. Here is how they are represented: There are two points, represented by sodipodi:arg1 and sodipodi:arg2 for angle in radians and sodipodi:r1 and sodipodi:r2 for respective radius from the center point. The further one is a point of the star, the shorter one one of the valleys. This point and valley are repeated according to sodipodi:sides. sodipodi:rounded controls their control handles.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="spiral"> + <arg type="i" name="cx" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the center of the spiral.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="cy" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the center of the spiral.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="r" direction="in" > + <doc:doc> + <doc:summary>Radius of the spiral.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="revolutions" direction="in" > + <doc:doc> + <doc:summary>Number of revolutions.</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 spiral.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method creates a spiral in the current layer using the current document style. However, fill is automatically set to "none". Stroke is unmodified.</doc:para> + <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para> + <doc:para>Additional variables include:</doc:para> + <doc:para>"sodipodi:expansion": at 1 the spiral gets bigger at a constant rate. Less than one and the loops get tighter and tighter as it goes. More than one and they get looser and looser. This affects the number of revolutions so that it might not actually match the "sodipodi:revolutions" argument.</doc:para> + <doc:para>"sodipodi:t0": at 0 the entire spiral is drawn, at 0.5 it is only drawn %50 of the way (starting from the outside) etc.</doc:para> + <doc:para>"sodipodi:argument": Rotates the spiral. In radians.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="line"> + <arg type="i" name="x" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the first point.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the first point.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="x2" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the second point.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y2" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the second point.</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 line.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method creates a line in the current layer using the current document style. It's a path, so the only attribute it will pay any attention to is "transform".</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="text"> + <arg type="i" name="x" direction="in" > + <doc:doc> + <doc:summary>The x coordinate to put the text at.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y" direction="in" > + <doc:doc> + <doc:summary>The y coordinate to put the text at.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="text" direction="in" > + <doc:doc> + <doc:summary>The text 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 text.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method creates some text in the current layer.</doc:para> + </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="import"> + <arg type="s" name="pathname" direction="in" > + <doc:doc> + <doc:summary>The path to a valid svg file.</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>Imports the file at pathname. Similar to the image + method.</doc:para> + </doc:description> + </doc:doc> + </method> + + + <method name="node"> + <arg type="s" name="svgtype" direction="in" > + <doc:doc> + <doc:summary>The type of node, probably "svg:path"</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="node_name" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The name of the new node.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Make any kind of node you want. Mostly for making paths. (May need to allow updateRepr to be called for it to show up.)</doc:para> + </doc:description> + </doc:doc> + </method> + + <!-- ENVIRONMENT FUNCTIONS --> + + <method name="document_get_width"> + <arg type="d" name="val" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>Document width.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Retrieve the width of the current document. anything outside the boundary will not be printed or exported but will be saved.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="document_get_height"> + <arg type="d" name="val" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>Document height.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Retrieve the height of the current document. anything outside the boundary will not be printed or exported but will be saved.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="document_get_css"> + <arg type="s" name="css" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>CSS attribute string for the document.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Get the current style for the document. All new shapes will use this style if it exists.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="document_set_css"> + <arg type="s" name="stylestring" direction="in" > + <doc:doc> + <doc:summary>A new CSS attribute string for the document.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Set the current style for the document. All new shapes will use this style if it exists.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="document_merge_css"> + <arg type="s" name="stylestring" direction="in" > + <doc:doc> + <doc:summary>A new CSS attribute string for the document.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Merge this string with the current style for the document. All new shapes will use this style if it exists.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref>, <doc:ref type="method" to="document.merge_css">merge_css()</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="document_resize_to_fit_selection"> + <doc:doc> + <doc:description> + <doc:para>Resize the document to contain all of the currently selected objects.</doc:para> + <doc:para>This ensures that the image is not clipped when printing or exporting.</doc:para> + </doc:description> + </doc:doc> + </method> + + + + <method name="document_set_display_area"> + <arg type="d" name="x0" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y0" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="x1" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y1" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="border" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Set display area.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="document_get_display_area"> + <doc:doc> + <doc:description> + <doc:para>Get display area.</doc:para> + </doc:description> + </doc:doc> + <arg type="ad" name="area" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>area</doc:summary> + </doc:doc> + </arg> + </method> + + + <!-- OBJECT FUNCTIONS --> + + <method name="set_attribute"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="attribute" direction="in" > + <doc:doc> + <doc:summary>The name of the attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="newval" direction="in" > + <doc:doc> + <doc:summary>The new value of the attribute. This will overwrite anything already set. To merge styles, see <doc:ref type="method" to="document.merge_css">merge_css()</doc:ref>. </doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Set any attribute, the available attributes depend on what kind of shape the object node represents. See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para> + </doc:description> + </doc:doc> + </method> + + + <method name="set_text"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + + <arg type="s" name="text" direction="in" > + <doc:doc> + <doc:summary>The text you want.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>set text of text object.</doc:para> + </doc:description> + </doc:doc> + </method> + + + <method name="text_apply_style"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + + <arg type="i" name="start" direction="in" > + <doc:doc> + <doc:summary>start text pos.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="end" direction="in" > + <doc:doc> + <doc:summary>end text pos.</doc:summary> + </doc:doc> + </arg> + + <arg type="s" name="css_attrib" direction="in" > + <doc:doc> + <doc:summary>css attribute.</doc:summary> + </doc:doc> + </arg> + + <arg type="s" name="css_attrib_val" direction="in" > + <doc:doc> + <doc:summary>css attribute value.</doc:summary> + </doc:doc> + </arg> + + + <doc:doc> + <doc:description> + <doc:para>set styling of partial text object.</doc:para> + </doc:description> + </doc:doc> + </method> + + + <method name="set_int_attribute"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="attribute" direction="in" > + <doc:doc> + <doc:summary>The name of the attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="newval" direction="in" > + <doc:doc> + <doc:summary>The new value of the attribute. This will overwrite anything already set.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Set any attribute, the available attributes depend on what kind of shape the object node represents. See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para> + <doc:para>This is a convenience function for <doc:ref type="method" to="document.set_attribute">set_attribute()</doc:ref>.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="set_double_attribute"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="attribute" direction="in" > + <doc:doc> + <doc:summary>The name of the attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="newval" direction="in" > + <doc:doc> + <doc:summary>The new value of the attribute. This will overwrite anything already set.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Set any attribute, the available attributes depend on what kind of shape the node represents. See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para> + <doc:para>This is a convenience function for <doc:ref type="method" to="document.set_attribute">set_attribute()</doc:ref>.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="get_attribute"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="attribute" direction="in" > + <doc:doc> + <doc:summary>The name of the attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="val" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The current value of the attribute. String is a copy and must be freed.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Get the value of any attribute. Not all objects will have every attribute their type supports, some are optional. See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="move"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="x" direction="in" > + <doc:doc> + <doc:summary>Distance to move along the x axis.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y" direction="in" > + <doc:doc> + <doc:summary>Distance to move along the y axis.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This will move a shape (or any object) relative to it's current location.</doc:para> + <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the object.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="move_to"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="x" direction="in" > + <doc:doc> + <doc:summary>the x coordinate of the desired location.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y" direction="in" > + <doc:doc> + <doc:summary>the y coordinate of the desired location.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This will move a shape (or any object) to an absolute location. The point moved is the center of the bounding box, which is usually similar to the center of the shape.</doc:para> + <doc:para>Note that creating a rectangle or ellipse at 100,100 and calling move_to to move it to 100,100 will not produce the same results.</doc:para> + <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the object.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="object_to_path"> + <arg type="s" name="objectname" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Turns an object into a path. Most objects contain paths (except rectangles) but are not paths themselves. </doc:para> + <doc:para>This will remove every attribute except d (the path attribute) style and id. id will not change. The appearance will be the same as well, it essentially encodes all information about the shape into the path.</doc:para> + <doc:para>After doing this you will no longer be able to modify the shape using shape specific attributes (cx, radius etc.) except transform</doc:para> + <doc:para>Required for certain functions that work on paths (not yet present in this API.)</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Paths">Paths</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="get_path"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="val" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The path of the object. NULL if the object has no path.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Get the path value of an object. Equivalent to calling <doc:ref type="method" to="document.get_attribute">get_attribte()</doc:ref> with argument "d". Will not turn object into a path if it is not already.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Paths">Paths</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="transform"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of any node or object.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="transformstr" direction="in" > + <doc:doc> + <doc:summary>A string that represents a transformation.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Takes a transformation string ("matrix(0.96629885,0.25742286,-0.25742286,0.96629885,0,0)" or "rotate(45)") and applies it to any shape or path.</doc:para> + <doc:para>Will merge with existing transformations.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="get_css"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>Any object with a style attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="css" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>A CSS Style string</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Retrieve the style of a object. Equivalent to calling <doc:ref type="method" to="document.get_attribute">get_attribute()</doc:ref> for "style".</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="modify_css"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>Any object with a style attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="cssattrib" direction="in" > + <doc:doc> + <doc:summary>An attribute such as "fill" or "stroke-width".</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="newval" direction="in" > + <doc:doc> + <doc:summary>The new value.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Set a particular attribute of a style string. Overwrites just that part of the style.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="merge_css"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>Any object with a style attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="stylestring" direction="in" > + <doc:doc> + <doc:summary>A full or partial CSS Style string.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Takes a CSS Style string and merges it with the objects current style, overwriting only the elements present in stylestring.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="set_color"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>Any object, or 'document' to apply to document style.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="red" direction="in" > + <doc:doc> + <doc:summary>The red component.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="green" direction="in" > + <doc:doc> + <doc:summary>The green component.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="blue" direction="in" > + <doc:doc> + <doc:summary>The blue component.</doc:summary> + </doc:doc> + </arg> + <arg type="b" name="fill" direction="in" > + <doc:doc> + <doc:summary>True to change fill color, false for stroke color.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Modifies the fill or stroke color of an object (or the document style) based on RGB values.</doc:para> + <doc:para>Red green and blue must be between 0-255 inclusive.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="move_to_layer"> + <arg type="s" name="objectname" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="layername" direction="in" > + <doc:doc> + <doc:summary>A layer name.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Moves an object to a different layer.</doc:para> + <doc:para>Will error if layer does not exist.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="document.layer_new">layer_new()</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="get_node_coordinates"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>A object that contains a path ("d") attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="ai" name="points" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>An array of points.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Returns an array of all of the X,Y coordinates of the points in the objects path.</doc:para> + <doc:para>If the path is a closed loop the first point is repeated at the end.</doc:para> + </doc:description> + </doc:doc> + </method> + + <!-- FILE I/O FUNCTIONS --> + + <method name="save" > + <doc:doc> + <doc:description> + <doc:para>Saves the current document with current name or a default name if has not been saved before.</doc:para> + <doc:para>Will overwrite without confirmation.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="save_as"> + <arg type="s" name="pathname" direction="in" > + <doc:doc> + <doc:summary>The path for the file to be saved as.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Saves the current document as pathname.</doc:para> + <doc:para>Will overwrite without confirmation.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="load"> + <arg type="s" name="pathname" direction="in" > + <doc:doc> + <doc:summary>The path to a valid svg file.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Loads the file at pathname.</doc:para> + <doc:para>Will lose all unsaved work in current document.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="mark_as_unmodified" > + <doc:doc> + <doc:description> + <doc:para>Marks the document as unmodified/saved.</doc:para> + <doc:para>Will prevent save confirmation on close if called at end of script.</doc:para> + </doc:description> + </doc:doc> + </method> + + + + <!-- + <method name="print_to_file" > + <doc:doc> + <doc:description> + <doc:para>Prints the current document with default settings.</doc:para> + <doc:para>Will only print things visible within the document boundaries.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="document.document_resize_to_fit_selection">document_resize_to_fit_selection()</doc:ref></doc:seealso> + </doc:doc> + </method> + --> + + <!-- PROGRAM CONTROL FUNCTIONS --> + + <method name="close" > + <doc:doc> + <doc:description> + <doc:para>Close this document.</doc:para> + <doc:para>You will not be able to send any more commands on this interface.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="exit" > + <doc:doc> + <doc:description> + <doc:para>Exit Inkscape.</doc:para> + <doc:para>You will not be able to send any more commands on any interface.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="undo" > + <doc:doc> + <doc:description> + <doc:para>Undo the last action.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="redo" > + <doc:doc> + <doc:description> + <doc:para>Redo the last undone action.</doc:para> + </doc:description> + </doc:doc> + </method> + + <!-- UPDATE FUNCTIONS --> + + <method name="pause_updates" > + <doc:doc> + <doc:description> + <doc:para>When updates are paused Inkscape will not draw every change as it is made. Also you will not be able to undo individual actions made while updates were paused and will only be able to undo them in a group. Inkscape may refresh the screen every couple of seconds even with updates off.</doc:para> + <doc:para>The advantage is a 2-5x speed increase, depending on the type of functions being called. This is most useful when creating large numbers of shapes.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="resume_updates" > + <doc:doc> + <doc:description> + <doc:para>Resume updates after they have been paused. If undo is called at this point it will undo everything that happened since pause_updates() was called.</doc:para> + <doc:para>This will update the display to show any changes that happened while updates were paused, a separate call to update() is not necessary.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="update" > + <doc:doc> + <doc:description> + <doc:para>This will update the document once if updates are paused but it will not resume updates.</doc:para> + <doc:para>This could be used to check on the progress of a complex drawing function, or to add in undo steps at certain points in a render.</doc:para> + </doc:description> + </doc:doc> + </method> + + <!-- SELECTION FUNCTIONS --> + + <method name="selection_get"> + <arg type="as" name="listy" direction="out" > + <!-- <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> --> + <doc:doc> + <doc:summary>List of the ids of currently selected objects.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Returns the current selection in the form of a list of ids of selected objects.</doc:para> + <doc:para>Manipulating this list will not affect the selection.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_add"> + <arg type="s" name="name" direction="in" > + <doc:doc> + <doc:summary>A object to add to the selection.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Adds a single object to the selection.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_add_list"> + <arg type="as" name="name" direction="in" > + <doc:doc> + <doc:summary>An array of object ids to add to the selection.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Adds a list of objects to the selection.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_set"> + <arg type="s" name="name" direction="in" > + <doc:doc> + <doc:summary>A object to select.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Replaces the selection with one containing just this object.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_set_list"> + <arg type="as" name="name" direction="in" > + <doc:doc> + <doc:summary>A list of objects to select.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Replaces the selection with one containing just these objects.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_rotate"> + <arg type="i" name="angle" direction="in" > + <doc:doc> + <doc:summary>Angle in degrees to rotate.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Rotates the selection around the center of it's bounding box.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_delete" > + <doc:doc> + <doc:description> + <doc:para>Delete all objects in the selection.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_clear" > + <doc:doc> + <doc:description> + <doc:para>Deselect everything. Selection will be empty.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="select_all" > + <doc:doc> + <doc:description> + <doc:para>Select all objects in current layer.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="select_all_in_all_layers" > + <doc:doc> + <doc:description> + <doc:para>Select all objects in every layer.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_box"> + <arg type="i" name="x" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the first point.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the first point.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="x2" direction="in" > + <doc:doc> + <doc:summary>X coordinate for the second point.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="y2" direction="in" > + <doc:doc> + <doc:summary>Y coordinate for the second point.</doc:summary> + </doc:doc> + </arg> + <arg type="b" name="replace" direction="in" > + <doc:doc> + <doc:summary>True to replace selection, false to add to selection.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This method finds all of the objects inside the box and adds them to the current selection. If replace is true it will clear the old selection first.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_invert" > + <doc:doc> + <doc:description> + <doc:para>Invert the selection in the current layer.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_group" > + <doc:doc> + <doc:description> + <doc:para>Group the selection.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Groups">Groups</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="selection_ungroup" > + <doc:doc> + <doc:description> + <doc:para>Ungroup the selection.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Groups">Groups</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="selection_cut" > + <doc:doc> + <doc:description> + <doc:para>Cut the current selection.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_copy" > + <doc:doc> + <doc:description> + <doc:para>Copy the current selection.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_paste" > + <doc:doc> + <doc:description> + <doc:para>Paste the current selection at the same location it was cut from.</doc:para> + <doc:para>To paste to a particular location, simply use selection_paste() followed by <doc:ref type="method" to="document.selection_move_to">selection_move_to()</doc:ref>.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_scale"> + <arg type="d" name="grow" direction="in" > + <doc:doc> + <doc:summary>The amount to scale the selection, 1 has no effect. Between 0 and 1 will shrink it proportionally. Greater than one will grow it proportionally.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Scale the selection relative to it's current size.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_move"> + <arg type="d" name="x" direction="in" > + <doc:doc> + <doc:summary>Amount to move in the x direction.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y" direction="in" > + <doc:doc> + <doc:summary>Amount to move in the y direction.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This will move the selection relative to it's current location.</doc:para> + <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the objects in the selection.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="selection_move_to"> + <arg type="d" name="x" direction="in" > + <doc:doc> + <doc:summary>X coordinate to move to.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y" direction="in" > + <doc:doc> + <doc:summary>Y coordinate to move to.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>This will move the center of the selection to a specific location.</doc:para> + <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the objects in the selection.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="selection_move_to_layer"> + <arg type="s" name="layer" direction="in" > + <doc:doc> + <doc:summary>layer to move the selection to.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Move every item in the selection to a different layer.</doc:para> + <doc:para>Will error if layer does not exist.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="selection_get_center"> + <arg type="ad" name="centerpoint" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>Center of the selection.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Gets the center of the selections bounding box in X,Y coordinates.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="selection_to_path" > + <doc:doc> + <doc:description> + <doc:para>Turns all the objects in the selection into paths.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="method" to="document.object_to_path">object_to_path()</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="selection_combine" > + <arg type="s" name="type" direction="in" > + <doc:doc> + <doc:summary>Type of combination.</doc:summary> + </doc:doc> + </arg> + <arg type="as" name="newpaths" direction="out" > + <doc:doc> + <doc:summary>List of the ids of resulting paths after applying the operation.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Will erase all objects in the selection and replace with a single aggregate path.</doc:para> + <doc:para>There are 5 types that can be passed in:</doc:para> + <doc:para>'union': The new shape is all of the other shapes put together, even if they don't overlap (paths can have multiple non-contiguous areas.)</doc:para> + <doc:para>'intersection': The new shape is composed of the area where ALL the objects in the selection overlap. If there is no area where all shapes overlap the new shape will be empty.</doc:para> + <doc:para>'difference': The area of the second shape is subtracted from the first, only works with two objects.</doc:para> + <doc:para>'exclusion': The new shape is the area(s) where none of the objects in the selection overlapped. Only works with two objects.</doc:para> + <doc:para>'division': the first object is split into multiple segments by the second object. Only works with two objects.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="selection_change_level" > + <arg type="s" name="command" direction="in" > + <doc:doc> + <doc:summary>How to change the level</doc:summary> + </doc:doc> + </arg> + <arg type="b" name="objectsmoved" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>True if the objects changed levels. False if they don't(if they were already on top when being raised for example.)</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Will change the level of a selection, respective of other objects in the same layer. Will not affect the overlap of objects in different layers. Will do nothing if the selection contains objects in multiple layers.</doc:para> + <doc:para>There are 4 commands that can be passed in:</doc:para> + <doc:para>"raise" or "lower": Move the selection one level up, or one level down.</doc:para> + <doc:para>"to_top" of "to_bottom": Move the selection above all other objects or below all other objects.</doc:para> + </doc:description> + </doc:doc> + </method> + + <!-- LAYER FUNCTIONS --> + + <method name="layer_new"> + <arg type="s" name="layername" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The name of the new layer.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Turns all the objects in the selection into paths.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="layer_set"> + <arg type="s" name="layer" direction="in" > + <doc:doc> + <doc:summary>The name of any layer.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Sets the layer given as the current layer</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="layer_get_all"> + <arg type="as" name="layers" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>list of layers.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Get a list of all the layers in this document.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="layer_change_level" > + <arg type="s" name="command" direction="in" > + <doc:doc> + <doc:summary>How to change the level</doc:summary> + </doc:doc> + </arg> + <arg type="b" name="layermoved" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>True if the layer was moved. False if it was not (if it was already on top when being raised for example.)</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Will change the level of a layer, respective of other layers. Will not affect the relative level of objects within the layer.</doc:para> + <doc:para>There are 4 commands that can be passed in:</doc:para> + <doc:para>"raise" or "lower": Move the layer one level up, or one level down.</doc:para> + <doc:para>"to_top" of "to_bottom": Move the layer above all other layers or below all other layers.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="layer_next" > + <doc:doc> + <doc:description> + <doc:para>Sets the next (or higher) layer as active.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso> + </doc:doc> + </method> + + <method name="layer_previous" > + <doc:doc> + <doc:description> + <doc:para>Sets the previous (or lower) layer as active.</doc:para> + </doc:description> + <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso> + </doc:doc> + </method> + +<!-- signals --> + <signal name="ObjectMoved"> + <arg name="object_name" type="s"> + <doc:doc> + <doc:summary>The id of the object.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when an object has been moved.</doc:para> + </doc:description> + </doc:doc> + </signal> +<!-- tree --> + + <method name="get_children" > + <arg type="s" name="type" direction="in" > + <doc:doc> + <doc:summary>Any node with an "id" attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="as" name="parentid" direction="out" > + <doc:doc> + <doc:summary>The ids of this nodes children, NULL if bottom level.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Returns the children of any node. This function along with <doc:ref type="method" to="get_parent">get_parent()</doc:ref> can be used to navigate the XML tree. </doc:para> + </doc:description> + </doc:doc> + </method> + <method name="get_parent" > + <arg type="s" name="type" direction="in" > + <doc:doc> + <doc:summary>Any node with an "id" attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="parentid" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The id of this nodes parent, NULL if toplevel.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Returns the parent of any node. This function along with <doc:ref type="method" to="get_children">get_children()</doc:ref> can be used to navigate the XML tree. </doc:para> + </doc:description> + </doc:doc> + </method> + +</interface> +</node> diff --git a/src/extension/dbus/org.inkscape.service.in b/src/extension/dbus/org.inkscape.service.in new file mode 100644 index 0000000..9fffa02 --- /dev/null +++ b/src/extension/dbus/org.inkscape.service.in @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +[D-BUS Service] +Name=org.inkscape +Exec=bindir/bin/inkscape + + diff --git a/src/extension/dbus/proposed-interface.xml b/src/extension/dbus/proposed-interface.xml new file mode 100644 index 0000000..829ee7e --- /dev/null +++ b/src/extension/dbus/proposed-interface.xml @@ -0,0 +1,142 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- SPDX-License-Identifier: GPL-2.0-or-later --> +<!-- + * These are some of the proposed functions for the document interface. + * + * It is only used in generating documentation. + * + * None of these methods are implemented. If someone does code one of + * these methods, remove it from here and add it to document-interface.xml. + * + * Authors: + * Soren Berg <Glimmer07@gmail.com> + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. +--> +<node name="/org/inkscape/proposed" + xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd" +> + <interface name="org.inkscape.proposed"> + + <signal name="Signals_Proposal"> + <doc:doc> + <doc:description> + <doc:para>Signals would undoubtedly be a useful thing to have in many circumstances. They are in proposed for two reasons: One, they complicate things for script writers and may conflict with the proposed C wrapper library. Two, I'm not sure how much coding it would take to implement them because I am familiar with neither Dbus signals or Inkscape events. Until I have done more experimenting I don't want to promise anything I'm not sure can be implemented in a timely fashion.</doc:para> + </doc:description> + </doc:doc> + </signal> + + <signal name="ObjectResized"> + <arg name="object_name" type="s"> + <doc:doc> + <doc:summary>The id of the object.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when an object has been resized.</doc:para> + </doc:description> + </doc:doc> + </signal> + + <signal name="ObjectStyleModified"> + <arg name="object_name" type="s"> + <doc:doc> + <doc:summary>The id of the object.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when the style of an object has been changed.</doc:para> + </doc:description> + </doc:doc> + </signal> + + <signal name="ObjectCreated"> + <arg name="object_name" type="s"> + <doc:doc> + <doc:summary>The id of the object.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when an object has been created. Possibly useful for working in conjunction with a live user.</doc:para> + </doc:description> + </doc:doc> + </signal> + + <signal name="ObjectAddedToSelection"> + <arg name="object_name" type="s"> + <doc:doc> + <doc:summary>The id of the object.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when an object has been added to the selection. Possibly useful for working in conjunction with a live user.</doc:para> + </doc:description> + </doc:doc> + </signal> + + <method name="path_new" > + <arg type="d" name="x" direction="in" > + <doc:doc> + <doc:summary>The x value to begin the path.</doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y" direction="in" > + <doc:doc> + <doc:summary>The y value to begin the path.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Begins a new path, extra nodes can be added with path_append().</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="path_append" > + <arg type="s" name="path" direction="in" > + <doc:doc> + <doc:summary>The name of the path to append to.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="type" direction="in" > + <doc:doc> + <doc:summary>A single letter denoting what type of node is being appended.</doc:summary> + </doc:doc> + </arg> + <arg type="ad" name="arguments" direction="in" > + <doc:doc> + <doc:summary>An array of numbers that describe the position and attributes of the path node.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Adds to an existing path. Close the path by sending "z" and no arguments.</doc:para> + <doc:para>You can no longer append to a path if it is closed.</doc:para> + </doc:description> + </doc:doc> + </method> + + +<!-- USE document-subset.h FILES --> + + <method name="selection_remove"> + <arg type="s" name="name" direction="in" > + <doc:doc> + <doc:summary>A object to remove from the selection.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Removes a single object from the selection. In proposed because I already have a ton of selection functions and am not sure people would need this.</doc:para> + </doc:description> + </doc:doc> + </method> + + </interface> +</node> diff --git a/src/extension/dbus/pytester.py b/src/extension/dbus/pytester.py new file mode 100644 index 0000000..fdd7e9a --- /dev/null +++ b/src/extension/dbus/pytester.py @@ -0,0 +1,291 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +##################################################################### +# Python test script for Inkscape DBus API. +# +# Contains many examples of functions and various stress tests etc. +# Multiple tests can be run at once but the output will be a bit chaotic. +# List of test functions can be found at the bottom of the script. +##################################################################### + +import dbus +import random + +##################################################################### +# Various test functions, called at bottom of script +##################################################################### + +def randomrect (document): + document.rectangle( random.randint(0,1000), + random.randint(0,1000), + random.randint(1,100), + random.randint(1,100)) + +def lottarects ( document ): + document.pause_updates() + listy = [] + for x in range(1,2000): + if x == 1000: + print "HALFWAY" + if x == 1: + print "BEGUN" + document.rectangle( 0, 0, 100, 100) + #randomrect(document) + print "DONE" + for x in listy: + print x + selection_set(x) + document.resume_updates() + +def lottaverbs (doc): + doc.pause_updates() + doc.document_set_css ("fill:#ff0000;fill-opacity:.5;stroke:#0000ff;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none") + doc.rectangle( 0, 0, 100, 100) + doc.select_all() + doc.selection_copy() + for x in range(1,2000): + if x == 1000: + print "HALFWAY" + if x == 1: + print "BEGUN" + doc.selection_paste() + #doc.rectangle( 0, 0, 100, 100) + doc.resume_updates() + +def testDrawing (doc): + doc.document_set_css ("fill:#000000;fill-opacity:.5;stroke:#000000;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none") + doc.ellipse( 0, 0, 100, 100) + doc.select_all() + doc.selection_copy() + for x in range(1,2000): + if x == 1000: + print "HALFWAY" + if x == 1: + print "BEGUN" + doc.selection_paste() + newrect = doc.selection_get()[0] + doc.set_color(newrect, 255 - x%255, 0, 200, True) + doc.set_color(newrect, 0, 255 - x%75, x%75, False) + doc.mark_as_unmodified() + + +def testcopypaste (document ): + #document.pause_updates() + print document.rectangle (400, 500, 100, 100) + print document.rectangle (200, 200, 100, 100) + document.select_all() + document.selection_copy() + document.selection_paste() + #document.resume_updates() + +def testShapes (doc): + doc.rectangle (0, 0, 100, 100) + doc.ellipse (100, 100, 100, 100) + doc.star (250, 250, 50, 25, 5, False, .9, 1.4) + doc.polygon (350, 350, 50, 0, 5) + doc.line (400,400,500,500) + doc.spiral (550,550,50,3) + +def testMovement (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (0, 100, 100, 100) + rect3 = doc.rectangle (0, 200, 100, 100) + doc.select_all() + doc.move(rect2, 100,100) + +def testImport (doc): + # CHANGE TO LOCAL SVG FILE! + img1 = doc.image(0,0, "/home/soren/chavatar.jpg") + doc.selection_add(img1) + doc.selection_scale(500) + doc.transform(img1, "rotate(30)") + +def testSelections (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (0, 100, 100, 100) + rect3 = doc.rectangle (0, 200, 100, 100) + rect4 = doc.rectangle (0, 300, 100, 100) + + doc.selection_add (rect1) + center = doc.selection_get_center() + for d in center: + print d + doc.selection_to_path() + doc.get_path(rect1) + doc.selection_move(100.0, 100.0) + doc.selection_set(rect2) + doc.selection_move_to(0.0,0.0) + doc.selection_set(rect3) + doc.move(rect4, 500.0, 500.0) + doc.select_all() + doc.selection_to_path() + result = doc.selection_get() + print len(result) + for d in result: + print d + +def testLevels (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (20, 20, 100, 100) + rect3 = doc.rectangle (40, 40, 100, 100) + rect4 = doc.rectangle (60, 60, 100, 100) + + doc.selection_set(rect1) + doc.selection_change_level("raise") + + doc.selection_set(rect4) + doc.selection_change_level("to_bottom") + +def testCombinations (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (20, 20, 100, 100) + rect3 = doc.rectangle (40, 40, 100, 100) + rect4 = doc.rectangle (60, 60, 100, 100) + rect5 = doc.rectangle (80, 80, 100, 100) + rect6 = doc.rectangle (100, 100, 100, 100) + rect7 = doc.rectangle (120, 120, 100, 100) + rect8 = doc.rectangle (140, 140, 100, 100) + rect9 = doc.rectangle (160, 160, 100, 100) + rect10 = doc.rectangle (180, 180, 100, 100) + + doc.selection_set_list([rect1, rect2]) + print doc.selection_combine("union") + doc.selection_set_list([rect3, rect4]) + print doc.selection_combine("intersection") + doc.selection_set_list([rect5, rect6]) + print doc.selection_combine("difference") + doc.selection_set_list([rect7, rect8]) + print doc.selection_combine("exclusion") + doc.selection_set_list([rect9, rect10]) + for d in doc.selection_divide(): + print d + +def testTransforms (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (20, 20, 100, 100) + doc.set_attribute(rect1, "transform", "matrix(0.08881734,0.94288151,-0.99604793,0.68505564,245.36153,118.60315)") + doc.selection_set(rect1) + + doc.selection_move_to(200, 200) + +def testLayer (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + print doc.new_layer() + rect2 = doc.rectangle (20, 20, 100, 100) + +def testGetSelection (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (20, 20, 100, 100) + rect3 = doc.rectangle (40, 40, 100, 100) + doc.select_all() + result = doc.selection_get() + print result + print len(result) + for d in result: + print d + + +def testDocStyle (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + doc.document_set_css ("fill:#ff0000;fill-opacity:.5;stroke:#0000ff;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none") + rect2 = doc.rectangle (20, 20, 100, 100) + doc.document_set_css ("fill:#ffff00;fill-opacity:1;stroke:#009002;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none") + rect3 = doc.rectangle (40, 40, 100, 100) + doc.document_set_css ("fill:#00ff00;fill-opacity:1") + rect4 = doc.rectangle (60, 60, 100, 100) + +def testStyle (doc): + doc.document_set_css ("fill:#ffff00;fill-opacity:1;stroke:#009002;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none") + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (20, 20, 100, 100) + rect3 = doc.rectangle (40, 40, 100, 100) + rect4 = doc.rectangle (60, 60, 100, 100) + + doc.modify_css (rect3, "fill-opacity", ".5") + doc.merge_css (rect4, "fill:#0000ff;fill-opacity:.25;") + print doc.get_css (rect4) + +def testLayers (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + layer1 = doc.layer_new() + layer2 = doc.layer_new() + rect2 = doc.rectangle (20, 20, 100, 100) + rect3 = doc.rectangle (40, 40, 100, 100) + doc.selection_add(rect3) + doc.selection_move_to_layer(layer1) + +def testLoadSave (doc): + doc.load("/home/soren/testfile.svg") + rect2 = doc.rectangle (0, 0, 200, 200) + doc.save_as("/home/soren/testsave.svg") + rect1 = doc.rectangle (20, 20, 200, 200) + doc.save() + rect3 = doc.rectangle (40, 40, 200, 200) + doc.save_as("/home/soren/testsave2.svg") + +def testArray (doc): + rect1 = doc.rectangle (0, 0, 100, 100) + rect2 = doc.rectangle (20, 20, 100, 100) + rect3 = doc.rectangle (40, 40, 100, 100) + doc.selection_set_list([rect1, rect2, rect3]) + +def testPath (doc): + cr1 = doc.ellipse(0,0,50,50) + print doc.get_path(cr1) + doc.object_to_path(cr1) + print doc.get_path(cr1) + #doc.get_node_coordinates(cr1) + +# Needs work. +def testText(doc): + print doc.text(200, 200, "svg:text") + + +##################################################################### +# Setup bus connection, create documents. +##################################################################### + +# Connect to bus +bus = dbus.SessionBus() + +# Get interface for default document +inkdoc1 = bus.get_object('org.inkscape', '/org/inkscape/desktop_0') +doc1 = dbus.Interface(inkdoc1, dbus_interface="org.inkscape.document") + +# Create new window and get the interface for that. (optional) +inkapp = bus.get_object('org.inkscape', + '/org/inkscape/application') +desk2 = inkapp.desktop_new(dbus_interface='org.inkscape.application') +inkdoc2 = bus.get_object('org.inkscape', desk2) +doc2 = dbus.Interface(inkdoc2, dbus_interface="org.inkscape.document") + + +##################################################################### +# Call desired test functions +##################################################################### + +#lottaverbs (doc1) +#lottarects (doc1) +#testDrawing (doc1) + +#doc1.pause_updates() + +testShapes(doc1) +#testMovement(doc1) +#testImport(doc1) # EDIT FUNCTION TO OPEN EXISTING FILE! +#testcopypaste (doc1) +#testTransforms (doc1) +#testDocStyle(doc1) +#testLayers(doc1) +#testLoadSave(doc1) +#testArray(doc1) +#testSelections(doc1) +#testCombinations(doc1) +#testText(doc1) +#testPath(doc1) + +#doc1.resume_updates + + +# Prevents asking if you want to save when closing document. +doc1.mark_as_unmodified() + diff --git a/src/extension/dbus/wrapper/inkdbus.pc.in b/src/extension/dbus/wrapper/inkdbus.pc.in new file mode 100644 index 0000000..512e3b3 --- /dev/null +++ b/src/extension/dbus/wrapper/inkdbus.pc.in @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libinkdbus-0.1 +Requires: gobject-2.0 dbus-glib-1 +Libs: -L${libdir} -linkdbus + +Name: inkdbus +Description: Inkscape DBus Interface Wrapper +Version: @VERSION@ + diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c new file mode 100644 index 0000000..cc9399c --- /dev/null +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c @@ -0,0 +1,787 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * TODO: insert short description here + *//* + * Authors: see git history + * + * Copyright (C) 2013 Authors + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ +#include "inkscape-dbus-wrapper.h" +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + + + +#include "document-client-glue.h" +#include <dbus/dbus-glib.h> +#include <dbus/dbus.h> + +// (static.*(\n[^}]*)*(async)+.*(\n[^}]*)*})|typedef void .*; +// http://www.josephkahn.com/music/index.xml + +/* PRIVATE get a connection to the session bus */ +DBusGConnection * +dbus_get_connection() { + GError *error = NULL; + DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (error) { + fprintf(stderr, "Failed to get connection"); + return NULL; + } + else + return connection; +} + +/* PRIVATE create a proxy object for a bus.*/ +DBusGProxy * +dbus_get_proxy(DBusGConnection *connection) { + return dbus_g_proxy_new_for_name (connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); +} + +#if 0 +/* PRIVATE register an object on a bus */ +static gpointer +dbus_register_object (DBusGConnection *connection, + DBusGProxy * proxy, + GType object_type, + const DBusGObjectInfo *info, + const gchar *path) +{ + GObject *object = (GObject*)g_object_new (object_type, NULL); + dbus_g_object_type_install_info (object_type, info); + dbus_g_connection_register_g_object (connection, path, object); + return object; +} +#endif + +/**************************************************************************** + DOCUMENT INTERFACE CLASS STUFF +****************************************************************************/ + +struct _DocumentInterface { + GObject parent; + DBusGProxy * proxy; +}; + +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->proxy = NULL; +} + + +DocumentInterface * +document_interface_new (void) +{ + return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL); +} + +DocumentInterface * +inkscape_desktop_init_dbus () +{ + DBusGConnection *connection; + GError *error; + DBusGProxy *proxy; + +#if !GLIB_CHECK_VERSION(2,36,0) + g_type_init (); +#endif + + error = NULL; + connection = dbus_g_bus_get (DBUS_BUS_SESSION, + &error); + if (connection == NULL) + { + g_printerr ("Failed to open connection to bus: %s\n", + error->message); + g_error_free (error); + exit (1); + } + + proxy = dbus_g_proxy_new_for_name (connection, + "org.inkscape", + "/org/inkscape/desktop_0", + "org.inkscape.document"); + + DocumentInterface * inkdesk = (DocumentInterface *)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL); + inkdesk->proxy = proxy; + return inkdesk; +} + + +//static +gboolean +inkscape_delete_all (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_delete_all (proxy, error); +} + +//static +gboolean +inkscape_call_verb (DocumentInterface *doc, const char * IN_verbid, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_call_verb(proxy, IN_verbid, error); +} + + +//static +gchar * +inkscape_rectangle (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_rectangle (proxy, IN_x, IN_y, IN_width, IN_height, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_ellipse (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_ellipse (proxy, IN_x, IN_y, IN_width, IN_height, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_polygon (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_radius, const gint IN_rotation, const gint IN_sides, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_polygon (proxy, IN_cx, IN_cy, IN_radius, IN_rotation, IN_sides, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_star (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r1, const gint IN_r2, const gdouble IN_arg1, const gdouble IN_arg2, const gint IN_sides, const gdouble IN_rounded, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_star (proxy, IN_cx, IN_cy, IN_r1, IN_r2, IN_arg1, IN_arg2, IN_sides, IN_rounded, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_spiral (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r, const gint IN_revolutions, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_spiral (proxy, IN_cx, IN_cy, IN_r, IN_revolutions, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_line (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_line (proxy, IN_x, IN_y, IN_x2, IN_y2, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_text (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_text (proxy, IN_x, IN_y, IN_text, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_image (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error) +{ + char * OUT_object_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_image (proxy, IN_x, IN_y, IN_text, &OUT_object_name, error); + return OUT_object_name; +} + +//static +char * +inkscape_node (DocumentInterface *doc, const char * IN_svgtype, GError **error) +{ + char *OUT_node_name; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_node (proxy, IN_svgtype, &OUT_node_name, error); + return OUT_node_name; +} + +//static +gdouble +inkscape_document_get_width (DocumentInterface *doc, GError **error) +{ + gdouble OUT_val; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_document_get_width (proxy, &OUT_val, error); + return OUT_val; +} + +//static +gdouble +inkscape_document_get_height (DocumentInterface *doc, GError **error) +{ + gdouble OUT_val; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_document_get_height (proxy, &OUT_val, error); + return OUT_val; +} + +//static +char * +inkscape_document_get_css (DocumentInterface *doc, GError **error) +{ + char * OUT_css; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_document_get_css (proxy, &OUT_css, error); + return OUT_css; +} + +//static +gboolean +inkscape_document_set_css (DocumentInterface *doc, const char * IN_stylestring, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_document_set_css (proxy, IN_stylestring, error); +} + +//static +gboolean +inkscape_document_merge_css (DocumentInterface *doc, const char * IN_stylestring, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_document_merge_css (proxy, IN_stylestring, error); +} + +//static +gboolean +inkscape_document_resize_to_fit_selection (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_document_resize_to_fit_selection (proxy, error); +} + +//static +gboolean +inkscape_set_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const char * IN_newval, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_set_attribute (proxy, IN_shape, IN_attribute, IN_newval, error); +} + +//static +gboolean +inkscape_set_int_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gint IN_newval, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_set_int_attribute (proxy, IN_shape, IN_attribute, IN_newval, error); +} + +//static +gboolean +inkscape_set_double_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gdouble IN_newval, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_set_double_attribute (proxy, IN_shape, IN_attribute, IN_newval, error); +} + +//static +char * +inkscape_get_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, GError **error) +{ + char * OUT_val; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_get_attribute (proxy, IN_shape, IN_attribute, &OUT_val, error); + return OUT_val; +} + +//static +gboolean +inkscape_move (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_move (proxy, IN_shape, IN_x, IN_y, error); +} + +//static +gboolean +inkscape_move_to (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_move_to (proxy, IN_shape, IN_x, IN_y, error); +} + +//static +gboolean +inkscape_object_to_path (DocumentInterface *doc, const char * IN_objectname, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_object_to_path (proxy, IN_objectname, error); +} + +//static +char * +inkscape_get_path (DocumentInterface *doc, const char * IN_shape, GError **error) +{ + char * OUT_val; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_get_path (proxy, IN_shape, &OUT_val, error); + return OUT_val; +} + +//static +gboolean +inkscape_transform (DocumentInterface *doc, const char * IN_shape, const char * IN_transformstr, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_transform (proxy, IN_shape, IN_transformstr, error); +} + +//static +char * +inkscape_get_css (DocumentInterface *doc, const char * IN_shape, GError **error) +{ + char * OUT_css; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_get_css (proxy, IN_shape, &OUT_css, error); + return OUT_css; +} + +//static +gboolean +inkscape_modify_css (DocumentInterface *doc, const char * IN_shape, const char * IN_cssattrib, const char * IN_newval, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_modify_css (proxy, IN_shape, IN_cssattrib, IN_newval, error); +} + +//static +gboolean +inkscape_merge_css (DocumentInterface *doc, const char * IN_shape, const char * IN_stylestring, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_merge_css (proxy, IN_shape, IN_stylestring, error); +} + +//static +gboolean +inkscape_set_color (DocumentInterface *doc, const char * IN_shape, const gint IN_red, const gint IN_green, const gint IN_blue, const gboolean IN_fill, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_set_color (proxy, IN_shape, IN_red, IN_green, IN_blue, IN_fill, error); +} + +//static +gboolean +inkscape_move_to_layer (DocumentInterface *doc, const char * IN_objectname, const char * IN_layername, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_move_to_layer (proxy, IN_objectname, IN_layername, error); +} + +//static +GArray* +inkscape_get_node_coordinates (DocumentInterface *doc, const char * IN_shape, GError **error) +{ + GArray* OUT_points; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_get_node_coordinates (proxy, IN_shape, &OUT_points, error); + return OUT_points; +} + +//static +gboolean +inkscape_save (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_save (proxy, error); +} + +//static +gboolean +inkscape_save_as (DocumentInterface *doc, const char * IN_pathname, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_save_as (proxy, IN_pathname, error); +} + +//static +gboolean +inkscape_load (DocumentInterface *doc, const char * IN_pathname, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_load (proxy, IN_pathname, error); +} + +//static +gboolean +inkscape_mark_as_unmodified (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_mark_as_unmodified (proxy, error); +} + +//static +gboolean +inkscape_close (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_close (proxy, error); +} + +//static +gboolean +inkscape_inkscape_exit (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_exit (proxy, error); +} + +//static +gboolean +inkscape_undo (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_undo (proxy, error); +} + +//static +gboolean +inkscape_redo (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_redo (proxy, error); +} + +//static +gboolean +inkscape_pause_updates (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_pause_updates (proxy, error); +} + +//static +gboolean +inkscape_resume_updates (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_resume_updates (proxy, error); +} + +//static +gboolean +inkscape_update (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_update (proxy, error); +} + +//static +char ** +inkscape_selection_get (DocumentInterface *doc, GError **error) +{ + char ** OUT_listy; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_selection_get (proxy, &OUT_listy, error); + return OUT_listy; +} + +//static +gboolean +inkscape_selection_add (DocumentInterface *doc, const char * IN_name, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_add (proxy, IN_name, error); +} + +//static +gboolean +inkscape_selection_add_list (DocumentInterface *doc, const char ** IN_name, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_add_list (proxy, IN_name, error); +} + +//static +gboolean +inkscape_selection_set (DocumentInterface *doc, const char * IN_name, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_set (proxy, IN_name, error); +} + +//static +gboolean +inkscape_selection_set_list (DocumentInterface *doc, const char ** IN_name, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_set_list (proxy, IN_name, error); +} + +//static +gboolean +inkscape_selection_rotate (DocumentInterface *doc, const gint IN_angle, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_rotate (proxy, IN_angle, error); +} + +//static +gboolean +inkscape_selection_delete (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_delete (proxy, error); +} + +//static +gboolean +inkscape_selection_clear (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_clear (proxy, error); +} + +//static +gboolean +inkscape_select_all (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_select_all (proxy, error); +} + +//static +gboolean +inkscape_select_all_in_all_layers (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_select_all_in_all_layers (proxy, error); +} + +//static +gboolean +inkscape_selection_box (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, const gboolean IN_replace, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_box (proxy, IN_x, IN_y, IN_x2, IN_y2, IN_replace, error); +} + +//static +gboolean +inkscape_selection_invert (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_invert (proxy, error); +} + +//static +gboolean +inkscape_selection_group (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_group (proxy, error); +} + +//static +gboolean +inkscape_selection_ungroup (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_ungroup (proxy, error); +} + +//static +gboolean +inkscape_selection_cut (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_cut (proxy, error); +} + +//static +gboolean +inkscape_selection_copy (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_copy (proxy, error); +} + +//static +gboolean +inkscape_selection_paste (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_paste (proxy, error); +} + +//static +gboolean +inkscape_selection_scale (DocumentInterface *doc, const gdouble IN_grow, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_scale (proxy, IN_grow, error); +} + +//static +gboolean +inkscape_selection_move (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_move (proxy, IN_x, IN_y, error); +} + +//static +gboolean +inkscape_selection_move_to (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_move_to (proxy, IN_x, IN_y, error); +} + +//static +gboolean +inkscape_selection_move_to_layer (DocumentInterface *doc, const char * IN_layer, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_move_to_layer (proxy, IN_layer, error); +} + +//static +GArray * +inkscape_selection_get_center (DocumentInterface *doc, GError **error) +{ + GArray* OUT_centerpoint; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_selection_get_center (proxy, &OUT_centerpoint, error); + return OUT_centerpoint; +} + +//static +gboolean +inkscape_selection_to_path (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_selection_to_path (proxy, error); +} + +//static +char ** +inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error) +{ + char ** OUT_newpaths; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_selection_combine (proxy, IN_type, &OUT_newpaths, error); + return OUT_newpaths; +} + +//static +gboolean +inkscape_selection_change_level (DocumentInterface *doc, const char * IN_command, GError **error) +{ + gboolean OUT_objectsmoved; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_selection_change_level (proxy, IN_command, &OUT_objectsmoved, error); + return OUT_objectsmoved; +} + +//static +char * +inkscape_layer_new (DocumentInterface *doc, GError **error) +{ + char * OUT_layername; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_layer_new (proxy, &OUT_layername, error); + return OUT_layername; +} + +//static +gboolean +inkscape_layer_set (DocumentInterface *doc, const char * IN_layer, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_layer_set (proxy, IN_layer, error); +} + +//static +char ** +inkscape_layer_get_all (DocumentInterface *doc, GError **error) +{ + char ** OUT_layers; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_layer_get_all (proxy, &OUT_layers, error); + return OUT_layers; +} + +//static +gboolean +inkscape_layer_change_level (DocumentInterface *doc, const char * IN_command, GError **error) +{ + gboolean OUT_layermoved; + DBusGProxy *proxy = doc->proxy; + org_inkscape_document_layer_change_level (proxy, IN_command, &OUT_layermoved, error); + return OUT_layermoved; +} + +//static +gboolean +inkscape_layer_next (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_layer_next (proxy, error); +} + +//static +gboolean +inkscape_layer_previous (DocumentInterface *doc, GError **error) +{ + DBusGProxy *proxy = doc->proxy; + return org_inkscape_document_layer_previous (proxy, error); +} + +/* +int +main (int argc, char** argv) +{ + gchar * result; + GError *error = NULL; + DocumentInterface * doc = inkscape_desktop_init_dbus (); + result = rectangle (doc->proxy, 10, 10, 100, 100, &error); + printf("RESULT: %s\n", result); + + //dbus_g_proxy_call(doc->proxy, "rectangle", &error, G_TYPE_INT, 100, G_TYPE_INT, 100, G_TYPE_INT, 100, G_TYPE_INT, 100, G_TYPE_INVALID, G_TYPE_INVALID); + printf("yes\n"); +} +*/ + diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h new file mode 100644 index 0000000..e2abd30 --- /dev/null +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h @@ -0,0 +1,347 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * TODO: insert short description here + *//* + * Authors: see git history + * + * Copyright (C) 2013 Authors + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ +#ifndef INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ +#define INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ + +#include <glib.h> +#include <glib-object.h> + +//#include "document-client-glue-mod.h" + +//#include <dbus/dbus-glib-bindings.h> +//#include <dbus/dbus-glib-lowlevel.h> + +#define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ()) +#define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface)) +#define DOCUMENT_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass)) +#define IS_DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TYPE_DOCUMENT_INTERFACE)) +#define IS_DOCUMENT_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_INTERFACE)) +#define DOCUMENT_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass)) + +G_BEGIN_DECLS + +typedef struct _DocumentInterface DocumentInterface; +typedef struct _DocumentInterfaceClass DocumentInterfaceClass; + +struct _DocumentInterface; + +struct _DocumentInterfaceClass { + GObjectClass parent; +}; + + +DocumentInterface *document_interface_new (void); +GType document_interface_get_type (void); + + + +DocumentInterface * +inkscape_desktop_init_dbus (); + +//static +gboolean +inkscape_delete_all (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_call_verb (DocumentInterface *doc, const char * IN_verbid, GError **error); + + +//static +gchar * +inkscape_rectangle (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error); + +//static +char * +inkscape_ellipse (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error); + +//static +char * +inkscape_polygon (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_radius, const gint IN_rotation, const gint IN_sides, GError **error); + +//static +char * +inkscape_star (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r1, const gint IN_r2, const gdouble IN_arg1, const gdouble IN_arg2, const gint IN_sides, const gdouble IN_rounded, GError **error); + +//static +char * +inkscape_spiral (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r, const gint IN_revolutions, GError **error); + +//static +char * +inkscape_line (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, GError **error); + +//static +char * +inkscape_text (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error); + +//static +char * +inkscape_image (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error); + +//static +char * +inkscape_node (DocumentInterface *doc, const char * IN_svgtype, GError **error); + +//static +gdouble +inkscape_document_get_width (DocumentInterface *doc, GError **error); + +//static +gdouble +inkscape_document_get_height (DocumentInterface *doc, GError **error); + +//static +char * +inkscape_document_get_css (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_document_set_css (DocumentInterface *doc, const char * IN_stylestring, GError **error); + +//static +gboolean +inkscape_document_merge_css (DocumentInterface *doc, const char * IN_stylestring, GError **error); + +//static +gboolean +inkscape_document_resize_to_fit_selection (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_set_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const char * IN_newval, GError **error); + +//static +gboolean +inkscape_set_int_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gint IN_newval, GError **error); + +//static +gboolean +inkscape_set_double_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gdouble IN_newval, GError **error); + +//static +char * +inkscape_get_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, GError **error); + +//static +gboolean +inkscape_move (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error); + +//static +gboolean +inkscape_move_to (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error); + +//static +gboolean +inkscape_object_to_path (DocumentInterface *doc, const char * IN_objectname, GError **error); + +//static +char * +inkscape_get_path (DocumentInterface *doc, const char * IN_shape, GError **error); + +//static +gboolean +inkscape_transform (DocumentInterface *doc, const char * IN_shape, const char * IN_transformstr, GError **error); + +//static +char * +inkscape_get_css (DocumentInterface *doc, const char * IN_shape, GError **error); + +//static +gboolean +inkscape_modify_css (DocumentInterface *doc, const char * IN_shape, const char * IN_cssattrib, const char * IN_newval, GError **error); + +//static +gboolean +inkscape_inkscape_merge_css (DocumentInterface *doc, const char * IN_shape, const char * IN_stylestring, GError **error); + +//static +gboolean +inkscape_set_color (DocumentInterface *doc, const char * IN_shape, const gint IN_red, const gint IN_green, const gint IN_blue, const gboolean IN_fill, GError **error); + +//static +gboolean +inkscape_move_to_layer (DocumentInterface *doc, const char * IN_objectname, const char * IN_layername, GError **error); + +//static +GArray* +inkscape_get_node_coordinates (DocumentInterface *doc, const char * IN_shape, GError **error); + +//static +gboolean +inkscape_save (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_save_as (DocumentInterface *doc, const char * IN_pathname, GError **error); + +//static +gboolean +inkscape_load (DocumentInterface *doc, const char * IN_pathname, GError **error); + +//static +gboolean +inkscape_mark_as_unmodified (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_close (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_inkscape_exit (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_undo (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_redo (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_pause_updates (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_resume_updates (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_update (DocumentInterface *doc, GError **error); + +//static +char ** +inkscape_selection_get (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_add (DocumentInterface *doc, const char * IN_name, GError **error); + +//static +gboolean +inkscape_selection_add_list (DocumentInterface *doc, const char ** IN_name, GError **error); + +//static +gboolean +inkscape_selection_set (DocumentInterface *doc, const char * IN_name, GError **error); + +//static +gboolean +inkscape_selection_set_list (DocumentInterface *doc, const char ** IN_name, GError **error); + +//static +gboolean +inkscape_selection_rotate (DocumentInterface *doc, const gint IN_angle, GError **error); + +//static +gboolean +inkscape_selection_delete (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_clear (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_select_all (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_select_all_in_all_layers (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_box (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, const gboolean IN_replace, GError **error); + +//static +gboolean +inkscape_selection_invert (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_group (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_ungroup (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_cut (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_copy (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_paste (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_scale (DocumentInterface *doc, const gdouble IN_grow, GError **error); + +//static +gboolean +inkscape_selection_move (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error); + +//static +gboolean +inkscape_selection_move_to (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error); + +//static +gboolean +inkscape_selection_move_to_layer (DocumentInterface *doc, const char * IN_layer, GError **error); + +//static +GArray * +inkscape_selection_get_center (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_selection_to_path (DocumentInterface *doc, GError **error); + +//static +char ** +inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error); + +//static +gboolean +inkscape_selection_change_level (DocumentInterface *doc, const char * IN_command, GError **error); + +//static +char * +inkscape_layer_new (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_layer_set (DocumentInterface *doc, const char * IN_layer, GError **error); + +//static +char ** +inkscape_layer_get_all (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_layer_change_level (DocumentInterface *doc, const char * IN_command, GError **error); + +//static +gboolean +inkscape_layer_next (DocumentInterface *doc, GError **error); + +//static +gboolean +inkscape_layer_previous (DocumentInterface *doc, GError **error); + +G_END_DECLS + +#endif // INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ |