adg: provided cairo-gobject fallbacks
authorNicola Fontana <ntd@entidi.it>
Thu, 4 Apr 2013 23:17:34 +0000 (5 01:17 +0200)
committerNicola Fontana <ntd@entidi.it>
Fri, 5 Apr 2013 13:00:58 +0000 (5 15:00 +0200)
Consider cairo-gobject entirely optional and implement fallbacks for
every GObject wrapper provided by it, i.e. only for cairo_pattern_t.

configure.ac
docs/adg/adg-docs.xml
src/adg/Makefile.am
src/adg/adg-cairo-fallback.c [new file with mode: 0644]
src/adg/adg-cairo-fallback.h [moved from src/adg/adg-matrix-fallback.h with 66% similarity]
src/adg/adg-entity.c
src/adg/adg-fill-style.c
src/adg/adg-gtk-area-gtk2.c
src/adg/adg-gtk-area.c
src/adg/adg-matrix.c

index 1e4e56c..d88c8f1 100644 (file)
@@ -9,7 +9,6 @@ m4_define([cpml_lt_version],[2:0:0])
 m4_define([gtkdoc_prereq],[1.12])dnl Support introspection annotations
 m4_define([gobject_prereq],[2.10.1])
 m4_define([cairo_prereq],[1.7.4])
-m4_define([cairo_gobject_prereq],cairo_prereq)
 m4_define([gtk2_prereq],[2.12.0])
 m4_define([gtk3_prereq],[3.0.0])
 m4_define([pangocairo_prereq],[1.18.0])
index b065616..53b6a77 100644 (file)
@@ -24,6 +24,7 @@
       <title>GBoxed types</title>
       <xi:include href="xml/adg-point.xml"/>
       <xi:include href="xml/adg-matrix.xml"/>
+      <xi:include href="xml/adg-cairo-fallback.xml"/>
     </chapter>
   </part>
 
index 583ef17..7fb5117 100644 (file)
@@ -53,6 +53,7 @@ built_h_sources=              adg-type-builtins.h
 private_h_sources=             adg-adim-private.h \
                                adg-alignment-private.h \
                                adg-arrow-private.h \
+                               adg-cairo-fallback.h \
                                adg-canvas-private.h \
                                adg-color-style-private.h \
                                adg-container-private.h \
@@ -70,7 +71,6 @@ private_h_sources=            adg-adim-private.h \
                                adg-line-style-private.h \
                                adg-logo-private.h \
                                adg-marker-private.h \
-                               adg-matrix-fallback.h \
                                adg-model-private.h \
                                adg-path-private.h \
                                adg-projection-private.h \
@@ -87,6 +87,7 @@ built_private_h_sources=      adg-marshal.h
 c_sources=                     adg-adim.c \
                                adg-alignment.c \
                                adg-arrow.c \
+                               adg-cairo-fallback.c \
                                adg-canvas.c \
                                adg-color-style.c \
                                adg-container.c \
diff --git a/src/adg/adg-cairo-fallback.c b/src/adg/adg-cairo-fallback.c
new file mode 100644 (file)
index 0000000..eb20a6f
--- /dev/null
@@ -0,0 +1,81 @@
+/* ADG - Automatic Drawing Generation
+ * Copyright (C) 2007,2008,2009,2010,2011,2012,2013  Nicola Fontana <ntd at entidi.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+
+/**
+ * SECTION:adg-cairo-fallback
+ * @title: Cairo wrappers
+ * @short_description: GObject wrappers for cairo structs.
+ *
+ * If GObject support has not been compiled in cairo, either by
+ * explicitely disabling it or because the installed cairo version
+ * does not provide them, a compatible selection of wrappers used
+ * by ADG is provided anyway.
+ *
+ * Since: 1.0
+ **/
+
+
+#include "adg-internal.h"
+#include <string.h>
+#include <math.h>
+
+#include "adg-cairo-fallback.h"
+
+
+#ifdef ADG_MISSING_GBOXED_MATRIX
+
+GType
+cairo_gobject_matrix_get_type(void)
+{
+    static GType matrix_type = 0;
+
+    if (G_UNLIKELY(matrix_type == 0))
+        matrix_type = g_boxed_type_register_static("CairoMatrix",
+                                                   (GBoxedCopyFunc) cairo_gobject_cairo_matrix_copy,
+                                                   g_free);
+
+    return matrix_type;
+}
+
+cairo_matrix_t *
+cairo_gobject_cairo_matrix_copy(const cairo_matrix_t *matrix)
+{
+    return g_memdup(matrix, sizeof(cairo_matrix_t));
+}
+
+#endif /* ADG_MISSING_GBOXED_MATRIX */
+
+
+#ifdef ADG_MISSING_GBOXED_PATTERN
+
+GType
+cairo_gobject_pattern_get_type(void)
+{
+    static GType pattern_type = 0;
+
+    if (G_UNLIKELY(pattern_type == 0))
+        pattern_type = g_boxed_type_register_static("CairoPattern",
+                                                    (GBoxedCopyFunc) cairo_pattern_reference,
+                                                    (GBoxedFreeFunc) cairo_pattern_destroy);
+
+    return pattern_type;
+}
+
+#endif /* ADG_MISSING_GBOXED_PATTERN */
similarity index 66%
rename from src/adg/adg-matrix-fallback.h
rename to src/adg/adg-cairo-fallback.h
index a598c86..821d083 100644 (file)
  */
 
 
