1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
package PDF::FromHTML::Template::Element::Circle;
use strict;
BEGIN {
use vars qw(@ISA);
@ISA = qw(PDF::FromHTML::Template::Element);
use PDF::FromHTML::Template::Element;
}
sub new
{
my $class = shift;
my $self = $class->SUPER::new(@_);
# warn 'Warning: <circle> missing required attribute R' unless exists $self->{R};
return $self;
}
sub render
{
my $self = shift;
my ($context) = @_;
return 0 unless $self->should_render($context);
return 1 if $context->{CALC_LAST_PAGE};
my ($x, $y, $r) = map { $context->get($self, $_) } qw(X Y R);
return 1 unless defined $r;
my $p = $context->{PDF};
$p->save_state;
$self->set_color($context, 'COLOR', 'stroke');
my $fillcolor = $context->get($self, 'FILLCOLOR');
$self->set_color($context, 'FILLCOLOR', 'fill');
my $width = $context->get($self, 'WIDTH') || 1;
$p->linewidth($width);
$p->circle($x, $y, $r);
if (defined $fillcolor)
{
$p->fill_stroke;
}
else
{
$p->stroke;
}
$p->restore_state;
return 1;
}
sub deltas
{
my $self = shift;
my ($context) = @_;
# my ($x, $y, $r) = map { $context->get($self, $_) } qw(X Y R);
my ($x, $y) = map { $context->get($self, $_) } qw(X Y);
#GGG Have $r involved here?
return {
X => $x - $context->{X},
Y => $y - $context->{Y},
};
}
1;
__END__
=head1 NAME
PDF::FromHTML::Template::Element::Circle - To draw a circle
=head1 NODE NAME
CIRCLE
=head1 INHERITANCE
PDF::FromHTML::Template::Element
=head1 ATTRIBUTES
=over 4
=item * R
This is the radius of the circle to be drawn
=item * COLOR
This is the color the circle should be drawn in. Defaults to black.
=item * FILLCOLOR
This is the color the circle should be filled in with. Defaults to none.
=item * WIDTH
This is the width of the line used to draw the circle. Defaults to 1 pixel.
=back
=head1 CHILDREN
None
=head1 AFFECTS
Nothing
=head1 DEPENDENCIES
None
=head1 USAGE
<circle R="1i" color="255,0,0"/>
This will cause a 1-inch radius circle to be drawn at the current position in
red.
=head1 AUTHOR
Rob Kinyon (rkinyon@columbus.rr.com)
=head1 SEE ALSO
=cut
|