From: Tony Cook <tony@develop=help.com> Date: Mon, 23 Aug 2010 13:56:09 +0000 (+0000) Subject: only prepend ./ to font filenames when passing them to T1Lib and X-Git-Tag: Imager-0.79~75 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/b851aeebcc6c2c6b52c715206e075b190d55e507 only prepend ./ to font filenames when passing them to T1Lib and then only when it would use its search mechanisms. --- diff --git a/Changes b/Changes index 025e5a00..53bdbcc9 100644 --- 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 =========== diff --git a/lib/Imager/Font.pm b/lib/Imager/Font.pm index 13f8a3db..2a0d124d 100644 --- a/lib/Imager/Font.pm +++ b/lib/Imager/Font.pm @@ -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}) { diff --git a/lib/Imager/Font/Type1.pm b/lib/Imager/Font/Type1.pm index d6513ca6..0df82b89 100644 --- a/lib/Imager/Font/Type1.pm +++ b/lib/Imager/Font/Type1.pm @@ -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 { diff --git a/t/t30t1font.t b/t/t30t1font.t index f08ea78f..da5b5863 100644 --- a/t/t30t1font.t +++ b/t/t30t1font.t @@ -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(); diff --git a/t/t38ft2font.t b/t/t38ft2font.t index 4431d431..85f8ed6b 100644 --- a/t/t38ft2font.t +++ b/t/t38ft2font.t @@ -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 {