]> git.imager.perl.org - imager.git/commitdiff
- Imager::Font::BBox advance_width() method was falling back to
authorTony Cook <tony@develop=help.com>
Wed, 20 Apr 2005 15:21:29 +0000 (15:21 +0000)
committerTony Cook <tony@develop=help.com>
Wed, 20 Apr 2005 15:21:29 +0000 (15:21 +0000)
  the wrong value when the font driver's low level function
  didn't return the advance width.

Changes
lib/Imager/Font/BBox.pm
t/t37w32font.t

diff --git a/Changes b/Changes
index be79a2611dfa84d6ee9fbe9697c10778f12c0dd9..34d375c7f08dd5d4fbd7b56d408aa83d17b773ed 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1059,6 +1059,9 @@ Revision history for Perl extension Imager.
   descriptions as other functions do.
 - fix a few compiler warnings
 - document the Imager::Font::BBox advance_width() method
+- Imager::Font::BBox advance_width() method was falling back to
+  the wrong value when the font driver's low level function
+  didn't return the advance width.
 
 =================================================================
 
index 2246a0be041859ccd1a6957bd2345c0a0c3bb364..4fe8ddfd1cd5e33e5eae38733e458f4004fbc89a 100644 (file)
@@ -131,7 +131,7 @@ otherwise the same as end_offset.
 sub advance_width {
   my $self = shift;
 
-  @$self > 6 ? $self->[6] : $self->[5];
+  @$self > 6 ? $self->[6] : $self->[2];
 }
 
 =item total_width()
index 98afbd304498a8bebf5a7e472bb9fe14c9e113a1..3e90195a26ac60525d04b1c548a94c3844d5194d 100644 (file)
@@ -1,68 +1,64 @@
 #!perl -w
-BEGIN { $| = 1; print "1..5\n"; }
-END {print "not ok 1\n" unless $loaded;}
-use Imager qw(:all);
-$loaded = 1;
-print "ok 1\n";
+use strict;
+use lib 't';
+use Test::More tests => 7;
+BEGIN { use_ok(Imager => ':all') }
 
 init_log("testout/t37w32font.log",1);
 
-sub skip { 
-  for (2..5) {
-    print "ok $_ # skip not MS Windows\n";
-  }
-  malloc_state();
-  exit(0);
-}
-
-i_has_format('w32') or skip();
-print "# has w32\n";
-
-$fontname=$ENV{'TTFONTTEST'} || 'Times New Roman Bold';
-
-# i_init_fonts(); # unnecessary for Win32 font support
-
-$bgcolor=i_color_new(255,0,0,0);
-$overlay=Imager::ImgRaw::new(200,70,3);
-
-@bbox=Imager::i_wf_bbox($fontname, 50.0,'XMCLH');
-print "#bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
+{
+  i_has_format('w32') or skip("no MS Windows", 6);
+  print "# has w32\n";
 
-Imager::i_wf_cp($fontname,$overlay,5,50,1,50.0,'XMCLH',1,1);
-i_line($overlay,0,50,100,50,$bgcolor, 1);
+  my $fontname=$ENV{'TTFONTTEST'} || 'Times New Roman Bold';
+  
+  # i_init_fonts(); # unnecessary for Win32 font support
 
-open(FH,">testout/t37w32font.ppm") || die "cannot open testout/t37w32font.ppm\n";
-binmode(FH);
-$io = Imager::io_new_fd(fileno(FH));
-i_writeppm_wiol($overlay,$io);
-close(FH);
+  my $bgcolor=i_color_new(255,0,0,0);
+  my $overlay=Imager::ImgRaw::new(200,70,3);
+  
+  my @bbox=Imager::i_wf_bbox($fontname, 50.0,'XMCLH');
+  print "#bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
+  
+  ok(Imager::i_wf_cp($fontname,$overlay,5,50,1,50.0,'XMCLH',1,1),
+     "i_wf_cp smoke test");
+  i_line($overlay,0,50,100,50,$bgcolor, 1);
+  
+  open(FH,">testout/t37w32font.ppm") || die "cannot open testout/t37w32font.ppm\n";
+  binmode(FH);
+  my $io = Imager::io_new_fd(fileno(FH));
+  i_writeppm_wiol($overlay,$io);
+  close(FH);
+  
+  $bgcolor=i_color_set($bgcolor,200,200,200,0);
+  my $backgr=Imager::ImgRaw::new(500,300,3);
+  
+  ok(Imager::i_wf_text($fontname,$backgr,100,100,$bgcolor,100,'MAW.',1, 1),
+     "i_wf_text smoke test");
+  i_line($backgr,0, 100, 499, 100, NC(0, 0, 255), 1);
+  
+  open(FH,">testout/t37w32font2.ppm") || die "cannot open testout/t37w32font2.ppm\n";
+  binmode(FH);
+  $io = Imager::io_new_fd(fileno(FH));
+  i_writeppm_wiol($backgr,$io);
+  close(FH);
+  
+  my $img = Imager->new(xsize=>200, ysize=>200);
+  my $font = Imager::Font->new(face=>$fontname, size=>20);
+  ok($img->string('x'=>30, 'y'=>30, string=>"Imager", color=>NC(255, 0, 0), 
+              font=>$font),
+     "string with win32 smoke test")
+    or print "# ",$img->errstr,"\n";
+  $img->write(file=>'testout/t37_oo.ppm') or print "not ";
+  my @bbox2 = $font->bounding_box(string=>'Imager');
+  is(@bbox2, 6, "got 6 values from bounding_box");
 
-print "ok 2\n";
-
-$bgcolor=i_color_set($bgcolor,200,200,200,0);
-$backgr=Imager::ImgRaw::new(500,300,3);
-
-Imager::i_wf_text($fontname,$backgr,100,100,$bgcolor,100,'MAW.',1, 1);
-i_line($backgr,0, 100, 499, 100, NC(0, 0, 255), 1);
-
-open(FH,">testout/t37w32font2.ppm") || die "cannot open testout/t37w32font2.ppm\n";
-binmode(FH);
-$io = Imager::io_new_fd(fileno(FH));
-i_writeppm_wiol($backgr,$io);
-close(FH);
-
-print "ok 3\n";
-
-my $img = Imager->new(xsize=>200, ysize=>200);
-my $font = Imager::Font->new(face=>$fontname, size=>20);
-$img->string('x'=>30, 'y'=>30, string=>"Imager", color=>NC(255, 0, 0), 
-            font=>$font);
-$img->write(file=>'testout/t37_oo.ppm') or print "not ";
-print "ok 4 # ",$img->errstr||'',"\n";
-my @bbox2 = $font->bounding_box(string=>'Imager');
-if (@bbox2 == 6) {
-  print "ok 5 # @bbox2\n";
-}
-else {
-  print "not ok 5\n";
+  # this only applies while the Win32 driver returns 6 values
+  # at this point we don't return the advance width from the low level
+  # bounding box function, so the Imager::Font::BBox advance method should
+  # return end_offset, check it does
+  my $bbox = $font->bounding_box(string=>"some text");
+  ok($bbox, "got the bounding box object");
+  is($bbox->advance_width, $bbox->end_offset, 
+     "check advance_width fallback correct");
 }