Subject: | Additional methods for PDF::Create::Page |
It would be nice if the methods in the attached file (set_stroke_color,
set_fill_color, set_line_width, circle) could be part of PDF::Create::Page.
Regards,
Slaven
Subject: | PDF-Create-Page-additions.txt |
use constant PI => 3.141592653;
sub set_stroke_color {
my($page, $r, $g, $b) = @_;
return if (defined $page->{'current_stroke_color'} &&
$page->{'current_stroke_color'} eq join(",", $r, $g, $b));
$page->{'pdf'}->page_stream($page);
$page->{'pdf'}->add("$r $g $b RG");
$page->{'current_stroke_color'} = join(",", $r, $g, $b);
}
sub set_fill_color {
my($page, $r, $g, $b) = @_;
return if (defined $page->{'current_fill_color'} &&
$page->{'current_fill_color'} eq join(",", $r, $g, $b));
$page->{'pdf'}->page_stream($page);
$page->{'pdf'}->add("$r $g $b rg");
$page->{'current_fill_color'} = join(",", $r, $g, $b);
}
sub set_line_width {
my($page, $w) = @_;
return if (defined $page->{'current_line_width'} &&
$page->{'current_line_width'} == $w);
$page->{'pdf'}->page_stream($page);
$page->{'pdf'}->add("$w w");
$page->{'current_line_width'} = $w;
}
sub circle {
my($page, $x, $y, $r) = @_;
my @coords;
for(my $i = 0; $i < PI*2; $i+=PI*2/$r/2) {
my($xi,$yi) = map { $_*$r } (sin $i, cos $i);
push @coords, $x+$xi, $y+$yi;
}
push @coords, @coords[0,1];
@coords = map { sprintf "%.2f", $_ } @coords;
$page->moveto(shift @coords, shift @coords);
for(my $i = 0; $i <= $#coords; $i+=2) {
$page->lineto($coords[$i], $coords[$i+1]);
}
}