Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaul Gutierrez Segales <rgs@collabora.co.uk>2011-10-30 22:12:16 (GMT)
committer Sascha Silbe <silbe@activitycentral.com>2011-11-22 12:28:58 (GMT)
commit90e708bc8e57f7b5dd65e433f840722b8a034c2e (patch)
treebeccc378d8cec7758af4eb24fda1e6c2de63f695
parent7d01f5927f1a862b07bb5b4eae95feccb198e594 (diff)
Add wrapper for rsvg
[split patch into several parts] Signed-off-by: Sascha Silbe <silbe@activitycentral.com>
-rw-r--r--configure.ac2
-rw-r--r--src/sugar3/Makefile.am6
-rw-r--r--src/sugar3/rsvg-wrapper.c156
-rw-r--r--src/sugar3/rsvg-wrapper.h71
4 files changed, 233 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index e815274..782895a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
AC_PATH_PROG(PYGTK_CODEGEN, pygtk-codegen-2.0, no)
-PKG_CHECK_MODULES(EXT, pygtk-2.0 gtk+-2.0 sm ice alsa)
+PKG_CHECK_MODULES(EXT, gtk+-3.0 gdk-3.0 gdk-pixbuf-2.0 sm ice alsa librsvg-2.0)
PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0`
AC_SUBST(PYGTK_DEFSDIR)
diff --git a/src/sugar3/Makefile.am b/src/sugar3/Makefile.am
index ca5abed..1273042 100644
--- a/src/sugar3/Makefile.am
+++ b/src/sugar3/Makefile.am
@@ -45,6 +45,8 @@ libsugarext_la_SOURCES = \
gsm-session.h \
gsm-xsmp.c \
gsm-xsmp.h \
+ rsvg-wrapper.c \
+ rsvg-wrapper.h \
sugar-grid.c \
sugar-grid.h \
sugar-key-grabber.c \
@@ -89,7 +91,9 @@ SugarExt_1_0_gir_FILES = \
sugar-key-grabber.c \
sugar-key-grabber.h \
gdk-wrapper.c \
- gdk-wrapper.h
+ gdk-wrapper.h \
+ rsvg-wrapper.c \
+ rsvg-wrapper.h
SugarExt_1_0_gir_INCLUDES = Gtk-3.0 Gdk-3.0
SugarExt_1_0_gir_PACKAGES = gtk+-3.0 gdk-3.0
diff --git a/src/sugar3/rsvg-wrapper.c b/src/sugar3/rsvg-wrapper.c
new file mode 100644
index 0000000..ec3a4cd
--- /dev/null
+++ b/src/sugar3/rsvg-wrapper.c
@@ -0,0 +1,156 @@
+/* rsvg-wrapper.c
+ * Copyright (C) 2011 Raul Gutierrez Segales
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+
+/* Wrapper around rsvg while it gets introspection support.
+ *
+ * See: https://bugzilla.gnome.org/show_bug.cgi?id=663049
+ */
+
+#include "rsvg-wrapper.h"
+#include <librsvg/rsvg.h>
+#include <librsvg/rsvg-cairo.h>
+
+
+G_DEFINE_TYPE (SugarRsvgWrapper, sugar_rsvg_wrapper, G_TYPE_OBJECT)
+
+#define RSVG_WRAPPER_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), SUGAR_TYPE_RSVG_WRAPPER, SugarRsvgWrapperPrivate))
+
+struct _SugarRsvgWrapperPrivate
+{
+ RsvgHandle *handle;
+};
+
+static void
+sugar_rsvg_wrapper_dispose (GObject *object)
+{
+ SugarRsvgWrapper *self = SUGAR_RSVG_WRAPPER (object);
+ SugarRsvgWrapperPrivate *priv = self->priv;
+
+ if (priv->handle)
+ rsvg_handle_free (priv->handle);
+
+ G_OBJECT_CLASS (sugar_rsvg_wrapper_parent_class)->dispose (object);
+}
+
+static void
+sugar_rsvg_wrapper_class_init (SugarRsvgWrapperClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (SugarRsvgWrapperPrivate));
+
+ object_class->dispose = sugar_rsvg_wrapper_dispose;
+}
+
+static void
+sugar_rsvg_wrapper_init (SugarRsvgWrapper *wrapper)
+{
+ SugarRsvgWrapperPrivate *priv;
+
+ priv = wrapper->priv = RSVG_WRAPPER_PRIVATE (wrapper);
+ priv->handle = NULL;
+}
+
+
+/**
+ * sugar_rsvg_wrapper_new:
+ * @data: (transfer none) (array length=len): the image data
+ * @len: the length of @data
+ *
+ * Creates a new wrapper object
+ *
+ * Returns: (transfer full): new #SugarRsvgWrapper
+ **/
+SugarRsvgWrapper*
+sugar_rsvg_wrapper_new (const guint8 *data,
+ gsize len)
+{
+ SugarRsvgWrapper* wrapper = g_object_new (SUGAR_TYPE_RSVG_WRAPPER, NULL);
+ SugarRsvgWrapperPrivate *priv;
+ GError *error;
+
+ priv = RSVG_WRAPPER_PRIVATE (wrapper);
+
+ /* My code never fails, hence I don't bother checking
+ * the error after the call - rgs
+ */
+ priv->handle = rsvg_handle_new_from_data (data, len, &error);
+
+ return wrapper;
+}
+
+/**
+ * sugar_rsvg_wrapper_get_width:
+ * @wrapper: an #SugarRsvgWrapper
+ *
+ * Gets the width of the associated RsvgHandle.
+ *
+ * Returns: The width of the wrapped RsvgHandle
+ **/
+int sugar_rsvg_wrapper_get_width(SugarRsvgWrapper *wrapper)
+{
+ SugarRsvgWrapperPrivate *priv = RSVG_WRAPPER_PRIVATE (wrapper);
+ RsvgDimensionData dim;
+
+ rsvg_handle_get_dimensions (priv->handle, &dim);
+ return dim.width;
+}
+
+/**
+ * sugar_rsvg_wrapper_get_height:
+ * @wrapper: an #SugarRsvgWrapper
+ *
+ * Gets the height of the associated RsvgHandle.
+ *
+ * Returns: The height of the wrapped RsvgHandle
+ **/
+int sugar_rsvg_wrapper_get_height(SugarRsvgWrapper *wrapper)
+{
+ SugarRsvgWrapperPrivate *priv = RSVG_WRAPPER_PRIVATE (wrapper);
+ RsvgDimensionData dim;
+
+ rsvg_handle_get_dimensions (priv->handle, &dim);
+ return dim.height;
+}
+
+/**
+ * sugar_rsvg_wrapper_render_cairo:
+ * @wrapper: an #SugarRsvgWrapper
+ * @cr: the cairo region
+ *
+ **/
+void sugar_rsvg_wrapper_render_cairo(SugarRsvgWrapper *wrapper, cairo_t * cr)
+{
+ SugarRsvgWrapperPrivate *priv = RSVG_WRAPPER_PRIVATE (wrapper);
+ rsvg_handle_render_cairo (priv->handle, cr);
+}
+
+/**
+ * sugar_rsvg_wrapper_get_pixbuf:
+ * @wrapper: an #SugarRsvgWrapper
+ *
+ * Returns: (transfer full): the #GdkPixbuf
+ **/
+GdkPixbuf *sugar_rsvg_wrapper_get_pixbuf(SugarRsvgWrapper *wrapper)
+{
+ SugarRsvgWrapperPrivate *priv = RSVG_WRAPPER_PRIVATE (wrapper);
+ return rsvg_handle_get_pixbuf (priv->handle);
+}
diff --git a/src/sugar3/rsvg-wrapper.h b/src/sugar3/rsvg-wrapper.h
new file mode 100644
index 0000000..e78c5a7
--- /dev/null
+++ b/src/sugar3/rsvg-wrapper.h
@@ -0,0 +1,71 @@
+/* rsvg-wrapper.h
+ * Copyright (C) 2011 Raul Gutierrez Segales
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef __RSVG_WRAPPER_H__
+#define __RSVG_WRAPPER_H__
+
+#include <cairo.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+G_BEGIN_DECLS
+
+#define SUGAR_TYPE_RSVG_WRAPPER sugar_rsvg_wrapper_get_type ()
+
+#define SUGAR_RSVG_WRAPPER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), SUGAR_TYPE_RSVG_WRAPPER, SugarRsvgWrapper))
+
+#define SUGAR_RSVG_WRAPPER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), SUGAR_TYPE_RSVG_WRAPPER, SugarRsvgWrapperClass))
+
+#define SUGAR_IS_RSVG_WRAPPER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SUGAR_TYPE_RSVG_WRAPPER))
+
+#define SUGAR_IS_RSVG_WRAPPER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), SUGAR_TYPE_RSVG_WRAPPER))
+
+#define SUGAR_RSVG_WRAPPER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), SUGAR_TYPE_RSVG_WRAPPER, SugarRsvgWrapperClass))
+
+typedef struct _SugarRsvgWrapper SugarRsvgWrapper;
+typedef struct _SugarRsvgWrapperClass SugarRsvgWrapperClass;
+typedef struct _SugarRsvgWrapperPrivate SugarRsvgWrapperPrivate;
+
+struct _SugarRsvgWrapper
+{
+ GObject parent;
+ SugarRsvgWrapperPrivate *priv;
+};
+
+struct _SugarRsvgWrapperClass
+{
+ GObjectClass parent_class;
+};
+
+GType sugar_rsvg_wrapper_get_type (void);
+
+SugarRsvgWrapper* sugar_rsvg_wrapper_new (const guint8 *data, gsize len);
+int sugar_rsvg_wrapper_load(SugarRsvgWrapper *wrapper);
+int sugar_rsvg_wrapper_get_width(SugarRsvgWrapper *wrapper);
+int sugar_rsvg_wrapper_get_height(SugarRsvgWrapper *wrapper);
+void sugar_rsvg_wrapper_render_cairo(SugarRsvgWrapper *wrapper, cairo_t * cr);
+GdkPixbuf * sugar_rsvg_wrapper_get_pixbuf(SugarRsvgWrapper *wrapper);
+
+#endif /* __RSVG_WRAPPER_H__ */