2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl test.pl'
5 ######################### We start with some black magic to print on failure.
7 # Change 1..1 below to 1..last_test_to_print .
8 # (It may become useful if the test is moved to ./t subdirectory.)
10 BEGIN { $| = 1; print "1..14\n"; }
11 END {print "not ok 1\n" unless $loaded;}
16 init_log("testout/t38ft2font.log",1);
20 print "ok $_ # skip no Freetype2 library\n";
26 if (!(i_has_format("ft2")) ) { skip(); }
29 $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
32 print "# cannot find fontfile for truetype test $fontname\n";
39 $bgcolor=i_color_new(255,0,0,0);
40 $overlay=Imager::ImgRaw::new(200,70,3);
42 $ttraw=Imager::Font::FreeType2::i_ft2_new($fontname, 0);
44 $ttraw or print Imager::_error_as_msg(),"\n";
48 @bbox=Imager::Font::FreeType2::i_ft2_bbox($ttraw, 50.0, 0, 'XMCLH', 0);
49 print "#bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
51 Imager::Font::FreeType2::i_ft2_cp($ttraw,$overlay,5,50,1,50.0,50, 'XMCLH',1,1, 0, 0);
52 i_draw($overlay,0,50,100,50,$bgcolor);
54 open(FH,">testout/t38ft2font.ppm") || die "cannot open testout/t38ft2font.ppm\n";
56 my $IO = Imager::io_new_fd(fileno(FH));
57 i_writeppm_wiol($overlay, $IO);
64 $bgcolor=i_color_set($bgcolor,200,200,200,0);
65 $backgr=Imager::ImgRaw::new(500,300,3);
68 Imager::Font::FreeType2::i_ft2_text($ttraw,$backgr,100,150,NC(255, 64, 64),200.0,50, 'MAW',1,1,0, 0);
69 Imager::Font::FreeType2::i_ft2_settransform($ttraw, [0.9659, 0.2588, 0, -0.2588, 0.9659, 0 ]);
70 Imager::Font::FreeType2::i_ft2_text($ttraw,$backgr,100,150,NC(0, 128, 0),200.0,50, 'MAW',0,1, 0, 0);
71 i_draw($backgr, 0,150, 499, 150, NC(0, 0, 255));
73 open(FH,">testout/t38ft2font2.ppm") || die "cannot open testout/t38ft2font.ppm\n";
75 $IO = Imager::io_new_fd(fileno(FH));
76 i_writeppm_wiol($backgr,$IO);
81 #$fontname = 'fontfiles/arial.ttf';
82 my $oof = Imager::Font->new(file=>$fontname, type=>'ft2', 'index'=>0)
86 my $im = Imager->new(xsize=>400, ysize=>250);
88 $im->string(font=>$oof,
93 color=>NC(255, 128, 255),
95 align=>0) or print "not ";
97 $oof->transform(matrix=>[1, 0.1, 0, 0, 1, 0])
100 $im->string(font=>$oof,
108 align=>1) or print "not ";
110 use Imager::Matrix2d ':handy';
111 $oof->transform(matrix=>m2d_rotate(degrees=>-30));
112 #$oof->transform(matrix=>m2d_identity());
113 $im->string(font=>$oof,
119 color=>NC(255,255,0),
121 align=>0, vlayout=>0)
123 $im->string(font=>$oof,
131 align=>0, vlayout=>0) or print "not ";
134 $oof->transform(matrix=>m2d_identity());
135 $oof->hinting(hinting=>1);
138 # the test font (dodge.ttf) only supports one character above 0xFF that
139 # I can see, 0x2010 HYPHEN (which renders the same as 0x002D HYPHEN MINUS)
140 # an attempt at utf8 support
141 # first attempt to use native perl UTF8
144 # we need to do this in eval to prevent compile time errors in older
146 eval q{$text = "A\x{2010}A"}; # A, HYPHEN, A in our test font
147 #$text = "A".chr(0x2010)."A"; # this one works too
148 if ($im->string(font=>$oof,
158 print "not ok 9 # ",$im->errstr,"\n";
162 print "ok 9 # skip no native UTF8 support in this version of perl\n";
165 # an attempt using emulation of UTF8
166 my $text = pack("C*", 0x41, 0xE2, 0x80, 0x90, 0x41);
167 #my $text = "A\xE2\x80\x90\x41\x{2010}";
168 #substr($text, -1, 0) = '';
169 if ($im->string(font=>$oof,
174 color=>NC(255,128,0),
180 print "not ok 10 # ",$im->errstr,"\n";
184 # well it was - it demostrates what happens when you combine
185 # transformations and font hinting
186 for my $steps (0..39) {
187 $oof->transform(matrix=>m2d_rotate(degrees=>-$steps+5));
188 # demonstrates why we disable hinting on a doing a transform
189 # if the following line is enabled then the 0 degrees output sticks
191 # $oof->hinting(hinting=>1);
192 $im->string(font=>$oof,
197 color=>NC(255, $steps * 5, 200-$steps * 5),
199 align=>0, ) or print "not ";
202 $im->write(file=>'testout/t38_oo.ppm')
203 or print "# could not save OO output: ",$im->errstr,"\n";
205 my (@got) = $oof->has_chars(string=>"\x01H");
206 @got == 2 or print "not ";
208 $got[0] and print "not ";
209 print "ok 12 # check if \\x01 is defined\n";
210 $got[1] or print "not ";
211 print "ok 13 # check if 'H' is defined\n";
212 $oof->has_chars(string=>"H\x01") eq "\x01\x00" or print "not ";