[cairo-commit] cairo-perl/examples/png caps_joins.pl, 1.1, 1.2 hering.pl, 1.1, 1.2 outline.pl, 1.1, 1.2 spiral.pl, 1.1, 1.2 splines_tolerance.pl, 1.1, 1.2 stars.pl, 1.1, 1.2

Torsten Schoenfeld commit at pdx.freedesktop.org
Tue Jul 12 13:29:51 PDT 2005


Committed by: tsch

Update of /cvs/cairo/cairo-perl/examples/png
In directory gabe:/tmp/cvs-serv30085/examples/png

Modified Files:
	caps_joins.pl hering.pl outline.pl spiral.pl 
	splines_tolerance.pl stars.pl 
Log Message:
	* Cairo.pm, Cairo.xs, t/Cairo.t: Replace the %backends hash with
	Cairo::HAS_PS_SURFACE, HAS_PDF_SURFACE, HAS_XLIB_SURFACE,
	HAS_FT_FONT and HAS_PNG_FUNCTIONS.

	* Cairo.pm, CairoPattern.xs, CairoSurface.xs, Makefile.PL:
	Implement the pattern and surface hierarchy suggested by the
	language bindings guidelines.

	* Cairo.xs: Use Cairo::Context for the namespace of cairo_t,
	instead of just Cairo, as suggested by the guidelines.

	* Cairo.xs, CairoFont.xs, CairoMatrix.xs, CairoPattern.xs,
	CairoSurface.xs, cairo-perl.h: Add new, remove old API.  Shuffle
	some things around.

	* Cairo.xs: Convert font and text extents and glyphs to and from
	native Perl data structures.

	* Cairo.xs, cairo-perl.h, cairo-perl.typemap: Remove everything
	that cannot be used from Perl, like the XLib and Glitz stuff.

	* CairoPath.xs, t/CairoPath.t: Add support for cairo_path_t,
	including a nice tied interface that lets you iterate over paths
	as if they were normal array references.

	* MakeHelper.pm: Extend the typemap generator to support "const"
	and "_noinc" types.  Change the enum handling to use the Glib
	convention, i.e. lowercase and hyphen instead of underscore.

	* Makefile.PL, README: Use ExtUtils::Depends.

	* examples/simple.pl, examples/png/caps_join.pl,
	examples/png/hering.pl, examples/png/outline.pl,
	examples/png/spiral.pl, examples/png/splines_tolerance.pl,
	examples/png/stars.pl: Update the examples to make them work again
	after all those API changes.

	* t/Cairo.t, t/CairoFont.t, CairoMatrix.t, CairoPattern.t,
	CairoSurface.t: Redo and/or expand the whole test suite.


Index: caps_joins.pl
===================================================================
RCS file: /cvs/cairo/cairo-perl/examples/png/caps_joins.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- caps_joins.pl	28 Nov 2004 05:30:30 -0000	1.1
+++ caps_joins.pl	12 Jul 2005 20:29:49 -0000	1.2
@@ -12,25 +12,21 @@
 };
 
 {
-	my $cr;
-
-	$cr = Cairo->create;
+	my $surf = Cairo::ImageSurface->create ('argb32', WIDTH, HEIGHT);
+	my $cr = Cairo::Context->create ($surf);
 
 	$0 =~ /(.*)\.pl/;
 	my $out = "$1.png";
 
-	open OUT, ">$out" or die "unable to open ($out) for output";
-
-	$cr->set_target_png (*OUT, 'ARGB32', WIDTH, HEIGHT);
-
 	$cr->rectangle (0, 0, WIDTH, HEIGHT);
-	$cr->set_rgb_color (1, 1, 1);
+	$cr->set_source_rgb (1, 1, 1);
 	$cr->fill;
 
 	draw_caps_joins ($cr, WIDTH, HEIGHT);
 
 	$cr->show_page;
-	close OUT;
+
+	$surf->write_to_png ($out);
 }
 
 sub stroke_v_twice
@@ -48,8 +44,8 @@
 	$cr->save;
 	{
 		$cr->set_line_width (2.0);
-		$cr->set_line_cap ('BUTT');
-		$cr->set_rgb_color (1, 1, 1);
+		$cr->set_line_cap ('butt');
+		$cr->set_source_rgb (1, 1, 1);
 		$cr->stroke;
 	}
 	$cr->restore;
