PDF::FromHTML::Template::Element::Circle - PDF::FromHTML::Template::Element::Circle documentation


PDF-FromHTML documentation Contained in the PDF-FromHTML distribution.

Index


Code Index:

NAME

Top

PDF::FromHTML::Template::Element::Circle

PURPOSE

Top

To draw a circle.

NODE NAME

Top

CIRCLE

INHERITANCE

Top

PDF::FromHTML::Template::Element

ATTRIBUTES

Top

* R This is the radius of the circle to be drawn
* COLOR This is the color the circle should be drawn in. Defaults to black.
* FILLCOLOR This is the color the circle should be filled in with. Defaults to none.
* WIDTH This is the width of the line used to draw the circle. Defaults to 1 pixel.

CHILDREN

Top

None

AFFECTS

Top

Nothing

DEPENDENCIES

Top

None

USAGE

Top

  <circle R="1i" color="255,0,0"/>

This will cause a 1-inch radius circle to be drawn at the current position in red.

AUTHOR

Top

Rob Kinyon (rkinyon@columbus.rr.com)

SEE ALSO

Top


PDF-FromHTML documentation Contained in the PDF-FromHTML distribution.

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__