From: Tony Cook Date: Wed, 20 Apr 2005 15:21:29 +0000 (+0000) Subject: - Imager::Font::BBox advance_width() method was falling back to X-Git-Tag: Imager-0.48^2~183 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/1fbba730d85cffccee3fe41717752e2b5beda282 - 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. --- diff --git a/Changes b/Changes index be79a261..34d375c7 100644 --- 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. ================================================================= diff --git a/lib/Imager/Font/BBox.pm b/lib/Imager/Font/BBox.pm index 2246a0be..4fe8ddfd 100644 --- a/lib/Imager/Font/BBox.pm +++ b/lib/Imager/Font/BBox.pm @@ -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() diff --git a/t/t37w32font.t b/t/t37w32font.t index 98afbd30..3e90195a 100644 --- a/t/t37w32font.t +++ b/t/t37w32font.t @@ -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"); }