#!perl -w
use strict;
-use Test::More tests => 144;
+use lib 't';
+use Test::More tests => 158;
++$|;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
SKIP:
{
- i_has_format("ft2") or skip("no freetype2 library found", 137);
+ i_has_format("ft2") or skip("no freetype2 library found", 157);
print "# has ft2\n";
my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
- -f $fontname or skip("cannot find fontfile $fontname", 137);
+ -f $fontname or skip("cannot find fontfile $fontname", 157);
my $bgcolor=i_color_new(255,0,0,0);
"check display width (roughly)");
# check with a char that fits inside the box
- my $bbox = $exfont->bounding_box(string=>"!", size=>100);
+ $bbox = $exfont->bounding_box(string=>"!", size=>100);
print "# pos width ", $bbox->pos_width, "\n";
is($bbox->pos_width, $bbox->advance_width,
"check backwards compatibility");
}
ok($mmim->write(file=>"testout/t38mm.ppm"), "save MM output");
+
+ SKIP:
+ { print "# alignment tests\n";
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ ok($font, "loaded deffont OO")
+ or skip("could not load font:".Imager->errstr, 4);
+ my $im = Imager->new(xsize=>140, ysize=>150);
+ my %common =
+ (
+ font=>$font,
+ size=>40,
+ aa=>1,
+ );
+ $im->line(x1=>0, y1=>40, x2=>139, y2=>40, color=>'blue');
+ $im->line(x1=>0, y1=>90, x2=>139, y2=>90, color=>'blue');
+ $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", 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");
+ }
}
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 {