[Sugar-devel] [PATCH] Remove the workaround for missing gobject-introspection bindings of Rsvg

Simon Schampijer simon at schampijer.de
Tue Mar 20 08:39:10 EDT 2012


gobject introspection bindings for librsvg have been pushed to librsvg
master [1] in 2.35.0, which solved [2]. We only have slight adopts to
make in our usage, for example we can not pass the data property
to the default constructor anymore and get_width and get_height is not
available anymore for the handle, but we can use the properties
instead.

This will work on Fedora 17 upwards.

Signed-off-by: Simon Schampijer <simon at laptop.org>

[1] http://git.gnome.org/browse/librsvg/
[2] https://bugzilla.gnome.org/show_bug.cgi?id=663049
[3] http://developer.gnome.org/rsvg/stable/RsvgHandle.html
---
 src/sugar3/Makefile.am      |    6 +--
 src/sugar3/graphics/icon.py |    9 +--
 src/sugar3/rsvg-wrapper.c   |  156 -------------------------------------------
 src/sugar3/rsvg-wrapper.h   |   71 -------------------
 4 files changed, 5 insertions(+), 237 deletions(-)
 delete mode 100644 src/sugar3/rsvg-wrapper.c
 delete mode 100644 src/sugar3/rsvg-wrapper.h

diff --git a/src/sugar3/Makefile.am b/src/sugar3/Makefile.am
index 3aec8bf..053052d 100644
--- a/src/sugar3/Makefile.am
+++ b/src/sugar3/Makefile.am
@@ -48,8 +48,6 @@ 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		\
@@ -133,9 +131,7 @@ SugarExt_1_0_gir_FILES = \
 	sugar-grid.c \
 	sugar-grid.h \
 	gdk-wrapper.c \
-	gdk-wrapper.h \
-	rsvg-wrapper.c \
-	rsvg-wrapper.h
+	gdk-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/graphics/icon.py b/src/sugar3/graphics/icon.py
index a1800c7..951be30 100644
--- a/src/sugar3/graphics/icon.py
+++ b/src/sugar3/graphics/icon.py
@@ -29,14 +29,13 @@ from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import Gdk
 from gi.repository import GdkPixbuf
+from gi.repository import Rsvg
 import cairo
 
 from sugar3.graphics import style
 from sugar3.graphics.xocolor import XoColor
 from sugar3.util import LRU
 
-from gi.repository import SugarExt
-
 _BADGE_SIZE = 0.45
 
 
@@ -64,7 +63,7 @@ class _SVGLoader(object):
                 logging.error(
                     'Icon %s, entity %s is invalid.', file_name, entity)
 
-        return SugarExt.RsvgWrapper.new(icon)
+        return Rsvg.Hanlde.new_with_data(icon)
 
 
 class _IconInfo(object):
@@ -260,8 +259,8 @@ class _IconBuffer(object):
 
         if is_svg:
             handle = self._load_svg(icon_info.file_name)
-            icon_width = handle.get_width()
-            icon_height = handle.get_height()
+            icon_width = handle.props.width
+            icon_height = handle.props.height
         else:
             pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_info.file_name)
             icon_width = pixbuf.get_width()
diff --git a/src/sugar3/rsvg-wrapper.c b/src/sugar3/rsvg-wrapper.c
deleted file mode 100644
index ec3a4cd..0000000
--- a/src/sugar3/rsvg-wrapper.c
+++ /dev/null
@@ -1,156 +0,0 @@
-/* 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
deleted file mode 100644
index e78c5a7..0000000
--- a/src/sugar3/rsvg-wrapper.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* 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__ */
-- 
1.7.7.6



More information about the Sugar-devel mailing list