Subject: | Reports error with text string of '0' |
GDTextUtil 0.80
Summary of my perl5 (revision 5 version 6 subversion 1) configuration:
Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
Given code similar to:
my $text = GD::Text::Align->new($image,
text => '0',
font => GD::gdTinyFont,
valign => 'center',
halign => 'center',
colour => $colour ) or
die GD::Text->error();
$text->draw($x, $y, 0);
Align.pm generates errors:
Use of uninitialized value in division (/) at c:/Perl/site/lib/GD/Text/Align.pm line 294.
Use of uninitialized value in division (/) at c:/Perl/site/lib/GD/Text/Align.pm line 294.
Use of uninitialized value in addition (+) at c:/Perl/site/lib/GD/Text/Align.pm line 450.
Use of uninitialized value in addition (+) at c:/Perl/site/lib/GD/Text/Align.pm line 450.
Suitable patch appears to be:
At Text.pm, line 503:
$self->_recalc_width() if $self->{text};
Replace with
$self->_recalc_width() if defined $self->{text};
The fault appears to be that width is not calculated at all if the text is defined but has a value translating to false.
Context of patch:
# XXX Should we really round this?
$self->{space} = sprintf "%.0f",
(($bb2[2]-$bb2[0]) - ($bb1[2]-$bb1[0]))/$n_spaces;
}
else
{
confess "Impossible error in GD::Text::_recalc.";
}
$self->_recalc_width() if defined $self->{text};
return 1;
}
=head2 $gd_text->is_builtin
Returns true if the current object is based on a builtin GD font.
=cut
Sorry for not giving a patch against 0.83, but the activestate repository
only has 0.80. The changelog seems to imply that this is hasn't been fixed.