]> git.imager.perl.org - imager.git/blob - t/t36oofont.t
added has_chars() method to Imager::Font::FreeType2
[imager.git] / t / t36oofont.t
1 #!/usr/bin/perl -w
2 use strict;
3
4 #use lib qw(blib/lib blib/arch);
5
6 # Before `make install' is performed this script should be runnable with
7 # `make test'. After `make install' it should work as `perl test.pl'
8
9 ######################### We start with some black magic to print on failure.
10
11 # Change 1..1 below to 1..last_test_to_print .
12 # (It may become useful if the test is moved to ./t subdirectory.)
13
14 BEGIN { $| = 1; print "1..7\n"; }
15 END {print "not ok 1\n" unless $::loaded;}
16 use Imager;
17 $::loaded=1;
18 print "ok 1\n";
19
20 init_log("testout/t36oofont.log", 1);
21
22 my $fontname_tt=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
23 my $fontname_pfb=$ENV{'T1FONTTESTPFB'}||'./fontfiles/dcr10.pfb';
24
25
26 my $green=Imager::Color->new(92,205,92,128);
27 die $Imager::ERRSTR unless $green;
28 my $red=Imager::Color->new(205, 92, 92, 255);
29 die $Imager::ERRSTR unless $red;
30
31
32
33 if (i_has_format("t1") and -f $fontname_pfb) {
34
35   my $img=Imager->new(xsize=>300, ysize=>100) or die "$Imager::ERRSTR\n";
36
37   my $font=Imager::Font->new(file=>$fontname_pfb,size=>25)
38     or die $img->{ERRSTR};
39
40   print "ok 2\n";
41
42   $img->string(font=>$font, text=>"XMCLH", 'x'=>100, 'y'=>100) 
43     or die $img->{ERRSTR};
44
45   print "ok 3\n";
46
47   $img->line(x1=>0, x2=>300, y1=>50, y2=>50, color=>$green);
48
49   my $text="LLySja";
50   my @bbox=$font->bounding_box(string=>$text, 'x'=>0, 'y'=>50);
51
52   print @bbox ? '' : 'not ', "ok 4\n";
53
54   $img->box(box=>\@bbox, color=>$green);
55
56   $img->write(file=>"testout/t36oofont1.ppm", type=>'pnm')
57     or die "cannot write to testout/t36oofont1.ppm: $img->{ERRSTR}\n";
58
59 } else {
60   print "ok 2 # skip\n";
61   print "ok 3 # skip\n";
62   print "ok 4 # skip\n";
63 }
64
65 if (i_has_format("tt") and -f $fontname_tt) {
66
67   my $img=Imager->new(xsize=>300, ysize=>100) or die "$Imager::ERRSTR\n";
68
69   my $font=Imager::Font->new(file=>$fontname_tt,size=>25)
70     or die $img->{ERRSTR};
71
72   print "ok 5\n";
73
74   $img->string(font=>$font, text=>"XMCLH", 'x'=>100, 'y'=>100) 
75     or die $img->{ERRSTR};
76
77   print "ok 6\n";
78
79   $img->line(x1=>0, x2=>300, y1=>50, y2=>50, color=>$green);
80
81   my $text="LLySja";
82   my @bbox=$font->bounding_box(string=>$text, 'x'=>0, 'y'=>50);
83
84   print @bbox ? '' : 'not ', "ok 7\n";
85
86   $img->box(box=>\@bbox, color=>$green);
87
88   $img->write(file=>"testout/t36oofont2.ppm", type=>'pnm')
89     or die "cannot write to testout/t36oofont2.ppm: $img->{ERRSTR}\n";
90
91 } else {
92   print "ok 5 # skip\n";
93   print "ok 6 # skip\n";
94   print "ok 7 # skip\n";
95 }
96