GD-SVG
view release on metacpan or search on metacpan
my $group = $this->currentGroup->group(@args);
push @{$this->{img}},$group;
return $group;
}
sub endGroup {
my $this = shift;
my $group = shift;
if ($group) {
my @imgs = grep {$_ ne $group} @{$this->{img}};
$this->{img} = \@imgs;
}
elsif (@{$this->{img}}>1) {
pop @{$this->{img}};
}
delete $this->{currentGroup};
}
sub newGroup {
my $this = shift;
my $group = $this->startGroup(@_);
eval "require GD::Group" unless GD::Group->can('new');
return GD::Group->new($this,$group);
}
#######################
# Drawing subroutines #
#######################
sub setPixel {
my ($self,$x1,$y1,$color_index) = @_;
###GD### $self->{gd}->setPixel($x1,$y1,$color_index);
my ($img,$id,$thickness,$dasharray) = $self->_prep($x1,$y1);
my $color = $self->_get_color($color_index);
my $result =
$img->circle(cx=>$x1,cy=>$y1,r=>'0.03',
id=>$id,
style=>{
'stroke'=>$color,
'fill' =>$color,
'fill-opacity'=>'1.0'
}
);
return $result;
}
sub line {
my ($self,$x1,$y1,$x2,$y2,$color_index) = @_;
# Are we trying to draw with a styled line (ie gdStyled, gdBrushed?)
# If so, we need to deconstruct the values for line thickness,
# foreground color, and dash spacing
if ($color_index eq 'gdStyled' || $color_index eq 'gdBrushed') {
my $fg = $self->_distill_gdSpecial($color_index);
$self->line($x1,$y1,$x2,$y2,$fg);
} else {
###GD### $self->{gd}->line($x1,$y1,$x2,$y2,$color_index);
my ($img,$id) = $self->_prep($x1,$y1);
my $style = $self->_build_style($id,$color_index,$color_index);
# Suggested patch by Jettero to fix lines
# that don't go to the ends of their length.
# This could possibly be relocated to _build_style
# but I'm unsure of the ramifications on other features.
$style->{'stroke-linecap'} = 'square';
my $result = $img->line(x1=>$x1,y1=>$y1,
x2=>$x2,y2=>$y2,
id=>$id,
style => $style,
);
$self->_reset();
return $result;
}
}
sub dashedLine { shift->_error('dashedLine'); }
# The fill parameter is used internally as a simplification...
sub rectangle {
my ($self,$x1,$y1,$x2,$y2,$color_index,$fill) = @_;
if ($color_index eq 'gdStyled' || $color_index eq 'gdBrushed') {
my $fg = $self->_distill_gdSpecial($color_index);
$self->rectangle($x1,$y1,$x2,$y2,$fg,$fill);
} else {
###GD###$self->{gd}->rectangle($x1,$y1,$x2,$y2,$color_index);
my ($img,$id) = $self->_prep($x1,$y1);
my $style = $self->_build_style($id,$color_index,$fill);
# flip coordinates if they are "backwards"
($x1,$x2) = ($x2,$x1) if $x1 > $x2;
($y1,$y2) = ($y2,$y1) if $y1 > $y2;
my $result =
$img->rectangle(x=>$x1,y=>$y1,
width =>$x2-$x1,
height =>$y2-$y1,
id =>$id,
style => $style,
);
$self->_reset();
return $result;
}
}
# This should just call the rectangle method passing it a flag.
# I will need to fix the glyph that bypasses this option...
sub filledRectangle {
my ($self,$x1,$y1,$x2,$y2,$color) = @_;
# Call the rectangle method passing the fill color
$self->rectangle($x1,$y1,$x2,$y2,$color,$color);
}
sub polygon {
my ($self,$poly,$color,$fill) = @_;
$self->_polygon($poly,$color,$fill,1);
}
sub polyline {
my ($self,$poly,$color,$fill) = @_;
$self->_polygon($poly,$color,$fill,0);
}
sub polydraw {
my $self = shift; # the GD::Image
( run in 1.482 second using v1.01-cache-2.11-cpan-71847e10f99 )