Imager
view release on metacpan or search on metacpan
FT2/t/t10ft2.t view on Meta::CPAN
#!perl -w
use strict;
use Test::More;
use Cwd qw(getcwd abs_path);
use Imager qw(:all);
use Imager::Test qw(diff_text_with_nul is_color3 is_color4 isnt_image is_image);
-d "testout" or mkdir "testout";
my @test_output;
push @test_output, "t38ft2font.log";
Imager->open_log(log => "testout/t38ft2font.log");
my $deffont = "fontfiles/dodge.ttf";
my @base_color = (64, 255, 64);
SKIP:
{
ok($Imager::formats{ft2}, "ft2 should be in %formats");
my $fontname=$ENV{'TTFONTTEST'} || $deffont;
-f $fontname or skip("cannot find fontfile $fontname", 189);
print STDERR "FreeType2 runtime ", Imager::Font::FT2::i_ft2_version(1),
" compile-time ", Imager::Font::FT2::i_ft2_version(0), "\n";
my $bgcolor=i_color_new(255,0,0,0);
my $overlay=Imager::ImgRaw::new(200,70,3);
my $ttraw=Imager::Font::FT2::i_ft2_new($fontname, 0);
$ttraw or print Imager::_error_as_msg(),"\n";
ok($ttraw, "loaded raw font");
my @bbox=Imager::Font::FT2::i_ft2_bbox($ttraw, 50.0, 0, 'XMCLH', 0);
print "#bbox @bbox\n";
is(@bbox, 8, "i_ft2_bbox() returns 8 values");
ok(Imager::Font::FT2::i_ft2_cp($ttraw,$overlay,5,50,1,50.0,50, 'XMCLH',1,1, 0, 0), "drawn to channel");
i_line($overlay,0,50,100,50,$bgcolor,1);
push @test_output, "t38ft2font.ppm";
open(FH,">testout/t38ft2font.ppm") || die "cannot open testout/t38ft2font.ppm\n";
binmode(FH);
my $IO = Imager::io_new_fd(fileno(FH));
ok(i_writeppm_wiol($overlay, $IO), "saved image");
close(FH);
$bgcolor=i_color_set($bgcolor,200,200,200,0);
my $backgr=Imager::ImgRaw::new(500,300,3);
# i_tt_set_aa(2);
ok(Imager::Font::FT2::i_ft2_text($ttraw,$backgr,100,150,NC(255, 64, 64),200.0,50, 'MAW',1,1,0, 0), "drew MAW");
Imager::Font::FT2::i_ft2_settransform($ttraw, [0.9659, 0.2588, 0, -0.2588, 0.9659, 0 ]);
ok(Imager::Font::FT2::i_ft2_text($ttraw,$backgr,100,150,NC(0, 128, 0),200.0,50, 'MAW',0,1, 0, 0), "drew rotated MAW");
i_line($backgr, 0,150, 499, 150, NC(0, 0, 255),1);
push @test_output, "t38ft2font2.ppm";
open(FH,">testout/t38ft2font2.ppm") || die "cannot open testout/t38ft2font.ppm\n";
binmode(FH);
$IO = Imager::io_new_fd(fileno(FH));
ok(i_writeppm_wiol($backgr,$IO), "saved second image");
close(FH);
my $oof = Imager::Font->new(file=>$fontname, type=>'ft2', 'index'=>0);
ok($oof, "loaded OO font");
my $im = Imager->new(xsize=>400, ysize=>250);
ok($im->string(font=>$oof,
text=>"Via OO",
'x'=>20,
'y'=>20,
size=>60,
color=>NC(255, 128, 255),
aa => 1,
align=>0), "drawn through OO interface");
ok($oof->transform(matrix=>[1, 0.1, 0, 0, 1, 0]),
"set matrix via OO interface");
ok($im->string(font=>$oof,
text=>"Shear",
'x'=>20,
'y'=>40,
size=>60,
sizew=>50,
channel=>1,
aa=>1,
align=>1), "drawn transformed through OO");
use Imager::Matrix2d ':handy';
ok($oof->transform(matrix=>m2d_rotate(degrees=>-30)),
"set transform from m2d module");
ok($im->string(font=>$oof,
text=>"SPIN",
'x'=>20,
'y'=>50,
size=>50,
sizew=>40,
color=>NC(255,255,0),
aa => 1,
align=>0, vlayout=>0), "drawn first rotated");
ok($im->string(font=>$oof,
text=>"SPIN",
'x'=>20,
'y'=>50,
( run in 1.431 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )