#$Id: GeneralPath.pm,v 1.7 2003/04/22 16:28:12 malay Exp $
# Perl module for GeneralPath
# Author: Malay < curiouser@ccmb.res.in >
# You may distribute this module under the same terms as perl itself
# POD documentation - main docs before the code
GeneralPath - DESCRIPTION of Object
Malay <curiouser@ccmb.ap.nic.in>
package Pastel
::Geometry
::GeneralPath
;
@ISA = qw(Pastel::Root Pastel::Shape);
use Pastel
::Geometry
::PathIteratorI
;
use Pastel
::Geometry
::Point
;
# _init is where the heavy stuff will happen when new is called
use constant WIND_EVEN_ODD
=> 'WIND_EVEN_ODD';
use constant WIND_NON_ZERO
=> 'WIND_NON_ZERO';
use constant SEG_MOVETO
=> 'SEG_MOVETO';
use constant SEG_LINETO
=> 'SEG_LINETO';
use constant SEG_QUADTO
=> 'SEG_QUADTO';
use constant SEG_CUBICTO
=> 'SEG_CUBICTO';
use constant SEG_CLOSE
=> 'SEG_CLOSE';
use constant SEG_ARCTO
=> 'SEG_ARCTO';
my ( $self, @args ) = @_;
my ( $rule, $shape ) = $self->_rearrange( [ 'RULE', 'SHAPE' ], @args );
if ( defined($rule) && $rule eq 'WIND_EVEN_ODD' ) {
$self->set_winding_rule('WIND_EVEN_ODD');
$self->set_winding_rule('WIND_NON_ZERO'); # Default winding rule
$self->{types
} = []; # Segment types
$self->{coord
} = []; # xy coord of each point
$self->{numtypes
} = 0; # y coord of current point
$self->{arc_rotation
} = 0;
# set stuff in self from @args
return $self; # success - we hope!
my ( $self, $rule ) = @_;
if ( ( $rule ne 'WIND_EVEN_ODD' ) && ( $rule ne 'WIND_NON_ZERO' ) ) {
'Illegal parameter in Pastel::Geometry::GeneralPath::set_winding_rule()\n';
if ( $rule eq 'WIND_EVEN_ODD' ) {
# default fill rule for SVG is nonzero
$self->set_fill_rule('evenodd'); # inherited from Pastel::Shape
$self->{arc_rotation
} = $r;
return $_[0]->{arc_rotation
};
my ( $self, $x, $y ) = @_;
push ( @
{ $self->{types
} }, SEG_MOVETO
);
push ( @
{ $self->{coord
} }, $x );
push ( @
{ $self->{coord
} }, $y );
my ( $self, $x, $y ) = @_;
push ( @
{ $self->{types
} }, SEG_LINETO
);
push ( @
{ $self->{coord
} }, $x );
push ( @
{ $self->{coord
} }, $y );
my @array = @_[ 0 .. 3 ];
push ( @
{ $self->{types
} }, SEG_QUADTO
);
push ( @
{ $self->{coord
} }, @array );
my @array = @_[ 0 .. 5 ];
push ( @
{ $self->{types
} }, SEG_CUBICTO
);
push ( @
{ $self->{coord
} }, @array );
push ( @
{ $self->{types
} }, SEG_CLOSE
);
push ( @
{$self->{types
} } , SEG_ARCTO
);
push (@
{$self->{coord
}}, @_ );
if ( $self->{numtypes
} < 1 || $self->{numcoord
} < 2 ) {
my $index = $self->{numcoord
};
# If last point is a CLOSE PATH then go back to the beginning
if ( $self->{types
}[ $self->{numtypes
} - 1 ] eq 'SEG_CLOSE' ) {
for ( my $j = $self->{numtypes
} - 2 ; $j > 0 ; $j-- ) {
if ( $self->{types
}[$j] eq 'SEG_MOVETO' ) {
elsif ( $self->{types
}[$j] eq 'SEG_LINETO' ) {
elsif ( $self->{types
}[$j] eq 'SEG_QUADTO' ) {
elsif ( $self->{types
}[$j] eq 'SEG_CUBICTO' ) {
elsif ($self->{types
}[$j] eq 'SEG_ARCTO' ){
elsif ( $self->{types
}[$j] eq 'SEG_CLOSE' ) {
return Pastel
::Geometry
::Point
->new(
-x
=> $self->{coord
}[ $index - 2 ],
-y
=> $self->{coord
}[ $index - 1 ]
$s .= '" style="' . $self->get_style($graphics) . '" />';
my $x = 0; # holds the last x coordinate
my $y = 0; # holds the last y coordinate
for ( my $i = 0 ; $i < $self->{numtypes
} ; $i++ ) {
if ( $self->{types
}[$i] eq 'SEG_MOVETO' ) {
$x = $self->{coord
}[$index];
$y = $self->{coord
}[ $index + 1 ];
'M' . $self->{coord
}[$index] . " " . $self->{coord
}[ $index + 1 ];
elsif ( $self->{types
}[$i] eq 'SEG_LINETO' ) {
if ( $self->{coord
}[$index] == $x ) {
$y = $self->{coord
}[ $index + 1 ];
elsif ( $self->{coord
}[ $index + 1 ] == $y ) {
$x = $self->{coord
}[$index];
$x = $self->{coord
}[$index];
$y = $self->{coord
}[ $index + 1 ];
. $self->{coord
}[$index] . " "
. $self->{coord
}[ $index + 1 ];
elsif ( $self->{types
}[$i] eq 'SEG_QUADTO' ) {
$x = $self->{coord
}[ $index + 2 ];
$y = $self->{coord
}[ $index + 3 ];
'Q' . $self->{coord
}[$index] . " " . $self->{coord
}[ $index + 1 ];
$s .= " " . $x . " " . $y;
elsif ( $self->{types
}[$i] eq 'SEG_CUBICTO' ) {
$x = $self->{coord
}[ $index + 4 ];
$y = $self->{coord
}[ $index + 5 ];
'C' . $self->{coord
}[$index] . " " . $self->{coord
}[ $index + 1 ];
. $self->{coord
}[ $index + 2 ] . " "
. $self->{coord
}[ $index + 3 ];
$s .= " " . $x . " " . $y;
elsif ($self->{types
}[$i] eq 'SEG_ARCTO'){
$x = $self->{coord
}[ $index + 4];
$y = $self->{coord
}[ $index + 5];
$s .= 'A'.$self->{coord
}[$index]." ".$self->{coord
}[$index + 1];
$s .= " ".$self->get_arc_rotation()." ";
$s .= $self->{coord
}[$index + 2];
$s .= " ".$self->{coord
}[$index + 3];
elsif ( $self->{types
}[$i] eq 'SEG_CLOSE' ) {