@@ -64,23 +60,23 @@
 	my $line_width = $height / 12 & (~1);
 
 	$cr->set_line_width ($line_width);
-	$cr->set_rgb_color (0, 0, 0);
+	$cr->set_source_rgb (0, 0, 0);
 
 	$cr->translate ($line_width, $line_width);
 	$width -= 2 * $line_width;
 
-	$cr->set_line_join ('BEVEL');
-	$cr->set_line_cap ('BUTT');
+	$cr->set_line_join ('bevel');
+	$cr->set_line_cap ('butt');
 	stroke_v_twice ($cr, $width, $height);
 
 	$cr->translate (0, $height / 4 - $line_width);
-	$cr->set_line_join ('MITER');
-	$cr->set_line_cap ('SQUARE');
+	$cr->set_line_join ('miter');
+	$cr->set_line_cap ('square');
 	stroke_v_twice ($cr, $width, $height);
 
 	$cr->translate (0, $height / 4 - $line_width);
-	$cr->set_line_join ('ROUND');
-	$cr->set_line_cap ('ROUND');
+	$cr->set_line_join ('round');
+	$cr->set_line_cap ('round');
 	stroke_v_twice ($cr, $width, $height);
 }
 

Index: hering.pl
===================================================================
RCS file: /cvs/cairo/cairo-perl/examples/png/hering.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hering.pl	28 Nov 2004 05:30:30 -0000	1.1
+++ hering.pl	12 Jul 2005 20:29:49 -0000	1.2
@@ -24,52 +24,48 @@
 };
 
 {
-	my $cr;
-
-	$cr = Cairo->create;
+	my $surf = Cairo::ImageSurface->create ('argb32', WIDTH, HEIGHT);
+	my $cr = Cairo::Context->create ($surf);
 
 	$0 =~ /(.*)\.pl/;
 	my $out = "$1.png";
 
-	open OUT, ">$out" or die "unable to open ($out) for output";
-
-	$cr->set_target_png (*OUT, 'ARGB32', WIDTH, HEIGHT);
-
 	$cr->rectangle (0, 0, WIDTH, HEIGHT);
-	$cr->set_rgb_color (1, 1, 1);
+	$cr->set_source_rgb (1, 1, 1);
 	$cr->fill;
 
 	draw_hering ($cr, WIDTH, HEIGHT);
 
 	$cr->show_page;
-	close OUT;
+
+	$surf->write_to_png ($out);
 }
 
 sub draw_hering
 {
 	my ($cr, $width, $height) = @_;
 
-	$cr->set_rgb_color (0, 0, 0);
+	$cr->set_source_rgb (0, 0, 0);
 	$cr->set_line_width (2.0);
 
 	$cr->save;
 	{
 		$cr->translate ($width / 2, $height / 2);
 		$cr->rotate (MAX_THETA);
-	
+
 		for (my $i=0; $i < LINES; $i++)
 		{
 		$cr->move_to (-2 * $width, 0);
 		$cr->line_to (2 * $width, 0);
 		$cr->stroke;
-		
+
 		$cr->rotate (- THETA_INC);
 		}
 	}
 	$cr->restore;
 
 	$cr->set_line_width (6);
-	$cr->set_rgb_color (1, 0, 0);
+	$cr->set_source_rgb (1, 0, 0);
 
 	$cr->move_to ($width / 4, 0);
 	$cr->rel_line_to (0, $height);

Index: outline.pl
===================================================================
RCS file: /cvs/cairo/cairo-perl/examples/png/outline.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- outline.pl	28 Nov 2004 05:30:30 -0000	1.1
+++ outline.pl	12 Jul 2005 20:29:49 -0000	1.2
@@ -11,63 +11,34 @@
 };
 
 {
-	my $cr;
-
-	$cr = Cairo->create;
+	my $surf = Cairo::ImageSurface->create ('argb32', WIDTH, HEIGHT);
+	my $cr = Cairo::Context->create ($surf);
 
 	$0 =~ /(.*)\.pl/;
 	my $out = "$1.png";
 
-	open OUT, ">$out" or die "unable to open ($out) for output";
-
-	$cr->set_target_png (*OUT, 'ARGB32', WIDTH, HEIGHT);
-
 	$cr->rectangle (0, 0, WIDTH, HEIGHT);
-	$cr->set_rgb_color (1, 1, 1);
+	$cr->set_source_rgb (1, 1, 1);
 	$cr->fill;
 
 	draw_outlines ($cr, WIDTH, HEIGHT);
 
 	$cr->show_page;
-	close OUT;
+
+	$surf->write_to_png ($out);
 }
 
 sub create_gradient
 {
 	my ($cr, $width, $height) = @_;
 
-	my $gradient;
-	my $matrix;
-	my $gradient_pattern;
-
-	$cr->save;
-
-	$gradient = $cr->current_target_surface->create_similar
-			('ARGB32', 3, 2);
-	$cr->set_target_surface ($gradient);
-
-	$cr->set_rgb_color (0, 0, 0);
-	$cr->rectangle (0, 0, 1, 2);
-	$cr->fill;
-
-	$cr->set_rgb_color (1, 1, 1);
-	$cr->rectangle (1, 0, 1, 2);
-	$cr->fill;
-
-	$cr->set_rgb_color (0, 0, 0);
-	$cr->rectangle (2, 0, 1, 2);
-	$cr->fill;
-
-	$cr->restore;
+	my $gradient = Cairo::LinearGradient->create (0, 0, $width, 0);
 
-	$matrix = Cairo::Matrix->create;
-	$matrix->scale (2.0 / $width, 1.0 / $height);
-	
-	$gradient_pattern = Cairo::Pattern::->create_for_surface ($gradient);
-	$gradient_pattern->set_matrix ($matrix);
-	$gradient_pattern->set_filter ('BILINEAR');
+	$gradient->add_color_stop_rgb (0.0, 0., 0., 0.);
+	$gradient->add_color_stop_rgb (0.5, 1., 1., 1.);
+	$gradient->add_color_stop_rgb (1.0, 0., 0., 0.);
 
-	return $gradient_pattern;
+	return $gradient;
 }
 
 sub draw_outlines
