+
+ # check that error codes are translated correctly
+ my $errfont = Imager::Font->new(file=>"t/t38ft2font.t", type=>"ft2");
+ is($errfont, undef, "new font vs non font");
+ cmp_ok(Imager->errstr, '=~', qr/unknown file format/, "check error message");
+
+ # Multiple Master tests
+ # we check a non-MM font errors correctly
+ print "# check that the methods act correctly for a non-MM font\n";
+ ok(!$exfont->is_mm, "exfont not MM");
+ ok((() = $exfont->mm_axes) == 0, "exfont has no MM axes");
+ cmp_ok(Imager->errstr, '=~', qr/no multiple masters/,
+ "and returns correct error when we ask");
+ ok(!$exfont->set_mm_coords(coords=>[0, 0]), "fail setting axis on exfont");
+ cmp_ok(Imager->errstr, '=~', qr/no multiple masters/,
+ "and returns correct error when we ask");
+
+ # try a MM font now - test font only has A defined
+ print "# Try a multiple master font\n";
+ my $mmfont = Imager::Font->new(file=>"fontfiles/MMOne.pfb", type=>"ft2",
+ color=>"white", aa=>1, size=>60);
+ ok($mmfont, "loaded MM font");
+ ok($mmfont->is_mm, "font is multiple master");
+ my @axes = $mmfont->mm_axes;
+ is(@axes, 2, "check we got both axes");
+ is($axes[0][0], "Weight", "name of first axis");
+ is($axes[0][1], 50, "min for first axis");
+ is($axes[0][2], 999, "max for first axis");
+ is($axes[1][0], "Slant", "name of second axis");
+ is($axes[1][1], 0, "min for second axis");
+ is($axes[1][2], 999, "max for second axis");
+ my $mmim = Imager->new(xsize=>200, ysize=>200);
+ $mmim->string(font=>$mmfont, x=>0, 'y'=>50, text=>"A");
+ ok($mmfont->set_mm_coords(coords=>[ 700, 0 ]), "set to bold, unsloped");
+ $mmim->string(font=>$mmfont, x=>0, 'y'=>100, text=>"A", color=>'blue');
+ my @weights = qw(50 260 525 760 999);
+ my @slants = qw(0 333 666 999);
+ for my $windex (0 .. $#weights) {
+ my $weight = $weights[$windex];
+ for my $sindex (0 .. $#slants) {
+ my $slant = $slants[$sindex];
+ $mmfont->set_mm_coords(coords=>[ $weight, $slant ]);
+ $mmim->string(font=>$mmfont, x=>30+32*$windex, 'y'=>50+45*$sindex,
+ text=>"A");
+ }
+ }
+
+ 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");
+ }
+
+
+ { # 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");