[aisleriot] Require librsvg for the scalable card themes



commit dc29410f15f6b640e2f5601450bfeb1b30b189fd
Author: Christian Persch <chpe gnome org>
Date:   Mon Apr 25 17:53:29 2011 +0200

    Require librsvg for the scalable card themes

 src/lib/Makefile.am              |   10 ++-
 src/lib/ar-card-theme-kde.c      |    4 -
 src/lib/ar-card-theme-preimage.c |    7 --
 src/lib/ar-card-theme-private.h  |    2 -
 src/lib/ar-card-theme-svg.c      |    3 -
 src/lib/ar-preimage-private.h    |    9 ---
 src/lib/ar-preimage.c            |  120 ++------------------------------------
 src/lib/ar-preimage.h            |   10 +--
 8 files changed, 15 insertions(+), 150 deletions(-)
---
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index e5e500c..2e7a115 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -26,9 +26,6 @@ libaisleriot_la_SOURCES = \
 	ar-gsettings.h \
 	ar-help.c \
 	ar-help.h \
-	ar-preimage.c \
-	ar-preimage.h \
-	ar-preimage-private.h \
 	ar-profile.c \
 	ar-profile.h \
 	ar-runtime.c \
@@ -50,7 +47,12 @@ libaisleriot_la_SOURCES += \
 endif # HAVE_CLUTTER
 
 if HAVE_RSVG
-libaisleriot_la_SOURCES += ar-card-theme-preimage.c
+libaisleriot_la_SOURCES += \
+	ar-preimage.c \
+	ar-preimage.h \
+	ar-preimage-private.h \
+	ar-card-theme-preimage.c \
+	$(NULL)
 
 if ENABLE_CARD_THEME_FORMAT_SVG
 libaisleriot_la_SOURCES += ar-card-theme-svg.c
