3 use Test::More tests => 13;
5 BEGIN { use_ok('Imager') }
7 -d "testout" or mkdir "testout";
9 require_ok('Imager::Font::Wrap');
11 my $img = Imager->new(xsize=>400, ysize=>400);
14 This is a test of text wrapping. This is a test of text wrapping. This =
15 is a test of text wrapping. This is a test of text wrapping. This is a =
16 test of text wrapping. This is a test of text wrapping. This is a test =
17 of text wrapping. This is a test of text wrapping. This is a test of =
20 Xxxxxxxxxxxxxxxxxxxxxxxxxxxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww xxxx.
22 This is a test of text wrapping. This is a test of text wrapping. This =
23 is a test of text wrapping. This is a test of text wrapping. This is a =
24 test of text wrapping. This is a test of text wrapping. This is a test =
25 of text wrapping. This is a test of text wrapping. This is a test of =
26 text wrapping. This is a test of text wrapping. This is a test of text =
27 wrapping. This is a test of text wrapping. This is a test of text =
28 wrapping. This is a test of text wrapping. This is a test of text =
29 wrapping. This is a test of text wrapping. This is a test of text =
35 my $fontfile = $ENV{WRAPTESTFONT} || $ENV{TTFONTTEST} || "fontfiles/ImUgly.ttf";
37 my $font = Imager::Font->new(file=>$fontfile);
41 $Imager::formats{'tt'} || $Imager::formats{'ft2'}
42 or skip("Need Freetype 1.x or 2.x to test", 11);
44 ok($font, "loading font")
45 or skip("Could not load test font", 8);
47 Imager::Font->priorities(qw(t1 ft2 tt));
48 ok(scalar Imager::Font::Wrap->wrap_text(string => $text,
57 ok($img->write(file=>'testout/t80wrapped.ppm'), "save to file");
58 ok(scalar Imager::Font::Wrap->wrap_text(string => $text,
67 my $bbox = $font->bounding_box(string=>"Xx", size=>13);
68 ok($bbox, "get height for check");
71 ok(scalar Imager::Font::Wrap->wrap_text
72 (string=>$text, font=>$font, image=>undef, size=>13, width=>380,
73 savepos=> \$used, height => $bbox->font_height), "savepos call");
74 ok($used > 20 && $used < length($text), "savepos value");
76 my @box = Imager::Font::Wrap->wrap_text
77 (string=>substr($text, 0, $used), font=>$font, image=>undef, size=>13,
80 ok(@box == 4, "bounds list count");
82 ok($box[3] == $bbox->font_height, "check height");
85 # http://rt.cpan.org/Ticket/Display.html?id=29771
86 # the length of the trailing line wasn't included in the text consumed
88 ok(scalar Imager::Font::Wrap->wrap_text
89 ( string => "test", font => $font, image => undef, size => 12,
90 width => 200, savepos => \$used, height => $bbox->font_height),
91 "regression 29771 - call wrap_text");
92 is($used, 4, "all text should be consumed");