]> git.imager.perl.org - imager.git/commitdiff
only prepend ./ to font filenames when passing them to T1Lib and
authorTony Cook <tony@develop=help.com>
Mon, 23 Aug 2010 13:56:09 +0000 (13:56 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 23 Aug 2010 13:56:09 +0000 (13:56 +0000)
then only when it would use its search mechanisms.

Changes
lib/Imager/Font.pm
lib/Imager/Font/Type1.pm
t/t30t1font.t
t/t38ft2font.t

diff --git a/Changes b/Changes
index 025e5a001d6dcb8098ec9ff0528e398afaac0c85..53bdbcc9ce5d9d6c30ec3945633a52284c7ccee2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,8 @@ Imager release history.  Older releases can be found in Changes.old
 Imager 0.78 - unreleased
 ===========
 
+TODO: fix i_giflib_version()
+
  - add each library-directory/pkgconfig/ to the pkg-config search path
    in Imager::Probe.
    Thanks to Justin Davis.
@@ -19,6 +21,11 @@ Bug fixes:
    directory.  Thanks to Justin Davis.
    https://rt.cpan.org/Ticket/Display.html?id=60491
 
+ - only prepend ./ to font filenames when passing them to T1Lib and
+   then only when it would use its search mechanisms.
+   https://rt.cpan.org/Ticket/Display.html?id=60509
+
+
 Imager 0.77 - 11 Aug 2010
 ===========
 
index 13f8a3db699e40ba86cd9db29e05307f6243d2f6..2a0d124d71011ace3df95bd6cbc216655dc22092 100644 (file)
@@ -73,13 +73,6 @@ sub new {
 
   if ($hsh{'file'}) {
     $file = $hsh{'file'};
-    if ( $file !~ m/^\// ) {
-      $file = './'.$file;
-      if (! -e $file) {
-       $Imager::ERRSTR = "Font $file not found";
-       return();
-      }
-    }
 
     $type = $hsh{'type'};
     if (!defined($type) or !$drivers{$type} or !$drivers{$type}{enabled}) {
index d6513ca6ac31acc0be149b440c46122dc3bc6390..0df82b897fa0781cfdb354ba293621601815512b 100644 (file)
@@ -38,7 +38,10 @@ sub new {
     $Imager::ERRSTR = "Type 1 fonts not supported in this build";
     return;
   }
-  unless ($hsh{file} =~ m!^/! || $hsh{file} =~ m!^\./!) {
+  # we want to avoid T1Lib's file search mechanism
+  unless ($hsh{file} =~ m!^/!
+         || $hsh{file} =~ m!^\.\/?/!
+         || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/) {
     $hsh{file} = './' . $hsh{file};
   }
 
@@ -47,7 +50,9 @@ sub new {
            $Imager::ERRSTR = "Afm file $hsh{afm} not found";
            return;
          }
-         unless ($hsh{afm} =~ m!^/! || $hsh{afm} =~ m!^\./!) {
+         unless ($hsh{afm} =~ m!^/!
+                 || $hsh{afm} =~ m!^\./!
+                 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/) {
            $hsh{file} = './' . $hsh{file};
          }
   } else {
index f08ea78fdd343b3f49a8ccd68afe545c5b7fae66..da5b5863901468ebe1b1ef238f954da6096f1724 100644 (file)
@@ -7,31 +7,32 @@
 # 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 Test::More tests => 94;
-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", 93);
-  }
-  elsif (! -f $fontname_pfb) {
-    skip("cannot find fontfile for type 1 test $fontname_pfb", 93);
-  }
-  elsif (! -f $fontname_afm) {
-    skip("cannot find fontfile for type 1 test $fontname_afm", 93);
-  }
-
   print "# has t1\n";
 
   #i_t1_set_aa(1);
@@ -344,6 +345,33 @@ SKIP:
     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();
index 4431d431d12bcb0fa4b9f9ae9d872f4087150452..85f8ed6b0dfba965a5ebcd622585e68a008770a1 100644 (file)
@@ -1,6 +1,7 @@
 #!perl -w
 use strict;
-use Test::More tests => 187;
+use Test::More tests => 189;
+use Cwd qw(getcwd abs_path);
 ++$|;
 # Before `make install' is performed this script should be runnable with
 # `make test'. After `make install' it should work as `perl test.pl'
@@ -16,17 +17,19 @@ use Imager::Test qw(diff_text_with_nul is_color3);
 
 init_log("testout/t38ft2font.log",2);
 
+my $deffont = "fontfiles/dodge.ttf";
+
 my @base_color = (64, 255, 64);
 
 SKIP:
 {
-  i_has_format("ft2") or skip("no freetype2 library found", 186);
+  i_has_format("ft2") or skip("no freetype2 library found", 188);
 
   print "# has ft2\n";
   
-  my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
+  my $fontname=$ENV{'TTFONTTEST'} || $deffont;
 
-  -f $fontname or skip("cannot find fontfile $fontname", 186);
+  -f $fontname or skip("cannot find fontfile $fontname", 188);
 
 
   my $bgcolor=i_color_new(255,0,0,0);
@@ -490,6 +493,34 @@ SKIP:
     ok(Imager::i_img_diff($im->{IMG}, $imcopy->{IMG}),
        "make sure we drew the '0'");
   }
+
+ SKIP:
+  { # RT 60509
+    # checks that a c:foo or c:\foo path is handled correctly on win32
+    my $type = "ft2";
+    $^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";
+  }
+
 }
 
 sub align_test {