]> git.imager.perl.org - imager.git/commitdiff
the align_string() method would ignore a string of "0" due to a
authorTony Cook <tony@develop=help.com>
Tue, 10 Aug 2010 04:45:44 +0000 (04:45 +0000)
committerTony Cook <tony@develop=help.com>
Tue, 10 Aug 2010 04:45:44 +0000 (04:45 +0000)
mis-use of C< ||= >.
https://rt.cpan.org/Ticket/Display.html?id=60199

Changes
Imager.pm
t/t38ft2font.t

diff --git a/Changes b/Changes
index 7ce0f82a1c3231b8ba99c32460baefb027268cad..1f85da0cd4a3647cf761133a6481f17888ce9c94 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,15 @@
 Imager release history.  Older releases can be found in Changes.old
 
+Imager 0.76 - unreleased
+===========
+
+Bug fixes:
+
+ - the align_string() method would ignore a string of "0" due to a
+   mis-use of C< ||= >.
+   Thanks to Maurice Height for reporting this.
+   https://rt.cpan.org/Ticket/Display.html?id=60199
+
 Imager 0.75_03 - 09 Aug 2010
 ==============
 
index af120dbf58fbd5a288768a0ecc9e89b89940d924..533ac4b200c8ba3645ed9f1e189b2c5aa2ce1612 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -3745,7 +3745,8 @@ sub align_string {
   }
 
   my %input=('x'=>0, 'y'=>0, @_);
-  $input{string}||=$input{text};
+  defined $input{string}
+    or $input{string} = $input{text};
 
   unless(exists $input{string}) {
     $self->_set_error("missing required parameter 'string'");
index 19e0cc6a70a826590816dc32bbf6749eb3690dc5..4431d431d12bcb0fa4b9f9ae9d872f4087150452 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 183;
+use Test::More tests => 187;
 ++$|;
 # Before `make install' is performed this script should be runnable with
 # `make test'. After `make install' it should work as `perl test.pl'
@@ -20,13 +20,13 @@ my @base_color = (64, 255, 64);
 
 SKIP:
 {
-  i_has_format("ft2") or skip("no freetype2 library found", 182);
+  i_has_format("ft2") or skip("no freetype2 library found", 186);
 
   print "# has ft2\n";
   
   my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
 
-  -f $fontname or skip("cannot find fontfile $fontname", 182);
+  -f $fontname or skip("cannot find fontfile $fontname", 186);
 
 
   my $bgcolor=i_color_new(255,0,0,0);
@@ -475,6 +475,21 @@ SKIP:
                   size => 11, sizew => 11, font => $font, aa => 1),
        'draw on translucent image')
   }
+
+  { # RT 60199
+    # not ft2 specific, but Imager
+    my $im = Imager->new(xsize => 100, ysize => 100);
+    my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+    my $imcopy = $im->copy;
+    ok($im, "make test image");
+    ok($font, "make test font");
+    ok($im->align_string(valign => "center", halign => "center",
+                        x => 50, y => 50, string => "0", color => "#FFF",
+                        font => $font),
+       "draw 0 aligned");
+    ok(Imager::i_img_diff($im->{IMG}, $imcopy->{IMG}),
+       "make sure we drew the '0'");
+  }
 }
 
 sub align_test {