]> git.imager.perl.org - imager.git/commitdiff
better error checking of automatic fill conversions
authorTony Cook <tony@develop=help.com>
Wed, 24 Oct 2001 10:09:38 +0000 (10:09 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 24 Oct 2001 10:09:38 +0000 (10:09 +0000)
Changes
Imager.pm
t/t20fill.t

diff --git a/Changes b/Changes
index 5ef38cce5b791a8c3e5f39fc8b51110b74e1238a..afdecd8d0288b2d60c4d7697c696a03ae9fd0138 100644 (file)
--- a/Changes
+++ b/Changes
@@ -533,6 +533,7 @@ Revision history for Perl extension Imager.
           added code to normalize the filter generated to preserve
           intensity scaling.
         - constant edge extension for scaling operations
+        - better error checking of automatic fill conversions
 
 
 =================================================================
index 70dade6d68dc29ddd453d984471a253d3d091064..95c38f3892c08a5b092d04a78ab9157048fc7c42 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -1711,7 +1711,10 @@ sub arc {
     unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
       # assume it's a hash ref
       require 'Imager/Fill.pm';
-      $opts{fill} = Imager::Fill->new(%{$opts{fill}});
+      unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
+        $self->{ERRSTR} = $Imager::ERRSTR;
+        return;
+      }
     }
     i_arc_cfill($self->{IMG},$opts{'x'},$opts{'y'},$opts{'r'},$opts{'d1'},
                 $opts{'d2'}, $opts{fill}{fill});
@@ -1823,7 +1826,10 @@ sub flood_fill {
     unless (UNIVERSAL::isa($opts{fill}, 'Imager::Fill')) {
       # assume it's a hash ref
       require 'Imager/Fill.pm';
-      $opts{fill} = Imager::Fill->new(%{$opts{fill}});
+      unless ($opts{fill} = Imager::Fill->new(%{$opts{fill}})) {
+        $self->{ERRSTR} = $Imager::ERRSTR;
+        return;
+      }
     }
     i_flood_cfill($self->{IMG}, $opts{x}, $opts{'y'}, $opts{fill}{fill});
   }
index ae84303a1323c4e3002f4159f181ee5d72d14107..0358f9914509f107fe2495c65f0af279aedf79d0 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 
-print "1..37\n";
+print "1..39\n";
 
 use Imager ':handy';
 use Imager::Fill;
@@ -106,14 +106,17 @@ my $im = Imager->new(xsize=>200, ysize=>200);
 $im->box(xmin=>10, ymin=>10, xmax=>190, ymax=>190,
          fill=>{ hatch=>'check4x4',
                  fg=>NC(128, 0, 0),
-                 bg=>NC(128, 64, 0) });
+                 bg=>NC(128, 64, 0) })
+  or print "# ",$im->errstr,"\n";
 $im->arc(r=>80, d1=>45, d2=>75, 
            fill=>{ hatch=>'stipple2',
                    combine=>1,
                    fg=>[ 0, 0, 0, 255 ],
-                   bg=>{ rgba=>[255,255,255,160] } });
+                   bg=>{ rgba=>[255,255,255,160] } })
+  or print "# ",$im->errstr,"\n";
 $im->arc(r=>80, d1=>75, d2=>135,
-         fill=>{ fountain=>'radial', xa=>100, ya=>100, xb=>20, yb=>100 });
+         fill=>{ fountain=>'radial', xa=>100, ya=>100, xb=>20, yb=>100 })
+  or print "# ",$im->errstr,"\n";
 $im->write(file=>'testout/t20_sample.ppm');
 
 # flood fill tests
@@ -230,6 +233,13 @@ ok($testnum++,
    "transformed image based fill");
 $oocopy->write(file=>'testout/t20_image_xform.ppm');
 
+ok($testnum++,
+   !$oocopy->arc(fill=>{ hatch=>"not really a hatch" }, r=>20),
+   "error handling of automatic fill conversion");
+ok($testnum++,
+   $oocopy->errstr =~ /Unknown hatch type/,
+   "error message for automatic fill conversion");
+
 sub ok ($$$) {
   my ($num, $test, $desc) = @_;