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.)
11 BEGIN { $| = 1; print "1..38\n"; }
12 END {print "not ok 1\n" unless $loaded;}
15 require "t/testtools.pl";
22 init_log("testout/t30t1font.log",1);
24 my $deffont = './fontfiles/dcr10.pfb';
26 my $fontname_pfb=$ENV{'T1FONTTESTPFB'}||$deffont;
27 my $fontname_afm=$ENV{'T1FONTTESTAFM'}||'./fontfiles/dcr10.afm';
30 if (!(i_has_format("t1")) ) {
31 skipx(37, "t1lib unavailable or disabled");
33 elsif (! -f $fontname_pfb) {
34 skipx(37, "cannot find fontfile for type 1 test $fontname_pfb");
36 elsif (! -f $fontname_afm) {
37 skipx(37, "cannot find fontfile for type 1 test $fontname_afm");
44 my $fnum=Imager::i_t1_new($fontname_pfb,$fontname_afm); # this will load the pfb font
45 unless (okx($fnum >= 0, "load font $fontname_pfb")) {
46 skipx(31, "without the font I can't do a thing");
50 my $bgcolor=Imager::Color->new(255,0,0,0);
51 my $overlay=Imager::ImgRaw::new(200,70,3);
53 okx(i_t1_cp($overlay,5,50,1,$fnum,50.0,'XMCLH',5,1), "i_t1_cp");
55 i_line($overlay,0,50,100,50,$bgcolor,1);
57 my @bbox=i_t1_bbox(0,50.0,'XMCLH',5);
58 okx(@bbox == 7, "i_t1_bbox");
59 print "# bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
61 open(FH,">testout/t30t1font.ppm") || die "cannot open testout/t35t1font.ppm\n";
62 binmode(FH); # for os2
63 my $IO = Imager::io_new_fd( fileno(FH) );
64 i_writeppm_wiol($overlay,$IO);
67 $bgcolor=Imager::Color::set($bgcolor,200,200,200,0);
68 my $backgr=Imager::ImgRaw::new(280,300,3);
71 okx(i_t1_text($backgr,10,100,$bgcolor,$fnum,150.0,'test',4,1), "i_t1_text");
74 # for perl < 5.6 we can hand-encode text
75 # since T1 doesn't support over 256 chars in an encoding we just drop
77 # the following is "A\xA1\x{2010}A"
79 my $text = pack("C*", 0x41, 0xC2, 0xA1, 0xE2, 0x80, 0x90, 0x41);
80 my $alttext = "A\xA1A";
82 my @utf8box = i_t1_bbox($fnum, 50.0, $text, length($text), 1);
83 okx(@utf8box == 7, "utf8 bbox element count");
84 my @base = i_t1_bbox($fnum, 50.0, $alttext, length($alttext), 0);
85 okx(@base == 7, "alt bbox element count");
86 my $maxdiff = $fontname_pfb eq $deffont ? 0 : $base[2] / 3;
87 print "# (@utf8box vs @base)\n";
88 okx(abs($utf8box[2] - $base[2]) <= $maxdiff,
89 "compare box sizes $utf8box[2] vs $base[2] (maxerror $maxdiff)");
91 # hand-encoded UTF8 drawing
92 okx(i_t1_text($backgr, 10, 140, $bgcolor, $fnum, 32, $text, length($text), 1,1), "draw hand-encoded UTF8");
94 okx(i_t1_cp($backgr, 80, 140, 1, $fnum, 32, $text, length($text), 1, 1),
95 "cp hand-encoded UTF8");
97 # ok, try native perl UTF8 if available
100 # we need to do this in eval to prevent compile time errors in older
102 eval q{$text = "A\xA1\x{2010}A"}; # A, a with ogonek, HYPHEN, A in our test font
103 #$text = "A".chr(0xA1).chr(0x2010)."A"; # this one works too
104 okx(i_t1_text($backgr, 10, 180, $bgcolor, $fnum, 32, $text, length($text), 1),
106 okx(i_t1_cp($backgr, 80, 180, 1, $fnum, 32, $text, length($text), 1),
108 @utf8box = i_t1_bbox($fnum, 50.0, $text, length($text), 0);
109 okx(@utf8box == 7, "native utf8 bbox element count");
110 okx(abs($utf8box[2] - $base[2]) <= $maxdiff,
111 "compare box sizes native $utf8box[2] vs $base[2] (maxerror $maxdiff)");
112 eval q{$text = "A\xA1\xA2\x01\x1F\x{0100}A"};
113 okx(i_t1_text($backgr, 10, 220, $bgcolor, $fnum, 32, $text, 0, 1, 0, "uso"),
114 "more complex output");
117 skipx(5, "perl too old to test native UTF8 support");
120 open(FH,">testout/t30t1font2.ppm") || die "cannot open testout/t35t1font.ppm\n";
122 $IO = Imager::io_new_fd( fileno(FH) );
123 i_writeppm_wiol($backgr, $IO);
126 my $rc=i_t1_destroy($fnum);
127 unless (okx($rc >= 0, "i_t1_destroy")) {
128 print "# i_t1_destroy failed: rc=$rc\n";
131 print "# debug: ",join(" x ",i_t1_bbox(0,50,"eses",4) ),"\n";
132 print "# debug: ",join(" x ",i_t1_bbox(0,50,"llll",4) ),"\n";
134 unlink "t1lib.log"; # lose it if it exists
136 okx(!-e("t1lib.log"), "disable t1log");
138 okx(-e("t1lib.log"), "enable t1log");
142 # character existance tests - uses the special ExistenceTest font
143 my $exists_font = 'fontfiles/ExistenceTest.pfb';
144 my $exists_afm = 'fontfiles/ExistenceText.afm';
146 -e $exists_font or die;
148 my $font_num = Imager::i_t1_new($exists_font, $exists_afm);
149 if (okx($font_num >= 0, 'loading test font')) {
150 # first the list interface
151 my @exists = Imager::i_t1_has_chars($font_num, "!A");
152 okx(@exists == 2, "return count from has_chars");
153 okx($exists[0], "we have an exclamation mark");
154 okx(!$exists[1], "we have no uppercase A");
156 # then the scalar interface
157 my $exists = Imager::i_t1_has_chars($font_num, "!A");
158 okx(length($exists) == 2, "return scalar length");
159 okx(ord(substr($exists, 0, 1)), "we have an exclamation mark");
160 okx(!ord(substr($exists, 1, 1)), "we have no upper-case A");
163 skipx(6, 'Could not load test font');
166 my $font = Imager::Font->new(file=>$exists_font, type=>'t1');
167 if (okx($font, "loaded OO font")) {
168 my @exists = $font->has_chars(string=>"!A");
169 okx(@exists == 2, "return count from has_chars");
170 okx($exists[0], "we have an exclamation mark");
171 okx(!$exists[1], "we have no uppercase A");
173 # then the scalar interface
174 my $exists = $font->has_chars(string=>"!A");
175 okx(length($exists) == 2, "return scalar length");
176 okx(ord(substr($exists, 0, 1)), "we have an exclamation mark");
177 okx(!ord(substr($exists, 1, 1)), "we have no upper-case A");
179 # check the advance width
180 my @bbox = $font->bounding_box(string=>'/', size=>100);
182 okx($bbox[2] != $bbox[5], "different advance to pos_width");
185 my $face_name = Imager::i_t1_face_name($font->{id});
186 print "# face $face_name\n";
187 okx($face_name eq 'ExistenceTest', "face name");
188 $face_name = $font->face_name;
189 okx($face_name eq 'ExistenceTest', "face name");
191 my @glyph_names = $font->glyph_names(string=>"!J/");
192 okx($glyph_names[0] eq 'exclam', "check exclam name OO");
193 okx(!defined($glyph_names[1]), "check for no J name OO");
194 okx($glyph_names[2] eq 'slash', "check slash name OO");
197 skipx(12, "Could not load test font");