@@ -83,15 +54,15 @@
 
 	$gradient = create_gradient ($cr, $width, $height);
 
-	$cr->set_pattern ($gradient);
+	$cr->set_source ($gradient);
 	draw_flat ($cr, $width, $height);
 
 	$cr->translate ($width + $pad, 0);
-	$cr->set_pattern ($gradient);
+	$cr->set_source ($gradient);
 	draw_tent ($cr, $width, $height);
 
 	$cr->translate ($width + $pad, 0);
-	$cr->set_pattern ($gradient);
+	$cr->set_source ($gradient);
 	draw_cylinder ($cr, $width, $height);
 
 	$cr->restore;
@@ -100,7 +71,7 @@
 sub draw_flat
 {
 	my ($cr, $width, $height) = @_;
-	
+
 	my $hwidth = $width / 2.0;
 
 	$cr->rectangle (0, $hwidth, $width, $height - $hwidth);

Index: spiral.pl
===================================================================
RCS file: /cvs/cairo/cairo-perl/examples/png/spiral.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- spiral.pl	28 Nov 2004 05:30:30 -0000	1.1
+++ spiral.pl	12 Jul 2005 20:29:49 -0000	1.2
@@ -11,31 +11,27 @@
 };
 
 {
-	my $cr;
-
-	$cr = Cairo->create;
+	my $surf = Cairo::ImageSurface->create ('argb32', WIDTH, HEIGHT);
+	my $cr = Cairo::Context->create ($surf);
 
 	$0 =~ /(.*)\.pl/;
 	my $out = "$1.png";
 
-	open OUT, ">$out" or die "unable to open ($out) for output";
-
-	$cr->set_target_png (*OUT, 'ARGB32', WIDTH, HEIGHT);
-
 	$cr->rectangle (0, 0, WIDTH, HEIGHT);
-	$cr->set_rgb_color (1, 1, 1);
+	$cr->set_source_rgb (1, 1, 1);
 	$cr->fill;
 
 	draw_spiral ($cr, WIDTH, HEIGHT);
 
 	$cr->show_page;
-	close OUT;
+
+	$surf->write_to_png ($out);
 }
 
 sub draw_spiral
 {
 	my ($cr, $width, $height) = @_;
-	
+
 	my $wd = .02 * $width;
 	my $hd = .02 * $height;
 
@@ -51,6 +47,6 @@
 		$cr->rel_line_to ($width - $wd * (2 * $i + 1), 0);
 	}
 
