#!perl -w
use strict;
-use Test::More tests => 158;
+use Test::More tests => 182;
++$|;
# 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", 181);
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", 181);
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
$im->line(x1=>0, y1=>110, x2=>139, y2=>110, color=>'blue');
for my $args ([ x=>5, text=>"A", color=>"white" ],
[ x=>40, text=>"y", color=>"white" ],
- [ x=>75, text=>"A", cp=>1 ],
- [ x=>110, text=>"y", cp=>1 ]) {
+ [ x=>75, text=>"A", channel=>1 ],
+ [ x=>110, text=>"y", channel=>1 ]) {
ok($im->string(%common, @$args, 'y'=>40), "A no alignment");
ok($im->string(%common, @$args, 'y'=>90, align=>1), "A align=1");
ok($im->string(%common, @$args, 'y'=>110, align=>0), "A align=0");
}
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");
+ $im->write(file => "foo.png");
+ 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");
+ }
}
sub align_test {
my @pos = $f->align(halign=>$h, valign=>$v, 'x'=>$x, 'y'=>$y,
image=>$img, size=>15, color=>'FFFFFF',
string=>"x$h ${v}y", channel=>1, aa=>1);
- @pos = $f->align(halign=>$h, valign=>$v, 'x'=>$x, 'y'=>$y,
- image=>$img, size=>15, color=>'FF99FF',
+ @pos = $img->align_string(halign=>$h, valign=>$v, 'x'=>$x, 'y'=>$y,
+ font=>$f, size=>15, color=>'FF99FF',
string=>"x$h ${v}y", aa=>1);
if (ok(@pos == 4, "$h $v aligned output")) {
# checking corners
cross($img, $pos[2], $cy, '0000FF');
}
else {
- SKIP: { skip("couldn't draw text", 8) };
+ SKIP: { skip("couldn't draw text", 7) };
}
-
}
sub okmatchcolor {