Cairo - Perl interface to the cairo library
use Cairo; my $surface = Cairo::ImageSurface->create ('argb32', 100, 100); my $cr = Cairo::Context->create ($surface); $cr->rectangle (10, 10, 40, 40); $cr->set_source_rgb (0, 0, 0); $cr->fill; $cr->rectangle (50, 50, 40, 40); $cr->set_source_rgb (1, 1, 1); $cr->fill; $cr->show_page; $surface->write_to_png ("output.png");
Cairo provides Perl bindings for the vector graphics library cairo. It supports multiple output targets, including the X Window Systems, PDF, and PNG. Cairo produces identical output on all those targets and makes use of hardware acceleration wherever possible.
Cairo::Context is the main object used when drawing with Cairo. To draw with Cairo, you create a Cairo::Context, set the target surface, and drawing options for the Cairo::Context, create shapes with methods like $cr-move_to> and $cr->line_to, and then draw shapes with $cr->stroke or $cr->fill.
$cr-
$cr->line_to
$cr->stroke
$cr->fill
Cairo::Context's can be pushed to a stack via $cr->save. They may then safely be changed, without loosing the current state. Use $cr->restore to restore to the saved state.
$cr->save
$cr->restore
$path = [ { type => "move-to", points => [[1, 2]] }, { type => "line-to", points => [[3, 4]] }, { type => "curve-to", points => [[5, 6], [7, 8], [9, 10]] }, ... { type => "close-path", points => [] }, ];
Cairo::Path is a data structure for holding a path. This data structure serves as the return value for $cr->copy_path_data and $cr->copy_path_data_flat as well the input value for $cr->append_path.
$cr->copy_path_data
$cr->copy_path_data_flat
$cr->append_path
Cairo::Path is represented as an array reference that contains path elements, represented by hash references with two keys: type and points. The value for type can be either of the following:
move-to
line-to
curve-to
close-path
The value for points is an array reference which contains zero or more points. Points are represented as array references that contain two doubles: x and y. The necessary number of points depends on the type of the path element:
line_to
The semantics and ordering of the coordinate values are consistent with $cr->move_to, $cr->line_to, $cr->curve_to, and $cr->close_path.
$cr->move_to
$cr->curve_to
$cr->close_path
Glyphs are represented as anonymous hash references with three keys: index, x and y. Example:
my @glyphs = ({ index => 1, x => 2, y => 3 }, { index => 2, x => 3, y => 4 }, { index => 3, x => 4, y => 5 });
Lists many available resources including tutorials and examples
Contains the reference manual
Copyright (C) 2005 by the cairo perl team
To install Cairo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cairo
CPAN shell
perl -MCPAN -e shell install Cairo
For more information on module installation, please visit the detailed CPAN module installation guide.