]> git.imager.perl.org - imager.git/blobdiff - t/t30t1font.t
[rt.cpan.org #65385] Patch for Imager::Color->hsv
[imager.git] / t / t30t1font.t
index 2a3370f27544210a1ddcf6e7bb1882c2c468e4d2..da5b5863901468ebe1b1ef238f954da6096f1724 100644 (file)
@@ -7,34 +7,35 @@
 # Change 1..1 below to 1..last_test_to_print .
 # (It may become useful if the test is moved to ./t subdirectory.)
 use strict;
-use lib 't';
-use Test::More tests => 77;
-BEGIN { use_ok(Imager => ':all') }
+use Test::More;
+use Imager ':all';
+use Imager::Test qw(diff_text_with_nul is_color3);
+use Cwd qw(getcwd abs_path);
 
 #$Imager::DEBUG=1;
 
+i_has_format("t1")
+  or plan skip_all => "t1lib unavailble or disabled";
+
+plan tests => 95;
+
 init_log("testout/t30t1font.log",1);
 
-my $deffont = './fontfiles/dcr10.pfb';
+my $deffont = 'fontfiles/dcr10.pfb';
 
 my $fontname_pfb=$ENV{'T1FONTTESTPFB'}||$deffont;
 my $fontname_afm=$ENV{'T1FONTTESTAFM'}||'./fontfiles/dcr10.afm';
 
+-f $fontname_pfb
+  or skip_all("cannot find fontfile for type 1 test $fontname_pfb");
+-f $fontname_afm
+  or skip_all("cannot find fontfile for type 1 test $fontname_afm");
+
 SKIP:
 {
-  if (!(i_has_format("t1")) ) {
-    skip("t1lib unavailable or disabled", 76);
-  }
-  elsif (! -f $fontname_pfb) {
-    skip("cannot find fontfile for type 1 test $fontname_pfb", 76);
-  }
-  elsif (! -f $fontname_afm) {
-    skip("cannot find fontfile for type 1 test $fontname_afm", 76);
-  }
-
   print "# has t1\n";
 
-  i_t1_set_aa(1);
+  #i_t1_set_aa(1);
 
   unlink "t1lib.log"; # lose it if it exists
   init(t1log=>0);
@@ -46,7 +47,7 @@ SKIP:
 
   my $fnum=Imager::i_t1_new($fontname_pfb,$fontname_afm); # this will load the pfb font
   unless (ok($fnum >= 0, "load font $fontname_pfb")) {
-    skip("without the font I can't do a thing", 48);
+    skip("without the font I can't do a thing", 90);
   }
 
   my $bgcolor=Imager::Color->new(255,0,0,0);
@@ -153,6 +154,7 @@ SKIP:
     is(length($exists), 2, "return scalar length");
     ok(ord(substr($exists, 0, 1)), "we have an exclamation mark");
     ok(!ord(substr($exists, 1, 1)), "we have no upper-case A");
+    i_t1_destroy($font_num);
   }
   
   my $font = Imager::Font->new(file=>$exists_font, type=>'t1');
@@ -179,9 +181,9 @@ SKIP:
     # names
     my $face_name = Imager::i_t1_face_name($font->{id});
     print "# face $face_name\n";
-    ok($face_name eq 'ExistenceTest', "face name");
+    is($face_name, 'ExistenceTest', "face name");
     $face_name = $font->face_name;
-    ok($face_name eq 'ExistenceTest', "face name");
+    is($face_name, 'ExistenceTest', "face name");
 
     my @glyph_names = $font->glyph_names(string=>"!J/");
     is($glyph_names[0], 'exclam', "check exclam name OO");
@@ -308,6 +310,68 @@ SKIP:
     is($bbox_utf8->advance_width, $bbox_tran->advance_width,
        "advance widths should match");
   }
+  { # 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/dcr10.pfb', type => 't1');
+    ok($font, "loaded dcr10.pfb");
+
+    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 \xBF
+    my $pound = pack("C*", 0xC2, 0xBF);
+    diff_text_with_nul("utf8 pound\0pound vs pound", "$pound\0$pound", $pound,
+                      font => $font, color => '#FFFFFF', utf8 => 1);
+    diff_text_with_nul("utf8 dash\0dash vs dash", "$pound\0$pound", $pound,
+                      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/dcr10.pfb', type=>'t1');
+    my $im = Imager->new(xsize => 40, ysize => 20, channels => 4);
+    ok($im->string(string => "AB", size => 20, aa => 2, color => '#F00',
+                  x => 0, y => 15, font => $font),
+       "draw to transparent image");
+    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");
+  }
+
+ SKIP:
+  { # RT 60509
+    # checks that a c:foo or c:\foo path is handled correctly on win32
+    my $type = "t1";
+    $^O eq "MSWin32" || $^O eq "cygwin"
+      or skip("only for win32", 2);
+    my $dir = getcwd
+      or skip("Cannot get cwd", 2);
+    if ($^O eq "cygwin") {
+      $dir = Cygwin::posix_to_win_path($dir);
+    }
+    my $abs_path = abs_path($deffont);
+    my $font = Imager::Font->new(file => $abs_path, type => $type);
+    ok($font, "found font by absolute path")
+      or print "# path $abs_path\n";
+    undef $font;
+
+    $^O eq "cygwin"
+      and skip("cygwin doesn't support drive relative DOSsish paths", 1);
+    my ($drive) = $dir =~ /^([a-z]:)/i
+      or skip("cwd has no drive letter", 2);
+    my $drive_path = $drive . $deffont;
+    $font = Imager::Font->new(file => $drive_path, type => $type);
+    ok($font, "found font by drive relative path")
+      or print "# path $drive_path\n";
+  }
 }
 
 #malloc_state();