Cairo: how do I use $cr->append_path to draw a path?



Hi,

I'm playing with Cairo to generate hexmaps for role-playing games, and
using the $cr->move_to and $cr->line_to methods, this works fine.

However, according to the documentation, I should also be able to build
a Cairo::Path object and use $cr->append_path to do the same thing. Yet,
when I try, it doesn't work. See the below code for an example:

#!/usr/bin/perl

use strict;
use warnings;
use Cairo;
use Data::Dump qw/dump/;

my $surface = Cairo::PdfSurface->create('out.pdf',200,200);
my $cr = Cairo::Context->create($surface);
$cr->set_source_rgb(0,0,0);

# The following does not work:
my $path = [
            { type => "move-to", points => [[10,10]] },
            { type => "line-to", points => [[10,190]] },
            { type => "line-to", points => [[190,190]] },
            { type => "line-to", points => [[190,10]] },
            { type => "close-path", points => [] } ,
           ];
$cr->append_path($path);

# This however does:
#$cr->move_to(10,10);
#$cr->line_to(10,190);
#$cr->line_to(190,190);
#$cr->line_to(190,10);
#$cr->close_path;
#my $path = $cr->copy_path;
#dump $path;
$cr->stroke;
$cr->show_page;
$surface->flush;
$surface->finish;

Am I doing something wrong, or am I reading the documentations
incorrectly?

Regards,

Mart




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]