]> git.imager.perl.org - imager.git/blobdiff - t/t35ttfont.t
skip the loop tests with older (un)giflibs
[imager.git] / t / t35ttfont.t
index e5572d68a2aa6a72b1199a4b4982f2ffd343a08b..3a0d7dc72722732d156a658491f9b2b9241f23a2 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use lib 't';
-use Test::More tests => 49;
+use Test::More tests => 72;
 
 BEGIN { use_ok(Imager => ':all') }
 require "t/testtools.pl";
@@ -10,7 +10,7 @@ init_log("testout/t35ttfont.log",2);
 
 SKIP:
 {
-  skip("freetype 1.x unavailable or disabled", 48
+  skip("freetype 1.x unavailable or disabled", 71
     unless i_has_format("tt");
   print "# has tt\n";
   
@@ -19,7 +19,7 @@ SKIP:
 
   if (!ok(-f $fontname, "check test font file exists")) {
     print "# cannot find fontfile for truetype test $fontname\n";
-    skip('Cannot load test font', 47);
+    skip('Cannot load test font', 70);
   }
 
   i_init_fonts();
@@ -31,11 +31,11 @@ SKIP:
   my $ttraw = Imager::i_tt_new($fontname);
   ok($ttraw, "create font");
 
-  my @bbox = i_tt_bbox($ttraw,50.0,'XMCLH',5,0);
+  my @bbox = i_tt_bbox($ttraw,50.0,'XMCLH',6,0);
   is(@bbox, 8, "bounding box");
   print "#bbox: ($bbox[0], $bbox[1]) - ($bbox[2], $bbox[3])\n";
 
-  ok(i_tt_cp($ttraw,$overlay,5,50,1,50.0,'XMCLH',5,1,0), "cp output");
+  ok(i_tt_cp($ttraw,$overlay,5,50,1,50.0,'XM CLH',6,1,0), "cp output");
   i_line($overlay,0,50,100,50,$bgcolor,1);
 
   open(FH,">testout/t35ttfont.ppm") || die "cannot open testout/t35ttfont.ppm\n";
@@ -49,7 +49,7 @@ SKIP:
   
   #     i_tt_set_aa(2);
   
-  ok(i_tt_text($ttraw,$backgr,100,120,$bgcolor,50.0,'test',4,1,0),
+  ok(i_tt_text($ttraw,$backgr,100,120,$bgcolor,50.0,'te st',5,1,0),
       "normal output");
 
   my $ugly = Imager::i_tt_new("./fontfiles/ImUgly.ttf");
@@ -57,7 +57,7 @@ SKIP:
   # older versions were dropping the bottom of g and the right of a
   ok(i_tt_text($ugly, $backgr,100, 80, $bgcolor, 14, 'g%g', 3, 1, 0), 
      "draw g%g");
-  ok(i_tt_text($ugly, $backgr,150, 80, $bgcolor, 14, 'delta', 5, 1, 0),
+  ok(i_tt_text($ugly, $backgr,150, 80, $bgcolor, 14, 'delta', 6, 1, 0),
       "draw delta");
   i_line($backgr,0,20,499,20,i_color_new(0,127,0,0),1);
   ok(i_tt_text($ttraw, $backgr, 20, 20, $bgcolor, 14, 'abcdefghijklmnopqrstuvwxyz{|}', 29, 1, 0), "alphabet");
@@ -175,7 +175,7 @@ SKIP:
   undef $hcfont;
   
   my $name_font = "fontfiles/NameTest.ttf";
-  $hcfont = Imager::Font->new(file=>$name_font);
+  $hcfont = Imager::Font->new(file=>$name_font, type=>'tt');
  SKIP:
   {
     ok($hcfont, "loading name font")
@@ -194,5 +194,69 @@ SKIP:
 
   undef $hcfont;
   
+ SKIP:
+  { print "# alignment tests\n";
+    my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'tt');
+    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/t35align.ppm'), "save align image");
+  }
+
+  { # Ticket #14804 Imager::Font->new() doesn't report error details
+    # when using freetype 1
+    # make sure we're using C locale for messages
+    use POSIX qw(setlocale LC_ALL);
+    setlocale(LC_ALL, "C");
+
+    my $font = Imager::Font->new(file=>'t/t35ttfont.t', type=>'tt');
+    ok(!$font, "font creation should have failed for invalid file");
+    cmp_ok(Imager->errstr, 'eq', 'Invalid file format.',
+         "test error message");
+
+    setlocale(LC_ALL, "");
+  }
+
+  { # check errstr set correctly
+    my $font = Imager::Font->new(file=>$fontname, type=>'tt',
+                               size => undef);
+    ok($font, "made size error test font");
+    my $im = Imager->new(xsize=>100, ysize=>100);
+    ok($im, "made size error test image");
+    ok(!$im->string(font=>$font, x=>10, 'y'=>50, string=>"Hello"),
+       "drawing should fail with no size");
+    is($im->errstr, "No font size provided", "check error message");
+
+    # try no string
+    ok(!$im->string(font=>$font, x=>10, 'y'=>50, size=>15),
+       "drawing should fail with no string");
+    is($im->errstr, "missing required parameter 'string'",
+       "check error message");
+  }
+
+  { # introduced in 0.46 - outputting just space crashes
+    my $im = Imager->new(xsize=>100, ysize=>100);
+    my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', size=>14);
+    ok($im->string(font=>$font, x=> 5, y => 50, string=>' '),
+      "outputting just a space was crashing");
+  }
+
   ok(1, "end of code");
 }