#!perl -w
use strict;
-use lib 't';
-use Test::More tests => 158;
+use Test::More tests => 183;
++$|;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
BEGIN { use_ok(Imager => ':all') }
+use Imager::Test qw(diff_text_with_nul is_color3);
+
init_log("testout/t38ft2font.log",2);
my @base_color = (64, 255, 64);
SKIP:
{
- i_has_format("ft2") or skip("no freetype2 library found", 157);
+ i_has_format("ft2") or skip("no freetype2 library found", 182);
print "# has ft2\n";
my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
- -f $fontname or skip("cannot find fontfile $fontname", 157);
+ -f $fontname or skip("cannot find fontfile $fontname", 182);
my $bgcolor=i_color_new(255,0,0,0);
ok(@got == 2, "has_chars returned 2 items");
ok(!$got[0], "have no chr(1)");
ok($got[1], "have 'H'");
- ok($oof->has_chars(string=>"H\x01") eq "\x01\x00",
+ is($oof->has_chars(string=>"H\x01"), "\x01\x00",
"scalar has_chars()");
print "# OO bounding boxes\n";
if (Imager::Font::FreeType2::i_ft2_can_face_name()) {
my $facename = Imager::Font::FreeType2::i_ft2_face_name($exfont->{id});
print "# face name '$facename'\n";
- ok($facename eq 'ExistenceTest', "test face name");
+ is($facename, 'ExistenceTest', "test face name");
$facename = $exfont->face_name;
- ok($facename eq 'ExistenceTest', "test face name OO");
+ is($facename, 'ExistenceTest', "test face name OO");
}
else {
# make sure we get the error we expect
}
ok($im->write(file=>'testout/t38align.ppm'), "save align image");
}
+
+
+ { # outputting a space in non-AA could either crash
+ # or fail (ft 2.2+)
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ my $im = Imager->new(xsize => 100, ysize => 100);
+ ok($im->string(x => 10, y => 10, string => "test space", aa => 0,
+ color => '#FFF', size => 8, font => $font),
+ "draw space non-antialiased (color)");
+ ok($im->string(x => 10, y => 50, string => "test space", aa => 0,
+ channel => 0, size => 8, font => $font),
+ "draw space non-antialiased (channel)");
+ }
+
+ { # cannot output "0"
+ # https://rt.cpan.org/Ticket/Display.html?id=21770
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ ok($font, "loaded imugly");
+ my $imbase = Imager->new(xsize => 100, ysize => 100);
+ my $im = $imbase->copy;
+ ok($im->string(x => 10, y => 50, string => "0", aa => 0,
+ color => '#FFF', size => 20, font => $font),
+ "draw '0'");
+ ok(Imager::i_img_diff($im->{IMG}, $imbase->{IMG}),
+ "make sure we actually drew it");
+ $im = $imbase->copy;
+ ok($im->string(x => 10, y => 50, string => 0.0, aa => 0,
+ color => '#FFF', size => 20, font => $font),
+ "draw 0.0");
+ ok(Imager::i_img_diff($im->{IMG}, $imbase->{IMG}),
+ "make sure we actually drew it");
+ }
+ { # string output cut off at NUL ('\0')
+ # https://rt.cpan.org/Ticket/Display.html?id=21770 cont'd
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ ok($font, "loaded imugly");
+
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, color => '#FFFFFF');
+ diff_text_with_nul("a\\0b vs a", "a\0b", "a",
+ font => $font, channel => 1);
+
+ # UTF8 encoded \x{2010}
+ my $dash = pack("C*", 0xE2, 0x80, 0x90);
+ diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
+ font => $font, color => '#FFFFFF', utf8 => 1);
+ diff_text_with_nul("utf8 dash\0dash vs dash", "$dash\0$dash", $dash,
+ font => $font, channel => 1, utf8 => 1);
+ }
+
+ { # RT 11972
+ # when rendering to a transparent image the coverage should be
+ # expressed in terms of the alpha channel rather than the color
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ my $im = Imager->new(xsize => 40, ysize => 20, channels => 4);
+ ok($im->string(string => "AB", size => 20, aa => 1, color => '#F00',
+ x => 0, y => 15, font => $font),
+ "draw to transparent image");
+ my $im_noalpha = $im->convert(preset => 'noalpha');
+ my $im_pal = $im->to_paletted(make_colors => 'mediancut');
+ my @colors = $im_pal->getcolors;
+ is(@colors, 2, "should be only 2 colors");
+ @colors = sort { ($a->rgba)[0] <=> ($b->rgba)[0] } @colors;
+ is_color3($colors[0], 0, 0, 0, "check we got black");
+ is_color3($colors[1], 255, 0, 0, "and red");
+ }
+
+ { # RT 27546
+ my $im = Imager->new(xsize => 100, ysize => 100, channels => 4);
+ $im->box(filled => 1, color => '#ff0000FF');
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ ok($im->string(x => 0, 'y' => 40, text => 'test',
+ size => 11, sizew => 11, font => $font, aa => 1),
+ 'draw on translucent image')
+ }
}
sub align_test {
else {
SKIP: { skip("couldn't draw text", 7) };
}
-
}
sub okmatchcolor {