wrap.t
上传用户:qdrechuli
上传日期:2022-08-01
资源大小:917k
文件大小:2k
- BEGIN { $| = 1; print "1..13n"; }
- END {print "not ok 1n" unless $loaded;}
- use GD;
- use GD::Text::Wrap;
- $loaded = 1;
- print "ok 1n";
- $text = <<EOSTR;
- Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
- sed diam nonummy nibh euismod tincidunt ut laoreet dolore
- magna aliquam erat volutpat.
- EOSTR
- $i = 2;
- # Create a GD:Image object
- $gd = GD::Image->new(170,150);
- print 'not ' unless defined $gd;
- printf "ok %dn", $i++;
- # Allocate colours
- $gd->colorAllocate(255,255,255);
- $gd->colorAllocate( 0, 0, 0);
- print 'not ' unless $gd->colorsTotal == 2;
- printf "ok %dn", $i++;
- # Create a GD::Text::Wrap object
- $wp = GD::Text::Wrap->new($gd, text => $text);
- print 'not ' unless defined $wp;
- printf "ok %dn", $i++;
- $wp->set(align => 'left', width => 130);
- # Get the bounding box
- @bb = $wp->get_bounds(20,10);
- #print "$i: @bbn";
- print 'not ' unless "@bb" eq '20 10 150 128';
- printf "ok %dn", $i++;
- # Draw, and check that the result is the same
- @bb2 = $wp->draw(20,10);
- print 'not ' unless "@bb" eq "@bb2";
- printf "ok %dn", $i++;
- $wp->set(align => 'left');
- @bb2 = $wp->draw(20,10);
- print 'not ' unless "@bb" eq "@bb2";
- printf "ok %dn", $i++;
- $wp->set(align => 'justified');
- @bb2 = $wp->draw(20,10);
- print 'not ' unless "@bb" eq "@bb2";
- printf "ok %dn", $i++;
- $wp->set(align => 'right');
- @bb2 = $wp->draw(20,10);
- print 'not ' unless "@bb" eq "@bb2";
- printf "ok %dn", $i++;
- @bb = "20 10 150 143";
- $wp->set(preserve_nl => 1);
- @bb2 = $wp->draw(20,10);
- #print "$i: @bb2n";
- print 'not ' unless "@bb" eq "@bb2";
- printf "ok %dn", $i++;
- $wp->set(preserve_nl => 0);
- # TTF
- if ($wp->can_do_ttf)
- {
- $rc = $wp->set_font('cetus.ttf', 10);
- print 'not ' unless $rc;
- printf "ok %dn", $i++;
- # Get the bounding box
- @bb = $wp->get_bounds(20,10);
- #print "$i: @bbn";
- print 'not ' unless "@bb" eq '20 10 150 170';
- printf "ok %dn", $i++;
- @bb2 = $wp->draw(20,10);
- print 'not ' unless "@bb" eq "@bb2";
- printf "ok %dn", $i++;
- }
- else
- {
- for (1 .. 3) { printf "ok %d # Skipn", $i++ };
- }
- __END__
- #Only here to test the test.
- open(GD, '>/tmp/wrap.png') or die $!;
- binmode GD;
- print GD $gd->png();
- close GD;