diff --git a/src/lib/ar-card-theme-kde.c b/src/lib/ar-card-theme-kde.c
index c846258..9edb00c 100644
--- a/src/lib/ar-card-theme-kde.c
+++ b/src/lib/ar-card-theme-kde.c
@@ -560,7 +560,6 @@ ar_card_theme_kde_class_init (ArCardThemeKDEClass * klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   ArCardThemeClass *theme_class = AR_CARD_THEME_CLASS (klass);
-  ArCardThemePreimageClass *preimage_theme_class = AR_CARD_THEME_PREIMAGE_CLASS (klass);
 
   gobject_class->finalize = ar_card_theme_kde_finalize;
   gobject_class->get_property = ar_card_theme_kde_get_property;
@@ -574,9 +573,6 @@ ar_card_theme_kde_class_init (ArCardThemeKDEClass * klass)
   theme_class->get_card_pixbuf = ar_card_theme_kde_get_card_pixbuf;
   theme_class->paint_card = ar_card_theme_kde_paint_card;
 
-  preimage_theme_class->needs_scalable_cards = TRUE;
-
-
   g_object_class_install_property
     (gobject_class,
      PROP_BACK_INDEX,
diff --git a/src/lib/ar-card-theme-preimage.c b/src/lib/ar-card-theme-preimage.c
index f459da9..653a641 100644
--- a/src/lib/ar-card-theme-preimage.c
+++ b/src/lib/ar-card-theme-preimage.c
@@ -81,13 +81,6 @@ ar_card_theme_preimage_load (ArCardTheme *card_theme,
   if (!theme->cards_preimage)
     return FALSE;
 
-  if (AR_CARD_THEME_PREIMAGE_GET_CLASS (theme)->needs_scalable_cards &&
-      !ar_preimage_is_scalable (theme->cards_preimage)) {
-    g_set_error (error, AR_CARD_THEME_ERROR, AR_CARD_THEME_ERROR_NOT_SCALABLE,
-                 "Theme is not scalable");
-    return FALSE;
-  }
-
   if (theme->font_options) {
     ar_preimage_set_font_options (theme->slot_preimage, theme->font_options);
     ar_preimage_set_font_options (theme->cards_preimage, theme->font_options);
diff --git a/src/lib/ar-card-theme-private.h b/src/lib/ar-card-theme-private.h
index 0ef9307..2c9b55b 100644
--- a/src/lib/ar-card-theme-private.h
+++ b/src/lib/ar-card-theme-private.h
@@ -132,8 +132,6 @@ typedef struct _ArCardThemePreimage      ArCardThemePreimage;
 struct _ArCardThemePreimageClass {
   ArCardThemeClass parent_class;
 
-  gboolean needs_scalable_cards;
-
   void (* clear_sized_theme_data) (ArCardThemePreimage *card_theme);
 };
 
diff --git a/src/lib/ar-card-theme-svg.c b/src/lib/ar-card-theme-svg.c
index a0212d3..ad2d059 100644
--- a/src/lib/ar-card-theme-svg.c
+++ b/src/lib/ar-card-theme-svg.c
@@ -198,15 +198,12 @@ static void
 ar_card_theme_svg_class_init (ArCardThemeSVGClass * klass)
 {
   ArCardThemeClass *theme_class = AR_CARD_THEME_CLASS (klass);
-  ArCardThemePreimageClass *preimage_theme_class = AR_CARD_THEME_PREIMAGE_CLASS (klass);
 
   theme_class->get_theme_info = ar_card_theme_svg_class_get_theme_info;
   theme_class->foreach_theme_dir = ar_card_theme_svg_class_foreach_theme_dir;
 
   theme_class->get_card_pixbuf = ar_card_theme_svg_get_card_pixbuf;
   theme_class->paint_card = ar_card_theme_svg_paint_card;
-
-  preimage_theme_class->needs_scalable_cards = TRUE;
 }
 
 /* private API */
diff --git a/src/lib/ar-preimage-private.h b/src/lib/ar-preimage-private.h
index b86f4c5..f6b6364 100644
--- a/src/lib/ar-preimage-private.h
+++ b/src/lib/ar-preimage-private.h
@@ -18,9 +18,7 @@
 
 /* Authors:   Richard Hoelscher <rah rahga com> */
 
-#ifdef HAVE_RSVG
 #include <librsvg/rsvg.h>
-#endif
 
 struct _ArPreimage {
   GObject parent;
@@ -28,13 +26,6 @@ struct _ArPreimage {
   gint width;
   gint height;
 
-#ifdef HAVE_RSVG
   RsvgHandle *rsvg_handle;
   cairo_font_options_t *font_options;
-#endif
-
-  /* raster pixbuf data */
-  GdkPixbuf *pixbuf;
-
-  guint scalable : 1;
 };
diff --git a/src/lib/ar-preimage.c b/src/lib/ar-preimage.c
index 15afa01..5d2b3fc 100644
--- a/src/lib/ar-preimage.c
+++ b/src/lib/ar-preimage.c
@@ -30,10 +30,8 @@
 /* For gdkcairo */
 #include <gdk/gdk.h>
 
-#ifdef HAVE_RSVG
 #include <librsvg/rsvg.h>
 #include <librsvg/rsvg-cairo.h>
-#endif /* HAVE_RSVG */
 
 #include "ar-profile.h"
 
@@ -45,7 +43,6 @@ G_DEFINE_TYPE (ArPreimage, ar_preimage, G_TYPE_OBJECT);
 static void
 ar_preimage_init (ArPreimage * preimage)
 {
-  preimage->scalable = FALSE;
   preimage->width = 0;
   preimage->height = 0;
 }
@@ -55,18 +52,12 @@ ar_preimage_finalize (GObject * object)
 {
   ArPreimage *preimage = AR_PREIMAGE (object);
 
-#ifdef HAVE_RSVG
   if (preimage->rsvg_handle != NULL) {
     g_object_unref (preimage->rsvg_handle);
   }
   if (preimage->font_options) {
     cairo_font_options_destroy (preimage->font_options);
   }
-#endif
-
-  if (preimage->pixbuf != NULL) {
-    g_object_unref (preimage->pixbuf);
-  }
 
   G_OBJECT_CLASS (ar_preimage_parent_class)->finalize (object);
 }
@@ -78,9 +69,7 @@ ar_preimage_class_init (ArPreimageClass * klass)
 
   oclass->finalize = ar_preimage_finalize;
 
-#ifdef HAVE_RSVG
   rsvg_init ();
-#endif
 }
 
 /**
@@ -102,8 +91,6 @@ ar_preimage_render (ArPreimage * preimage, gint width, gint height)
   g_return_val_if_fail (width > 0 && height > 0, NULL);
   g_return_val_if_fail (preimage != NULL, NULL);
 
-#ifdef HAVE_RSVG
-  if (preimage->scalable) {     /* Render vector image */
     pixbuf = ar_preimage_render_sub (preimage,
                                         NULL,
                                         width,
@@ -113,13 +100,6 @@ ar_preimage_render (ArPreimage * preimage, gint width, gint height)
                                         ((double) preimage->width),
                                         ((double) height) /
                                         ((double) preimage->height));
-  } else
-#endif /* HAVE_RSVG */
-  {
-    /* Render raster image */
-    pixbuf = gdk_pixbuf_scale_simple (preimage->pixbuf,
-                                      width, height, GDK_INTERP_BILINEAR);
-  }
 
   return pixbuf;
 }
@@ -143,8 +123,6 @@ ar_preimage_render_cairo (ArPreimage * preimage,
   g_return_if_fail (width > 0 && height > 0);
   g_return_if_fail (preimage != NULL);
 
-#ifdef HAVE_RSVG
-  if (preimage->scalable) {     /* Render vector image */
     ar_preimage_render_cairo_sub (preimage,
                                      cr,
                                      NULL,
@@ -155,27 +133,8 @@ ar_preimage_render_cairo (ArPreimage * preimage,
                                      ((double) preimage->width),
                                      ((double) height) /
                                      ((double) preimage->height));
-  } else
-#endif /* HAVE_RSVG */
-  {
-    GdkPixbuf *pixbuf;
-
-    /* FIXMEchpe: we don't really need this fallback anymore */
-    /* Render raster image */
-    pixbuf = gdk_pixbuf_scale_simple (preimage->pixbuf,
-                                      width, height, GDK_INTERP_BILINEAR);
-
-    cairo_save (cr);
-    gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
-    cairo_paint (cr);
-    cairo_restore (cr);
-
-    g_object_unref (pixbuf);
-  }
 }
 
-#ifdef HAVE_RSVG
-
 /* This routine is copied from librsvg:
    Copyright © 2005 Dom Lachowicz <cinamod hotmail com>
    Copyright © 2005 Caleb Moore <c moore student unsw edu au>
@@ -244,8 +203,7 @@ ar_preimage_render_cairo_sub (ArPreimage * preimage,
 {
   cairo_matrix_t matrix;
 
-  if (!preimage->scalable)
-    return;
+  g_return_if_fail (AR_IS_PREIMAGE (preimage));
 
   if (preimage->font_options) {
     cairo_set_antialias (cr, cairo_font_options_get_antialias (preimage->font_options));
@@ -295,9 +253,6 @@ ar_preimage_render_sub (ArPreimage * preimage,
   cairo_surface_t *surface;
   cairo_t *cr;
 
-  if (!preimage->scalable)
-    return NULL;
-
   rowstride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, width);
 
   data = g_try_malloc0 (rowstride * height);
@@ -323,8 +278,6 @@ ar_preimage_render_sub (ArPreimage * preimage,
                                    (GdkPixbufDestroyNotify) g_free, data);
 }
 
-#endif /* HAVE_RSVG */
-
 /**
  * ar_preimage_new_from_file:
  * @filename:
@@ -338,7 +291,6 @@ ArPreimage *
 ar_preimage_new_from_file (const gchar * filename, GError ** error)
 {
   ArPreimage *preimage;
-  GdkPixbuf *pixbuf;
 
   g_return_val_if_fail (filename != NULL, NULL);
 
@@ -346,13 +298,10 @@ ar_preimage_new_from_file (const gchar * filename, GError ** error)
 
   preimage = g_object_new (AR_TYPE_PREIMAGE, NULL);
 
-#ifdef HAVE_RSVG
-  preimage->rsvg_handle = rsvg_handle_new_from_file (filename, NULL);
+  preimage->rsvg_handle = rsvg_handle_new_from_file (filename, error);
   if (preimage->rsvg_handle) {
     RsvgDimensionData data;
 
-    preimage->scalable = TRUE;
-
     rsvg_handle_get_dimensions (preimage->rsvg_handle, &data);
 
     ar_profileend ("creating ArPreimage from %s", filename);
@@ -370,24 +319,10 @@ ar_preimage_new_from_file (const gchar * filename, GError ** error)
 
     return preimage;
   }
-#endif /* HAVE_RSVG */
 
-  /* Not an SVG */
-  preimage->scalable = FALSE;
-
-  pixbuf = gdk_pixbuf_new_from_file (filename, error);
   ar_profileend ("creating ArPreimage from %s", filename);
 
-  if (!pixbuf) {
-    g_object_unref (preimage);
-    return NULL;
-  }
-
-  preimage->pixbuf = pixbuf;
-  preimage->width = gdk_pixbuf_get_width (pixbuf);
-  preimage->height = gdk_pixbuf_get_height (pixbuf);
-
-  return preimage;
+  return NULL;
 }
 
 /**
@@ -401,8 +336,7 @@ void
 ar_preimage_set_font_options (ArPreimage * preimage,
                                  const cairo_font_options_t * font_options)
 {
-#ifdef HAVE_RSVG
-  g_return_if_fail (GAMES_IS_PREIMAGE (preimage));
+  g_return_if_fail (AR_IS_PREIMAGE (preimage));
 
   if (preimage->font_options) {
     cairo_font_options_destroy (preimage->font_options);
@@ -413,21 +347,6 @@ ar_preimage_set_font_options (ArPreimage * preimage,
   } else {
     preimage->font_options = NULL;
   }
-#endif /* HAVE_RSVG */
-}
-
-/**
- * ar_preimage_is_scalable:
- * @preimage:
- *
- * Returns: %TRUE iff @preimage contains an SVG image
- */
-gboolean
-ar_preimage_is_scalable (ArPreimage * preimage)
-{
-  g_return_val_if_fail (GAMES_IS_PREIMAGE (preimage), FALSE);
-
-  return preimage->scalable;
 }
 
 /**
@@ -439,7 +358,7 @@ ar_preimage_is_scalable (ArPreimage * preimage)
 gint
 ar_preimage_get_width (ArPreimage * preimage)
 {
-  g_return_val_if_fail (GAMES_IS_PREIMAGE (preimage), 0);
+  g_return_val_if_fail (AR_IS_PREIMAGE (preimage), 0);
 
   return preimage->width;
 }
@@ -453,34 +372,7 @@ ar_preimage_get_width (ArPreimage * preimage)
 gint
 ar_preimage_get_height (ArPreimage * preimage)
 {
-  g_return_val_if_fail (GAMES_IS_PREIMAGE (preimage), 0);
+  g_return_val_if_fail (AR_IS_PREIMAGE (preimage), 0);
 
   return preimage->height;
 }
-
-/**
- * ar_preimage_render_unscaled_pixbuf:
- * @preimage:
- *
- * Renders @preimage onto a new #GdkPixbuf at its natural size
- *
- * Returns: (transfer full) (allow-none): a reference to a #GdkPixbuf possibly owned by @images which
- * you must not modify; or %NULL if there was an error
- */
-GdkPixbuf *
-ar_preimage_render_unscaled_pixbuf (ArPreimage * preimage)
-{
-  GdkPixbuf *unscaled_pixbuf;
-
-  g_return_val_if_fail (GAMES_IS_PREIMAGE (preimage), NULL);
-
-  if ((unscaled_pixbuf = preimage->pixbuf)) {
-    g_object_ref (unscaled_pixbuf);
-  } else {
-    unscaled_pixbuf = ar_preimage_render (preimage,
-                                             preimage->width,
-                                             preimage->height);
-  }
-
-  return unscaled_pixbuf;
-}
diff --git a/src/lib/ar-preimage.h b/src/lib/ar-preimage.h
index d3aacb6..1d6b14d 100644
--- a/src/lib/ar-preimage.h
+++ b/src/lib/ar-preimage.h
@@ -31,9 +31,9 @@ G_BEGIN_DECLS
 #define AR_TYPE_PREIMAGE             (ar_preimage_get_type ())
 #define AR_PREIMAGE(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), AR_TYPE_PREIMAGE, ArPreimage))
 #define AR_PREIMAGE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), AR_TYPE_PREIMAGE, ArPreimageClass))
-#define GAMES_IS_PREIMAGE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AR_TYPE_PREIMAGE))
-#define GAMES_IS_PREIMAGE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), AR_TYPE_PREIMAGE))
-#define GAMES_GET_PREIMAGE_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), AR_TYPE_PREIMAGE, ArPreimageClass))
+#define AR_IS_PREIMAGE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AR_TYPE_PREIMAGE))
+#define AR_IS_PREIMAGE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), AR_TYPE_PREIMAGE))
+#define AR_GET_PREIMAGE_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), AR_TYPE_PREIMAGE, ArPreimageClass))
 
 typedef struct _ArPreimage ArPreimage;
 
@@ -77,14 +77,10 @@ void ar_preimage_render_cairo_sub (ArPreimage * preimage,
                                       double xzoom,
                                       double yzoom);
 
-gboolean ar_preimage_is_scalable (ArPreimage * preimage);
-
 gint ar_preimage_get_width (ArPreimage * preimage);
 
 gint ar_preimage_get_height (ArPreimage * preimage);
 
-GdkPixbuf *ar_preimage_render_unscaled_pixbuf (ArPreimage * preimage);
-
 G_END_DECLS
 
 #endif /* AR_PREIMAGE_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]