]> git.imager.perl.org - imager.git/blob - t/t37w32font.t
new samples
[imager.git] / t / t37w32font.t
1 #!perl -w
2 BEGIN { $| = 1; print "1..5\n"; }
3 END {print "not ok 1\n" unless $loaded;}
4 use Imager qw(:all);
5 $loaded = 1;
6 print "ok 1\n";
7
8 init_log("testout/t37w32font.log",1);
9
10 sub skip { 
11   for (2..5) {
12     print "ok $_ # skip not MS Windows\n";
13   }
14   malloc_state();
15   exit(0);
16 }
17
18 i_has_format('w32') or skip();
19 print "# has w32\n";
20
21 $fontname=$ENV{'TTFONTTEST'} || 'Times New Roman Bold';
22
23 # i_init_fonts(); # unnecessary for Win32 font support
24
25 $bgcolor=i_color_new(255,0,0,0);
26 $overlay=Imager::ImgRaw::new(200,70,3);
27
28 @bbox=Imager::i_wf_bbox($fontname, 50.0,'XMCLH');
29 print "#bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
30
31 Imager::i_wf_cp($fontname,$overlay,5,50,1,50.0,'XMCLH',1,1);
32 i_line($overlay,0,50,100,50,$bgcolor, 1);
33
34 open(FH,">testout/t37w32font.ppm") || die "cannot open testout/t37w32font.ppm\n";
35 binmode(FH);
36 $io = Imager::io_new_fd(fileno(FH));
37 i_writeppm_wiol($overlay,$io);
38 close(FH);
39
40 print "ok 2\n";
41
42 $bgcolor=i_color_set($bgcolor,200,200,200,0);
43 $backgr=Imager::ImgRaw::new(500,300,3);
44
45 Imager::i_wf_text($fontname,$backgr,100,100,$bgcolor,100,'MAW.',1, 1);
46 i_line($backgr,0, 100, 499, 100, NC(0, 0, 255), 1);
47
48 open(FH,">testout/t37w32font2.ppm") || die "cannot open testout/t37w32font2.ppm\n";
49 binmode(FH);
50 $io = Imager::io_new_fd(fileno(FH));
51 i_writeppm_wiol($backgr,$io);
52 close(FH);
53
54 print "ok 3\n";
55
56 my $img = Imager->new(xsize=>200, ysize=>200);
57 my $font = Imager::Font->new(face=>$fontname, size=>20);
58 $img->string('x'=>30, 'y'=>30, string=>"Imager", color=>NC(255, 0, 0), 
59              font=>$font);
60 $img->write(file=>'testout/t37_oo.ppm') or print "not ";
61 print "ok 4 # ",$img->errstr||'',"\n";
62 my @bbox2 = $font->bounding_box(string=>'Imager');
63 if (@bbox2 == 6) {
64   print "ok 5 # @bbox2\n";
65 }
66 else {
67   print "not ok 5\n";
68 }