4 use Imager::Test qw(isnt_image);
5 use Test::More tests => 14;
7 # extracted from t/t36oofont.t
9 my $fontname_pfb = "fontfiles/dcr10.pfb";
11 my $green=Imager::Color->new(92,205,92,128);
12 die $Imager::ERRSTR unless $green;
13 my $red=Imager::Color->new(205, 92, 92, 255);
14 die $Imager::ERRSTR unless $red;
16 -d "testout" or mkdir "testout";
17 ok(-d "testout", "make output directory");
19 Imager::init_log("testout/t20oo.log", 1);
21 my $img=Imager->new(xsize=>300, ysize=>100) or die "$Imager::ERRSTR\n";
23 my $font=Imager::Font->new(file=>$fontname_pfb,size=>25, type => "t1")
24 or die $img->{ERRSTR};
26 ok(1, "created font");
28 ok($img->string(font=>$font, text=>"XMCLH", 'x'=>100, 'y'=>100),
30 $img->line(x1=>0, x2=>300, y1=>50, y2=>50, color=>$green);
33 my @bbox=$font->bounding_box(string=>$text, 'x'=>0, 'y'=>50);
35 is(@bbox, 8, "bounding box list length");
37 $img->box(box=>\@bbox, color=>$green);
40 $text = pack("C*", 0x41, 0xE2, 0x80, 0x90, 0x41);
41 ok($img->string(font=>$font, text=>$text, 'x'=>100, 'y'=>50, utf8=>1,
43 "draw 'utf8' hand-encoded text");
45 ok($img->string(font=>$font, text=>$text, 'x'=>140, 'y'=>50, utf8=>1,
46 underline=>1, channel=>2),
47 "channel 'utf8' hand-encoded text");
52 or skip("perl too old for native utf8", 2);
53 eval q{$text = "A\x{2010}A"};
54 ok($img->string(font=>$font, text=>$text, 'x'=>180, 'y'=>50,
56 "draw native UTF8 text");
57 ok($img->string(font=>$font, text=>$text, 'x'=>220, 'y'=>50, channel=>1),
58 "channel native UTF8 text");
61 ok($img->write(file=>"testout/t36oofont1.ppm", type=>'pnm'),
62 "write t36oofont1.ppm")
63 or print "# ",$img->errstr,"\n";
66 my $font1 = Imager::Font->new(file => $fontname_pfb, type => "t1");
67 my $font2 = Imager::Font::T1->new(file => $fontname_pfb);
69 for my $font ($font1, $font2) {
70 print "# ", join(",", $font->{color}->rgba), "\n";
72 my $im = Imager->new(xsize => 20, ysize => 20, channels => 4);
74 ok($im->string(text => "T", font => $font, y => 15),
75 "draw with default color")
76 or print "# ", $im->errstr, "\n";
77 my $work = Imager->new(xsize => 20, ysize => 20);
78 my $cmp = $work->copy;
79 $work->rubthrough(src => $im);
80 isnt_image($work, $cmp, "make sure something was drawn");
84 { # open a non-font as a font (test open failure)
85 local $ENV{LANG} = "C";
86 local $ENV{LC_ALL} = "C";
87 my $font = Imager::Font->new(file => "t/t20oo.t", type => "t1");
88 ok(!$font, "should fail to open test script as a font");
89 print "# ", Imager->errstr, "\n";
92 unless ($ENV{IMAGER_KEEP_FILES}) {
93 unlink "testout/t36oofont1.ppm";