-#ifndef __ADG_MATRIX_FALLBACK_H__
-#define __ADG_MATRIX_FALLBACK_H__
+#ifndef __ADG_CAIRO_FALLBACK_H__
+#define __ADG_CAIRO_FALLBACK_H__
 
 
 G_BEGIN_DECLS
 
 
-/* Backward compatibility: old cairo releases did not wrap cairo_matrix_t */
+/* Provide some GObject wrappers around cairo_matrix_t and cairo_pattern_t
+ * if cairo-gobject support has not been provided by cairo itself or
+ * if the cairo version is too old to provide them. */
+
 
 #ifndef CAIRO_GOBJECT_TYPE_MATRIX
 
@@ -40,7 +43,19 @@ cairo_matrix_t *cairo_gobject_cairo_matrix_copy
 #endif /* CAIRO_GOBJECT_TYPE_MATRIX */
 
 
+#ifndef CAIRO_GOBJECT_TYPE_PATTERN
+
+#define ADG_MISSING_GBOXED_PATTERN          1
+#define CAIRO_GOBJECT_TYPE_PATTERN          (cairo_gobject_pattern_get_type())
+
+GType   cairo_gobject_pattern_get_type      (void) G_GNUC_CONST;
+cairo_pattern_t *
+        cairo_gobject_cairo_pattern_copy    (const cairo_pattern_t  *pattern);
+
+#endif /* CAIRO_GOBJECT_TYPE_PATTERN */
+
+
 G_END_DECLS
 
 
-#endif /* __ADG_MATRIX_FALLBACK_H__ */
+#endif /* __ADG_CAIRO_FALLBACK_H__ */
index c2c872f..669c9cb 100644 (file)
@@ -84,7 +84,7 @@
 #include "adg-style.h"
 #include "adg-model.h"
 #include "adg-point.h"
-#include "adg-matrix-fallback.h"
+#include "adg-cairo-fallback.h"
 
 #include "adg-entity-private.h"
 
index 9903afb..8e8b0dd 100644 (file)
@@ -53,6 +53,7 @@
 
 #include "adg-internal.h"
 #include "adg-style.h"
+#include "adg-cairo-fallback.h"
 
 #include "adg-fill-style.h"
 #include "adg-fill-style-private.h"
index 1855bb2..57eced5 100644 (file)
@@ -68,7 +68,7 @@
 #include "adg-title-block.h"
 #include <adg-canvas.h>
 #include "adg-gtk-utils.h"
-#include "adg-matrix-fallback.h"
+#include "adg-cairo-fallback.h"
 
 #include "adg-gtk-area.h"
 #include "adg-gtk-area-private.h"
index 464cffe..6921dc4 100644 (file)
@@ -84,7 +84,7 @@
 #include "adg-title-block.h"
 #include <adg-canvas.h>
 #include "adg-gtk-utils.h"
-#include "adg-matrix-fallback.h"
+#include "adg-cairo-fallback.h"
 
 #include "adg-gtk-area.h"
 #include "adg-gtk-area-private.h"
index 469e155..059f086 100644 (file)
@@ -24,9 +24,8 @@
  * @title: Matrix
  * @short_description: #cairo_matrix_t enhancements and utilities.
  *
- * This API provides a #GBoxed wrapper around #cairo_matrix_t
- * (if not yet provided by cairo-gobject) * and augments its methods
- * with some useful addition.
+ * The following functions augment the cairo_matrix_t available methods
+ * providing some useful addition.
  *
  * Since: 1.0
  **/
 #include <string.h>
 #include <math.h>
 
-#include "adg-matrix-fallback.h"
-
-
-#ifdef ADG_MISSING_GBOXED_MATRIX
-
-GType
-cairo_gobject_matrix_get_type(void)
-{
-    static GType matrix_type = 0;
-
-    if (G_UNLIKELY(matrix_type == 0))
-        matrix_type = g_boxed_type_register_static("CairoMatrix",
-                                                   (GBoxedCopyFunc) cairo_gobject_cairo_matrix_copy,
-                                                   g_free);
-
-    return matrix_type;
-}
-
-cairo_matrix_t *
-cairo_gobject_cairo_matrix_copy(const cairo_matrix_t *matrix)
-{
-    return g_memdup(matrix, sizeof(cairo_matrix_t));
-}
-
-#endif /* ADG_MISSING_GBOXED_MATRIX */
-
 
 /**
  * adg_matrix_identity: