[cairo-commit] cairo-perl Cairo.xs, 1.13, 1.14 CairoFont.xs, 1.7, 1.8 CairoPattern.xs, 1.10, 1.11 CairoSurface.xs, 1.13, 1.14 ChangeLog, 1.28, 1.29 MakeHelper.pm, 1.6, 1.7 Makefile.PL, 1.17, 1.18 cairo-perl-private.h, 1.3, 1.4

Torsten Schoenfeld commit at pdx.freedesktop.org
Thu Aug 10 10:34:42 PDT 2006


Committed by: tsch

Update of /cvs/cairo/cairo-perl
In directory kemper:/tmp/cvs-serv10208

Modified Files:
	Cairo.xs CairoFont.xs CairoPattern.xs CairoSurface.xs 
	ChangeLog MakeHelper.pm Makefile.PL cairo-perl-private.h 
Log Message:
	* Cairo.xs, CairoFont.xs, CairoPattern.xs, CairoSurface.xs,
	MakeHelper.pm, Makefile.PL, cairo-perl-private.h, t/Cairo.t,
	t/CairoFont.t, t/CairoPattern.t, t/CairoSurface.t: Make it
	possible to compile and run the bindings against cairo 1.0.x.  Use
	a package lookup table for patterns and surfaces to work around
	the lack of type accessors.  Add version guards around things that
	were introduced in 1.2.0.

	* CairoSurface.xs: Use OUTLIST for
	cairo_surface_get_device_offset.

	* CairoPattern.xs, CairoSurface.xs, cairo-perl-private.h: Rename
	cair_perl_set_isa to cairo_perl_set_isa.  Doh!

	* t/CairoSurface.t: Explicitly clear the image surface on cairo
	1.0.x before writing it out since 1.0.x doesn't do it for us.  Use
	lexical surface variables to make sure they get destroyed before
	execution ends which in turn makes sure all tests inside callbacks
	are run before Test::More checks if reality matches the test plan.


Index: Cairo.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/Cairo.xs,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Cairo.xs	15 Jul 2006 14:41:11 -0000	1.13
+++ Cairo.xs	10 Aug 2006 17:34:40 -0000	1.14
@@ -48,8 +48,8 @@
 
 /* Copied from Glib/GType.xs. */
 void
-cair_perl_set_isa (const char *child_package,
-                   const char *parent_package)
+cairo_perl_set_isa (const char *child_package,
+                    const char *parent_package)
 {
 	char *child_isa_full;
 	AV *isa;
@@ -293,6 +293,8 @@
 
 void cairo_restore (cairo_t * cr);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 void cairo_push_group (cairo_t *cr);
 
 void cairo_push_group_with_content (cairo_t *cr, cairo_content_t content);
@@ -301,6 +303,8 @@
 
 void cairo_pop_group_to_source (cairo_t *cr);
 
+#endif
+
 void cairo_set_operator (cairo_t * cr, cairo_operator_t op);
 
 void cairo_set_source_rgb (cairo_t *cr, double red, double green, double blue);
@@ -357,8 +361,12 @@
 
 void cairo_new_path (cairo_t * cr);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 void cairo_new_sub_path (cairo_t *cr);
 
+#endif
+
 void cairo_move_to (cairo_t * cr, double x, double y);
 
 void cairo_line_to (cairo_t * cr, double x, double y);
@@ -439,8 +447,12 @@
     OUTPUT:
 	RETVAL
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 void cairo_set_scaled_font (cairo_t *cr, const cairo_scaled_font_t *scaled_font);
 
+#endif
+
 void cairo_show_text (cairo_t * cr, const char * utf8);
 
 ##void cairo_show_glyphs (cairo_t * cr, cairo_glyph_t * glyphs, int num_glyphs);
@@ -544,8 +556,12 @@
 
 cairo_surface_t * cairo_get_target (cairo_t *cr);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 cairo_surface_t * cairo_get_group_target (cairo_t *cr);
 
+#endif
+
 cairo_path_t * cairo_copy_path (cairo_t *cr);
 
 cairo_path_t * cairo_copy_path_flat (cairo_t *cr);

Index: CairoFont.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/CairoFont.xs,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- CairoFont.xs	2 Jul 2006 13:11:26 -0000	1.7
+++ CairoFont.xs	10 Aug 2006 17:34:40 -0000	1.8
@@ -13,8 +13,12 @@
 
 cairo_status_t cairo_font_face_status (cairo_font_face_t * font);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 cairo_font_type_t cairo_font_face_get_type (cairo_font_face_t *font_face);
 
+#endif
+
 void DESTROY (cairo_font_face_t * font)
     CODE:
 	cairo_font_face_destroy (font);
@@ -30,8 +34,12 @@
 
 cairo_status_t cairo_scaled_font_status (cairo_scaled_font_t *scaled_font);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 cairo_font_type_t cairo_scaled_font_get_type (cairo_scaled_font_t *scaled_font);
 
+#endif
+
 ##cairo_status_t cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font, cairo_font_extents_t *extents);
 cairo_font_extents_t * cairo_scaled_font_extents (cairo_scaled_font_t *scaled_font)
     PREINIT:
@@ -42,6 +50,8 @@
     OUTPUT:
 	RETVAL
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 ##void cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font, const char *utf8, cairo_text_extents_t *extents);
 cairo_text_extents_t * cairo_scaled_font_text_extents (cairo_scaled_font_t *scaled_font, const char *utf8)
     PREINIT:
@@ -52,6 +62,8 @@
     OUTPUT:
 	RETVAL
 
+#endif
+
 ##void cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, cairo_glyph_t *glyphs, int num_glyphs, cairo_text_extents_t *extents);
 cairo_text_extents_t * cairo_scaled_font_glyph_extents (cairo_scaled_font_t *scaled_font, ...)
     PREINIT:
@@ -69,6 +81,8 @@
     OUTPUT:
 	RETVAL
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 cairo_font_face_t * cairo_scaled_font_get_font_face (cairo_scaled_font_t *scaled_font);
 
 ##void cairo_scaled_font_get_font_matrix (cairo_scaled_font_t *scaled_font, cairo_matrix_t *font_matrix);
@@ -99,6 +113,8 @@
     OUTPUT:
 	RETVAL
 
+#endif
+
 void DESTROY (cairo_scaled_font_t * font)
     CODE:
 	cairo_scaled_font_destroy (font);

Index: CairoPattern.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/CairoPattern.xs,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- CairoPattern.xs	15 Jul 2006 14:41:11 -0000	1.10
+++ CairoPattern.xs	10 Aug 2006 17:34:40 -0000	1.11
@@ -12,6 +12,7 @@
 static const char *
 get_package (cairo_pattern_t *pattern)
 {
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
 	cairo_pattern_type_t type;
 	const char *package;
 
@@ -40,6 +41,10 @@
 	}
 
 	return package;
+#else
+	const char *package = cairo_perl_package_table_lookup (pattern);
+	return package ? package : "Cairo::Pattern";
+#endif
 }
 
 SV *
@@ -72,35 +77,50 @@
 
 cairo_status_t cairo_pattern_status (cairo_pattern_t *pattern);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 cairo_pattern_type_t cairo_pattern_get_type (cairo_pattern_t *pattern);
 
+#endif
+
 # --------------------------------------------------------------------------- #
 
 MODULE = Cairo::Pattern	PACKAGE = Cairo::SolidPattern	PREFIX = cairo_pattern_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::SolidPattern", "Cairo::Pattern");
+	cairo_perl_set_isa ("Cairo::SolidPattern", "Cairo::Pattern");
 
 # cairo_pattern_t* cairo_pattern_create_rgb (double red, double green, double blue);
 cairo_pattern_t_noinc * cairo_pattern_create_rgb (class, double red, double green, double blue)
     C_ARGS:
 	red, green, blue
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::SolidPattern");
+#endif
 
 # cairo_pattern_t* cairo_pattern_create_rgba (double red, double green, double blue, double alpha);
 cairo_pattern_t_noinc * cairo_pattern_create_rgba (class, double red, double green, double blue, double alpha)
     C_ARGS:
 	red, green, blue, alpha
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::SolidPattern");
+#endif
 
 # --------------------------------------------------------------------------- #
 
 MODULE = Cairo::Pattern	PACKAGE = Cairo::SurfacePattern	PREFIX = cairo_pattern_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::SurfacePattern", "Cairo::Pattern");
+	cairo_perl_set_isa ("Cairo::SurfacePattern", "Cairo::Pattern");
 
 cairo_pattern_t_noinc * create (class, cairo_surface_t * surface);
     CODE:
 	RETVAL = cairo_pattern_create_for_surface (surface);
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::SurfacePattern");
+#endif
     OUTPUT:
 	RETVAL
 
@@ -117,7 +137,7 @@
 MODULE = Cairo::Pattern	PACKAGE = Cairo::Gradient	PREFIX = cairo_pattern_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::Gradient", "Cairo::Pattern");
+	cairo_perl_set_isa ("Cairo::Gradient", "Cairo::Pattern");
 
 void cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern, double offset, double red, double green, double blue);
 
@@ -128,11 +148,14 @@
 MODULE = Cairo::Pattern	PACKAGE = Cairo::LinearGradient	PREFIX = cairo_pattern_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::LinearGradient", "Cairo::Gradient");
+	cairo_perl_set_isa ("Cairo::LinearGradient", "Cairo::Gradient");
 
 cairo_pattern_t_noinc * create (class, double x0, double y0, double x1, double y1);
     CODE:
 	RETVAL = cairo_pattern_create_linear (x0, y0, x1, y1);
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::LinearGradient");
+#endif
     OUTPUT:
 	RETVAL
 
@@ -141,10 +164,13 @@
 MODULE = Cairo::Pattern	PACKAGE = Cairo::RadialGradient	PREFIX = cairo_pattern_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::RadialGradient", "Cairo::Gradient");
+	cairo_perl_set_isa ("Cairo::RadialGradient", "Cairo::Gradient");
 
 cairo_pattern_t_noinc * create (class, double cx0, double cy0, double radius0, double cx1, double cy1, double radius1);
     CODE:
 	RETVAL = cairo_pattern_create_radial (cx0, cy0, radius0, cx1, cy1, radius1);
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::RadialGradient");
+#endif
     OUTPUT:
 	RETVAL

Index: CairoSurface.xs
===================================================================
RCS file: /cvs/cairo/cairo-perl/CairoSurface.xs,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- CairoSurface.xs	15 Jul 2006 14:41:11 -0000	1.13
+++ CairoSurface.xs	10 Aug 2006 17:34:40 -0000	1.14
@@ -9,9 +9,58 @@
 #include <cairo-perl.h>
 #include <cairo-perl-private.h>
 
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+
+static HV *pointer_to_package = NULL;
+
+/* A hex character represents four bits in the address of a pointer, so we'll
+ * need BITS_PER_LONG/4 characters.  That's sizeof (long) * 2.  Add 2 for the
+ * "0x" part.  Add 1 for the trailing \0.  Reasoning courtesy of Robert Love.
+ */
+#define MAX_KEY_LENGTH ((sizeof(long) * 2) + 2 + 1)
+
+/* This stuff is also used in CairoPattern.xs, hence no static on the
+ * functions.
+ */
+
+void
+cairo_perl_package_table_insert (void *pointer, const char *package)
+{
+	char key[MAX_KEY_LENGTH];
+
+	if (!pointer_to_package) {
+		pointer_to_package = newHV ();
+	}
+
+	sprintf (key, "%p", pointer);
+	hv_store (pointer_to_package, key, strlen (key), newSVpv (package, PL_na), 0);
+}
+
+const char *
+cairo_perl_package_table_lookup (void *pointer)
+{
+	char key[MAX_KEY_LENGTH];
+	SV **sv;
+
+	if (!pointer_to_package) {
+		return NULL;
+	}
+
+	sprintf (key, "%p", pointer);
+	sv = hv_fetch (pointer_to_package, key, strlen (key), 0);
+	if (sv && SvOK (*sv)) {
+		return SvPV_nolen (*sv);
+	}
+
+	return NULL;
+}
+
+#endif
+
 static const char *
 get_package (cairo_surface_t *surface)
 {
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
 	cairo_surface_type_t type;
 	const char *package;
 
@@ -50,6 +99,10 @@
 	}
 
 	return package;
+#else
+	const char *package = cairo_perl_package_table_lookup (surface);
+	return package ? package : "Cairo::Surface";
+#endif
 }
 
 SV *
@@ -196,25 +249,26 @@
 	cairo_surface_destroy (surface);
 
 cairo_surface_t_noinc * cairo_surface_create_similar (cairo_surface_t * other, cairo_content_t content, int width, int height);
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+    {
+	const char *package = cairo_perl_package_table_lookup (other);
+	cairo_perl_package_table_insert (RETVAL, package ? package : "Cairo::Surface");
+    }
+#endif
 
 cairo_status_t cairo_surface_status (cairo_surface_t *surface);
 
 void cairo_surface_set_device_offset (cairo_surface_t *surface, double x_offset, double y_offset);
 
-##void cairo_surface_get_device_offset (cairo_surface_t *surface, double *x_offset, double *y_offset);
-void
-cairo_surface_get_device_offset (cairo_surface_t *surface)
-    PREINIT:
-	double x_offset;
-	double y_offset;
-    PPCODE:
-	cairo_surface_get_device_offset (surface, &x_offset, &y_offset);
-	EXTEND (sp, 2);
-	PUSHs (sv_2mortal (newSVnv (x_offset)));
-	PUSHs (sv_2mortal (newSVnv (y_offset)));
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
+void cairo_surface_get_device_offset (cairo_surface_t *surface, OUTLIST double x_offset, OUTLIST double y_offset);
 
 void cairo_surface_set_fallback_resolution (cairo_surface_t *surface, double x_pixels_per_inch, double y_pixels_per_inch);
 
+#endif
+
 ##void cairo_surface_get_font_options (cairo_surface_t *surface, cairo_font_options_t *options);
 cairo_font_options_t * cairo_surface_get_font_options (cairo_surface_t *surface)
     CODE:
@@ -229,10 +283,14 @@
 
 void cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface, int x, int y, int width, int height);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 cairo_surface_type_t cairo_surface_get_type (cairo_surface_t *surface);
 
 cairo_content_t cairo_surface_get_content (cairo_surface_t *surface);
 
+#endif
+
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
 
 cairo_status_t cairo_surface_write_to_png (cairo_surface_t *surface, const char *filename);
@@ -258,17 +316,27 @@
 MODULE = Cairo::Surface	PACKAGE = Cairo::ImageSurface	PREFIX = cairo_image_surface_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::ImageSurface", "Cairo::Surface");
+	cairo_perl_set_isa ("Cairo::ImageSurface", "Cairo::Surface");
 
 ##cairo_surface_t * cairo_image_surface_create (cairo_format_t format, int width, int height);
 cairo_surface_t_noinc * cairo_image_surface_create (class, cairo_format_t format, int width, int height)
     C_ARGS:
 	format, width, height
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::ImageSurface");
+#endif
 
 ##cairo_surface_t * cairo_image_surface_create_for_data (unsigned char *data, cairo_format_t format, int width, int height, int stride);
 cairo_surface_t_noinc * cairo_image_surface_create_for_data (class, unsigned char *data, cairo_format_t format, int width, int height, int stride)
     C_ARGS:
 	data, format, width, height, stride
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::ImageSurface");
+#endif
+
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
 
 # unsigned char * cairo_image_surface_get_data (cairo_surface_t *surface);
 SV *
@@ -283,18 +351,28 @@
 
 cairo_format_t cairo_image_surface_get_format (cairo_surface_t *surface);
 
+#endif
+
 int cairo_image_surface_get_width (cairo_surface_t *surface);
 
 int cairo_image_surface_get_height (cairo_surface_t *surface);
 
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 0)
+
 int cairo_image_surface_get_stride (cairo_surface_t *surface);
 
+#endif
+
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
 
 ##cairo_surface_t * cairo_image_surface_create_from_png (const char *filename);
 cairo_surface_t_noinc * cairo_image_surface_create_from_png (class, const char *filename)
     C_ARGS:
 	filename
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::ImageSurface");
+#endif
 
 ##cairo_surface_t * cairo_image_surface_create_from_png_stream (cairo_read_func_t read_func, void *closure);
 cairo_surface_t_noinc *
@@ -306,6 +384,9 @@
 	RETVAL = cairo_image_surface_create_from_png_stream (
 			read_func_marshaller, callback);
 	cairo_perl_callback_free (callback);
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::ImageSurface");
+#endif
     OUTPUT:
 	RETVAL
 
@@ -318,12 +399,16 @@
 MODULE = Cairo::Surface	PACKAGE = Cairo::PdfSurface	PREFIX = cairo_pdf_surface_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::PdfSurface", "Cairo::Surface");
+	cairo_perl_set_isa ("Cairo::PdfSurface", "Cairo::Surface");
 
 ##cairo_surface_t * cairo_pdf_surface_create (const char *filename, double width_in_points, double height_in_points);
 cairo_surface_t_noinc * cairo_pdf_surface_create (class, const char *filename, double width_in_points, double height_in_points)
     C_ARGS:
 	filename, width_in_points, height_in_points
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::PdfSurface");
+#endif
 
 ##cairo_surface_t * cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
 cairo_surface_t_noinc *
@@ -339,6 +424,9 @@
 	cairo_surface_set_user_data (
 		RETVAL, (const cairo_user_data_key_t *) &callback, callback,
 		(cairo_destroy_func_t) cairo_perl_callback_free);
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::PdfSurface");
+#endif
     OUTPUT:
 	RETVAL
 
@@ -353,12 +441,16 @@
 MODULE = Cairo::Surface	PACKAGE = Cairo::PsSurface	PREFIX = cairo_ps_surface_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::PsSurface", "Cairo::Surface");
+	cairo_perl_set_isa ("Cairo::PsSurface", "Cairo::Surface");
 
 ##cairo_surface_t * cairo_ps_surface_create (const char *filename, double width_in_points, double height_in_points);
 cairo_surface_t_noinc * cairo_ps_surface_create (class, const char *filename, double width_in_points, double height_in_points)
     C_ARGS:
 	filename, width_in_points, height_in_points
+    POSTCALL:
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::PsSurface");
+#endif
 
 ##cairo_surface_t * cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, void *closure, double width_in_points, double height_in_points);
 cairo_surface_t_noinc *
@@ -374,6 +466,9 @@
 	cairo_surface_set_user_data (
 		RETVAL, (const cairo_user_data_key_t *) &callback, callback,
 		(cairo_destroy_func_t) cairo_perl_callback_free);
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+	cairo_perl_package_table_insert (RETVAL, "Cairo::PsSurface");
+#endif
     OUTPUT:
 	RETVAL
 
@@ -389,12 +484,15 @@
 
 # --------------------------------------------------------------------------- #
 
+# The SVG surface doesn't need the special package treatment because it didn't
+# exist in cairo 1.0.
+
 #ifdef CAIRO_HAS_SVG_SURFACE
 
 MODULE = Cairo::Surface	PACKAGE = Cairo::SvgSurface	PREFIX = cairo_svg_surface_
 
 BOOT:
-	cair_perl_set_isa ("Cairo::SvgSurface", "Cairo::Surface");
+	cairo_perl_set_isa ("Cairo::SvgSurface", "Cairo::Surface");
 
 # cairo_surface_t * cairo_svg_surface_create (const char *filename, double width_in_points, double height_in_points);
 cairo_surface_t_noinc *

Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-perl/ChangeLog,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ChangeLog	15 Jul 2006 16:05:17 -0000	1.28
+++ ChangeLog	10 Aug 2006 17:34:40 -0000	1.29
@@ -1,3 +1,25 @@
+2006-08-10	tsch
+
+	* Cairo.xs, CairoFont.xs, CairoPattern.xs, CairoSurface.xs,
+	MakeHelper.pm, Makefile.PL, cairo-perl-private.h, t/Cairo.t,
+	t/CairoFont.t, t/CairoPattern.t, t/CairoSurface.t: Make it
+	possible to compile and run the bindings against cairo 1.0.x.  Use
+	a package lookup table for patterns and surfaces to work around
+	the lack of type accessors.  Add version guards around things that
+	were introduced in 1.2.0.
+
+	* CairoSurface.xs: Use OUTLIST for
+	cairo_surface_get_device_offset.
+
+	* CairoPattern.xs, CairoSurface.xs, cairo-perl-private.h: Rename
+	cair_perl_set_isa to cairo_perl_set_isa.  Doh!
+
+	* t/CairoSurface.t: Explicitly clear the image surface on cairo
+	1.0.x before writing it out since 1.0.x doesn't do it for us.  Use
+	lexical surface variables to make sure they get destroyed before
+	execution ends which in turn makes sure all tests inside callbacks
+	are run before Test::More checks if reality matches the test plan.
+
 2006-07-15	tsch
 
 	* Cairo.pm, NEWS, README: Beta release 0.90.

