
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 PNG, PDF and SVG. Cairo produces identical output on all those targets.

Note that this listing still lacks entries for Cairo::Surfaces and some utility methods.
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.
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. =over
$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.
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:
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:
The semantics and ordering of the coordinate values are consistent with $cr->move_to, $cr->line_to, $cr->curve_to, and $cr->close_path.
A color stop is represented as an array reference with five elements: offset, red, green, blue, and alpha.
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 });
If your cairo library supports it, the FreeType integration allows you to load font faces from font files. You can query for this capability with Cairo::HAS_FT_FONT. To actually use this, you'll need the Font::FreeType module.
This method allows you to create a Cairo::FontFace from a Font::FreeType::Face. To obtain the latter, you can for example load it from a file:
my $file = '/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf'; my $ft_face = Font::FreeType->new->face ($file); my $face = Cairo::FtFontFace->create ($ft_face);

Lists many available resources including tutorials and examples
Contains the reference manual


Copyright (C) 2004-2008 by the cairo perl team