GD-SVG
view release on metacpan or search on metacpan
sub _transform_coords {
my ($refx,$refy,$x,$y,$dstx,$dsty) = @_;
my $xoffset = $x - $refx;
my $yoffset = $y - $refy;
my $newx = $dstx + $xoffset;
my $newy = $dsty + $yoffset;
return ($newx,$newy);
}
sub _copy_image {
my $self = shift;
my ($source,$dstx,$dsty,$srcx,$srcy,$width,$height) = @_;
eval "use MIME::Base64; 1"
or croak "The MIME::Base64 module is required to copy a GD::Image into a GD::SVG: $@";
my $subimage = GD::Image->new($width,$height); # will be loaded
$subimage->copy($source->isa('GD::Simple') ? $source->gd : $source,
0,0,
$srcx,$srcy,
$width,$height);
my $data = encode_base64($subimage->png);
my ($img,$id) = $self->_prep($dstx,$dsty);
my $result =
$img->image('x' => $dstx,
'y' => $dsty,
width => $width,
height => $height,
id => $id,
'xlink:href' => "data:image/png;base64,$data");
$self->_reset;
return $result;
}
##################################################
# Image Transformation Methods
##################################################
# None implemented
##################################################
# Character And String Drawing
##################################################
sub string {
my ($self,$font_obj,$x,$y,$text,$color_index) = @_;
my $img = $self->currentGroup;
my $id = $self->_create_id($x,$y);
my $formatting = $font_obj->formatting();
my $color = $self->_get_color($color_index);
my $result =
$img->text(
id=>$id,
x=>$x,
y=>$y + $font_obj->{height} - GD::SVG::TEXT_KLUDGE,
%$formatting,
fill => $color,
)->cdata($text);
return $result;
}
sub stringUp {
my ($self,$font_obj,$x,$y,$text,$color_index) = @_;
my $img = $self->currentGroup;
my $id = $self->_create_id($x,$y);
my $formatting = $font_obj->formatting();
my $color = $self->_get_color($color_index);
$x += $font_obj->height;
my $result =
$img->text(
id=>$id,
%$formatting,
'transform' => "translate($x,$y) rotate(-90)",
fill => $color,
)->cdata($text);
}
sub char {
my ($self,@rest) = @_;
$self->string(@rest);
}
sub charUp {
my ($self,@rest) = @_;
$self->stringUp(@rest);
}
# Replicating the TrueType handling
#sub GD::Image::stringFT { shift->_error('stringFT'); }
sub stringFT {
return;
}
# not implemented
sub useFontConfig {
return 0;
}
##################################################
# Alpha Channels
##################################################
sub alphaBlending { shift->_error('alphaBlending'); }
sub saveAlpha { shift->_error('saveAlpha'); }
##################################################
# Miscellaneous Image Methods
##################################################
sub interlaced { shift->_error('inerlaced'); }
sub getBounds {
my $self = shift;
my $width = $self->{width};
my $height = $self->{height};
return($width,$height);
}
sub isTrueColor { shift->_error('isTrueColor'); }
sub compare { shift->_error('compare'); }
sub clip { shift->_error('clip'); }
sub boundsSafe { shift->_error('boundsSafe'); }
##########################################
# Internal routines for meshing with SVG #
##########################################
# Fetch out typical params used for drawing.
package GD::SVG::Image;
use Carp 'confess';
sub _prep {
my ($self,@params) = @_;
my $img = $self->currentGroup;
my $id = $self->_create_id(@params);
# my $thickness = $self->_get_thickness() || 1;
( run in 1.714 second using v1.01-cache-2.11-cpan-bbe5e583499 )