Index: MakeHelper.pm
===================================================================
RCS file: /cvs/cairo/cairo-perl/MakeHelper.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- MakeHelper.pm	3 Jun 2006 14:21:09 -0000	1.6
+++ MakeHelper.pm	10 Aug 2006 17:34:40 -0000	1.7
@@ -345,8 +345,30 @@
 	{
 		my $name = name($_);
 		my @enum_values = @{$enums{$_}};
+
+		# Create stub converters to make xsubpp happy even if the
+		# current cairo doesn't have this type
+		unless (@enum_values) {
+			print ENUMS <<"EOS";
+int
+cairo_${name}_from_sv (SV * $name)
+{
+	return 0;
+}
+
+SV *
+cairo_${name}_to_sv (int val)
+{
+	return &PL_sv_undef;
+}
+
+EOS
+
+			# Skip to next enum value
+			next;
+		}
+
 		my $value_list = join ", ", map { canonicalize($_, $enum_values[0]) } @enum_values[1..$#enum_values];
-		
 		my $tree_from = if_tree_from (@enum_values);
 		my $tree_to = if_tree_to (@enum_values);
 

Index: Makefile.PL
===================================================================
RCS file: /cvs/cairo/cairo-perl/Makefile.PL,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- Makefile.PL	15 Jul 2006 14:41:11 -0000	1.17
+++ Makefile.PL	10 Aug 2006 17:34:40 -0000	1.18
@@ -12,7 +12,7 @@
 use MakeHelper;
 
 my %extreqs = (
-	'cairo' => '1.2.0',
+	'cairo' => '1.0.0',
 );
 
 # Unfortunately we already need these prereqs for writing the Makefile ...
@@ -51,12 +51,7 @@
 mkdir $autogen_dir unless (-d $autogen_dir);
 $MakeHelper::autogen_dir = $autogen_dir;
 
-my %cairo_cfg;
-eval { %cairo_cfg = ExtUtils::PkgConfig->find ("cairo >= $extreqs{cairo}"); };
-if ($@) {
-	warn $@;
-        die "*** please use Cairo 0.03 to work with cairo 1.0.x\n";
-}
+my %cairo_cfg = ExtUtils::PkgConfig->find ("cairo >= $extreqs{cairo}");
 
 my %backend_macros = (
 	'cairo_pdf_surface_t' => 'CAIRO_HAS_PDF_SURFACE',
@@ -96,7 +91,6 @@
 		CAIRO_EXTEND_NONE
 		CAIRO_EXTEND_REPEAT
 		CAIRO_EXTEND_REFLECT
-		CAIRO_EXTEND_PAD
 	/],
 	cairo_fill_rule_t => [qw/
 		CAIRO_FILL_RULE_
@@ -118,13 +112,6 @@
 		CAIRO_FONT_SLANT_ITALIC
 		CAIRO_FONT_SLANT_OBLIQUE
 	/],
-	cairo_font_type_t => [qw/
-		CAIRO_FONT_TYPE_
-		CAIRO_FONT_TYPE_TOY
-		CAIRO_FONT_TYPE_FT
-		CAIRO_FONT_TYPE_WIN32
-		CAIRO_FONT_TYPE_ATSUI
-	/],
 	cairo_font_weight_t => [qw/
 		CAIRO_FONT_WEIGHT_
 		CAIRO_FONT_WEIGHT_NORMAL
@@ -136,7 +123,6 @@
 		CAIRO_FORMAT_RGB24
 		CAIRO_FORMAT_A8
 		CAIRO_FORMAT_A1
-		CAIRO_FORMAT_RGB16_565
 	/],
 	cairo_hint_metrics_t => [qw/
 		CAIRO_HINT_METRICS_
@@ -188,13 +174,6 @@
 		CAIRO_PATH_CURVE_TO
 		CAIRO_PATH_CLOSE_PATH
 	/],
-	cairo_pattern_type_t => [qw/
-		CAIRO_PATTERN_TYPE_
-		CAIRO_PATTERN_TYPE_SOLID
-		CAIRO_PATTERN_TYPE_SURFACE
-		CAIRO_PATTERN_TYPE_LINEAR
-		CAIRO_PATTERN_TYPE_RADIAL
-	/],
 	cairo_status_t => [qw/
 		CAIRO_STATUS_
 		CAIRO_STATUS_SUCCESS
@@ -217,7 +196,6 @@
 		CAIRO_STATUS_INVALID_VISUAL
 		CAIRO_STATUS_FILE_NOT_FOUND
 		CAIRO_STATUS_INVALID_DASH
-		CAIRO_STATUS_INVALID_DSC_COMMENT
 	/],
 	cairo_subpixel_order_t => [qw/
 		CAIRO_SUBPIXEL_ORDER_
@@ -227,7 +205,40 @@
 		CAIRO_SUBPIXEL_ORDER_VRGB
 		CAIRO_SUBPIXEL_ORDER_VBGR
 	/],
-	cairo_surface_type_t => [qw/
+);
+
+my $have_cairo_1_2 = ExtUtils::PkgConfig->atleast_version("cairo", "1.2.0");
+
+if ($have_cairo_1_2) {
+	my %new = (
+		cairo_extend_t => [qw/CAIRO_EXTEND_PAD/],
+		cairo_format_t => [qw/CAIRO_FORMAT_RGB16_565/],
+		cairo_status_t => [qw/CAIRO_STATUS_INVALID_DSC_COMMENT/],
+	);
+
+	foreach my $enum (keys %new) {
+		foreach my $value (@{$new{$enum}}) {
+			push @{$enums{$enum}}, $value;
+		}
+	}
+
+	$enums{cairo_font_type_t} = [qw/
+		CAIRO_FONT_TYPE_
+		CAIRO_FONT_TYPE_TOY
+		CAIRO_FONT_TYPE_FT
+		CAIRO_FONT_TYPE_WIN32
+		CAIRO_FONT_TYPE_ATSUI
+	/];
+
+	$enums{cairo_pattern_type_t} = [qw/
+		CAIRO_PATTERN_TYPE_
+		CAIRO_PATTERN_TYPE_SOLID
+		CAIRO_PATTERN_TYPE_SURFACE
+		CAIRO_PATTERN_TYPE_LINEAR
+		CAIRO_PATTERN_TYPE_RADIAL
+	/];
+
+	$enums{cairo_surface_type_t} = [qw/
 		CAIRO_SURFACE_TYPE_
 		CAIRO_SURFACE_TYPE_IMAGE
 		CAIRO_SURFACE_TYPE_PDF
@@ -240,13 +251,22 @@
 		CAIRO_SURFACE_TYPE_BEOS
 		CAIRO_SURFACE_TYPE_DIRECTFB
 		CAIRO_SURFACE_TYPE_SVG
-	/],
-	cairo_svg_version_t => [qw/
+	/];
+
+	$enums{cairo_svg_version_t} = [qw/
 		CAIRO_SVG_VERSION_
 		CAIRO_SVG_VERSION_1_1
 		CAIRO_SVG_VERSION_1_2
-	/],
-);
+	/];
+} else {
+	# We need to create empty enum entries for new types so that typemaps
+	# are generated for them.  xsubpp demands typemaps even if the code is
+	# #if'd out.
+	$enums{cairo_font_type_t} = [];
+	$enums{cairo_pattern_type_t} = [];
+	$enums{cairo_surface_type_t} = [];
+	$enums{cairo_svg_version_t} = [];
+}
 
 MakeHelper::do_enums (\%enums);
 

Index: cairo-perl-private.h
===================================================================
RCS file: /cvs/cairo/cairo-perl/cairo-perl-private.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cairo-perl-private.h	15 Jul 2006 14:41:11 -0000	1.3
+++ cairo-perl-private.h	10 Aug 2006 17:34:40 -0000	1.4
@@ -10,8 +10,16 @@
 #ifndef _CAIRO_PERL_PRIVATE_H_
 #define _CAIRO_PERL_PRIVATE_H_
 
-void cair_perl_set_isa (const char * child_package, const char * parent_package);
+void cairo_perl_set_isa (const char * child_package, const char * parent_package);
 
 cairo_matrix_t * cairo_perl_copy_matrix (cairo_matrix_t *matrix);
 
+#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 2, 0)
+
+void cairo_perl_package_table_insert (void *pointer, const char *package);
+
+const char * cairo_perl_package_table_lookup (void *pointer);
+
+#endif
+
 #endif /* _CAIRO_PERL_PRIVATE_H_ */



More information about the cairo-commit mailing list