-	$cr->set_rgb_color (0, 0, 1);
+	$cr->set_source_rgb (0, 0, 1);
 	$cr->stroke;
 }

Index: splines_tolerance.pl
===================================================================
RCS file: /cvs/cairo/cairo-perl/examples/png/splines_tolerance.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- splines_tolerance.pl	28 Nov 2004 05:30:30 -0000	1.1
+++ splines_tolerance.pl	12 Jul 2005 20:29:49 -0000	1.2
@@ -11,25 +11,21 @@
 };
 
 {
-	my $cr;
-
-	$cr = Cairo->create;
+	my $surf = Cairo::ImageSurface->create ('argb32', WIDTH, HEIGHT);
+	my $cr = Cairo::Context->create ($surf);
 
 	$0 =~ /(.*)\.pl/;
 	my $out = "$1.png";
 
-	open OUT, ">$out" or die "unable to open ($out) for output";
-
-	$cr->set_target_png (*OUT, 'ARGB32', WIDTH, HEIGHT);
-
 	$cr->rectangle (0, 0, WIDTH, HEIGHT);
-	$cr->set_rgb_color (1, 1, 1);
+	$cr->set_source_rgb (1, 1, 1);
 	$cr->fill;
 
 	draw_splines ($cr, WIDTH, HEIGHT);
 
 	$cr->show_page;
-	close OUT;
+
+	$surf->write_to_png ($out);
 }
 
 sub draw_spline
@@ -51,7 +47,7 @@
 	my $line_width = .08 * $width;
 	my $gap = $width / 6;
 
-	$cr->set_rgb_color (0, 0, 0);
+	$cr->set_source_rgb (0, 0, 0);
 	$cr->set_line_width ($line_width);
 
 	$cr->translate ($gap, 0);

Index: stars.pl
===================================================================
RCS file: /cvs/cairo/cairo-perl/examples/png/stars.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- stars.pl	28 Nov 2004 05:30:30 -0000	1.1
+++ stars.pl	12 Jul 2005 20:29:49 -0000	1.2
@@ -12,25 +12,21 @@
 };
 
 {
-	my $cr;
-
-	$cr = Cairo->create;
+	my $surf = Cairo::ImageSurface->create ('argb32', WIDTH, HEIGHT);
+	my $cr = Cairo::Context->create ($surf);
 
 	$0 =~ /(.*)\.pl/;
 	my $out = "$1.png";
 
-	open OUT, ">$out" or die "unable to open ($out) for output";
-
-	$cr->set_target_png (*OUT, 'ARGB32', WIDTH, HEIGHT);
-
 	$cr->rectangle (0, 0, WIDTH, HEIGHT);
-	$cr->set_rgb_color (1, 1, 1);
+	$cr->set_source_rgb (1, 1, 1);
 	$cr->fill;
 
 	draw_stars ($cr, WIDTH, HEIGHT);
 
 	$cr->show_page;
-	close OUT;
+
+	$surf->write_to_png ($out);
 }
 
 sub star_path
@@ -52,14 +48,14 @@
 {
 	my ($cr, $width, $height) = @_;
 
-	$cr->set_rgb_color (0, 0, 0);
+	$cr->set_source_rgb (0, 0, 0);
 
 	$cr->save;
 	{
 		$cr->translate (5, $height / 2.6);
 		$cr->scale ($height, $height);
 		star_path ($cr);
-		$cr->set_fill_rule ('WINDING');
+		$cr->set_fill_rule ('winding');
 		$cr->fill;
 	}
 	$cr->restore;
@@ -69,7 +65,7 @@
 		$cr->translate ($width - $height - 5, $height / 2.6);
 		$cr->scale ($height, $height);
 		star_path ($cr);
-		$cr->set_fill_rule ('EVEN_ODD');
+		$cr->set_fill_rule ('even-odd');
 		$cr->fill;
 	}
 	$cr->restore;




More information about the cairo-commit mailing list