[cairo-commit] [cairo-www] src/perl_cairo_module.mdwn
Carl Worth
cworth at freedesktop.org
Thu Feb 26 16:43:59 PST 2009
src/perl_cairo_module.mdwn | 71 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
New commits:
commit d44b1b8b8bcd8c888b832d7881385589899b5147
Author: c9s <c9s at web>
Date: Thu Feb 26 16:43:59 2009 -0800
diff --git a/src/perl_cairo_module.mdwn b/src/perl_cairo_module.mdwn
new file mode 100644
index 0000000..7d261a0
--- /dev/null
+++ b/src/perl_cairo_module.mdwn
@@ -0,0 +1,71 @@
+Back to [[cookbook]]
+
+# Install Cairo CPAN Module
+
+Using CPAN:
+ # cpan Cairo
+
+Using CPANPLUS
+ # cpanp -i Cairo
+
+## Draw Lines
+
+ #!/usr/bin/perl
+
+ use strict;
+ use warnings;
+ use Cairo;
+
+ use constant
+ {
+ IMG_WIDTH => 640,
+ IMG_HEIGHT => 480,
+ PADDING => "10 10 10 10" # top , right , bottom , left
+ };
+
+ die "png backend not supported" unless (Cairo::HAS_PNG_FUNCTIONS);
+
+ my $png = shift || "vc32-mask.png";
+
+ my $surf = Cairo::ImageSurface->create ('argb32', IMG_WIDTH, IMG_HEIGHT);
+ my $cr = Cairo::Context->create ($surf);
+
+ $cr->rectangle (0, 0, IMG_WIDTH, IMG_HEIGHT);
+ $cr->set_source_rgba (1, 1, 1, 0.5);
+ $cr->fill;
+
+
+ my %padding;
+
+ @padding{ qw/top right bottom left/ } = split /\s+/,PADDING;
+ my @point = (
+ [ $padding{left}, $padding{top} ] ,
+ [ IMG_WIDTH - $padding{right} , $padding{top} ],
+ [ IMG_WIDTH - $padding{right} , IMG_HEIGHT - $padding{bottom} ],
+ [ $padding{left} , IMG_HEIGHT - $padding{bottom} ] ,
+ [ $padding{left}, $padding{top} ] ,
+ );
+
+
+
+ $cr->save;
+ $cr->set_source_rgba (0, 0, 0, 1 );
+ $cr->set_line_width ( 3 );
+ $cr->set_dash ( 0 , 50.0 , 10.0 , 10.0 , 10.0 );
+
+ for my $i ( 0 .. 3 ) {
+ my $p = $point[$i] ;
+ my $next_p = $point[ $i + 1 ];
+ $cr->new_path;
+ $cr->move_to ( @$p );
+ $cr->line_to ( @$next_p );
+ $cr->stroke;
+ # $cr->rotate ((M_PI * 2) / $count);
+ }
+
+ $cr->restore;
+
+
+
+ $surf->write_to_png ($png);
+
More information about the cairo-commit
mailing list