]> git.imager.perl.org - imager.git/commitdiff
- the XS code for i_tt_glyph_name() used unsigned char to store a
authorTony Cook <tony@develop=help.com>
Mon, 18 Oct 2004 23:52:10 +0000 (23:52 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 18 Oct 2004 23:52:10 +0000 (23:52 +0000)
  unicode character when it should have used unsigned long.
- the XS code for i_t1_glyph_name() used unsigned char to store a
  unicode character when it should have used unsigned long.
- resolves https://rt.cpan.org/Ticket/Display.html?id=7949
- the type 1 glyph_names() method didn't do correct error handling
  when the string parameter wasn't supplied

Changes
Imager.xs
lib/Imager/Font/Type1.pm
t/t30t1font.t
t/t35ttfont.t
t/t38ft2font.t
t/testtools.pl

diff --git a/Changes b/Changes
index 967dbd13fc0b368dd9e9141fbf3fc2282ff593aa..d9c417cf4aef4f8fce71772c1b93bc46bf1d66e2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -858,7 +858,6 @@ Revision history for Perl extension Imager.
   names
 - added reliable_only optional parameter to the glyph_names()
   method so you can ignore theresult of FT_Has_PS_Glyph_Names()
-- partly resolves https://rt.cpan.org/Ticket/Display.html?id=7949
 - handle errors given by i_ft2_glyph_name() a bit more
   correctly
 - the FT1 glyph_names() method didn't do correct error handling 
@@ -867,6 +866,13 @@ Revision history for Perl extension Imager.
   wasn't being released (detected with valgrind)
 - the testtools.pl match[nx]() functions escapes the test string on 
   test failure a bit better
+- the XS code for i_tt_glyph_name() used unsigned char to store a 
+  unicode character when it should have used unsigned long.
+- the XS code for i_t1_glyph_name() used unsigned char to store a 
+  unicode character when it should have used unsigned long.
+- resolves https://rt.cpan.org/Ticket/Display.html?id=7949
+- the type 1 glyph_names() method didn't do correct error handling 
+  when the string parameter wasn't supplied
 
 =================================================================
 
index 2e5baba4a5a5e25ece3c1002f6471825e146870b..aeae14b905ca59e6991fd07dd0db671ae8ccbd04 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -1864,7 +1864,7 @@ i_t1_glyph_name(handle, text_sv, utf8 = 0)
         text = SvPV(text_sv, work_len);
         len = work_len;
         while (len) {
-          unsigned char ch;
+          unsigned long ch;
           if (utf8) {
             ch = i_utf8_advance(&text, &len);
             if (ch == ~0UL) {
@@ -2053,7 +2053,7 @@ i_tt_glyph_name(handle, text_sv, utf8 = 0)
         text = SvPV(text_sv, work_len);
         len = work_len;
         while (len) {
-          unsigned char ch;
+          unsigned long ch;
           if (utf8) {
             ch = i_utf8_advance(&text, &len);
             if (ch == ~0UL) {
index bae896992a1d473ac821613baeee0d55bb5948b8..5c71e62107edfe7c03471c47c98f6e4530d84d96 100644 (file)
@@ -127,7 +127,7 @@ sub glyph_names {
 
   my $string = $input{string};
   defined $string
-    or return Imager->_seterror("no string parameter passed to glyph_names");
+    or return Imager->_set_error("no string parameter passed to glyph_names");
   my $utf8 = _first($input{utf8} || 0);
 
   Imager::i_t1_glyph_name($self->{id}, $string, $utf8);
index 22b12642d72aadba94524f7c2f7e265738f72ea0..810aacd3983d952e65be6f51e037b04ba37dc4c7 100644 (file)
@@ -8,7 +8,7 @@
 # (It may become useful if the test is moved to ./t subdirectory.)
 use strict;
 my $loaded;
-BEGIN { $| = 1; print "1..38\n"; }
+BEGIN { $| = 1; print "1..41\n"; }
 END {print "not ok 1\n" unless $loaded;}
 use Imager qw(:all);
 use Imager::Color;
@@ -28,13 +28,13 @@ my $fontname_afm=$ENV{'T1FONTTESTAFM'}||'./fontfiles/dcr10.afm';
 
 
 if (!(i_has_format("t1")) ) {
-  skipx(37, "t1lib unavailable or disabled");
+  skipx(40, "t1lib unavailable or disabled");
 }
 elsif (! -f $fontname_pfb) {
-  skipx(37, "cannot find fontfile for type 1 test $fontname_pfb");
+  skipx(40, "cannot find fontfile for type 1 test $fontname_pfb");
 }
 elsif (! -f $fontname_afm) {
-  skipx(37, "cannot find fontfile for type 1 test $fontname_afm");
+  skipx(40, "cannot find fontfile for type 1 test $fontname_afm");
 } else {
 
   print "# has t1\n";
@@ -189,12 +189,25 @@ elsif (! -f $fontname_afm) {
     okx($face_name eq 'ExistenceTest', "face name");
 
     my @glyph_names = $font->glyph_names(string=>"!J/");
-    okx($glyph_names[0] eq 'exclam', "check exclam name OO");
+    isx($glyph_names[0], 'exclam', "check exclam name OO");
     okx(!defined($glyph_names[1]), "check for no J name OO");
-    okx($glyph_names[2] eq 'slash', "check slash name OO");
+    isx($glyph_names[2], 'slash', "check slash name OO");
+
+    # this character chosen since when it's truncated to one byte it
+    # becomes 0x21 or '!' which the font does define
+    my $text = pack("C*", 0xE2, 0x80, 0xA1); # "\x{2021}" as utf-8
+    @glyph_names = $font->glyph_names(string=>$text, utf8=>1);
+    isx($glyph_names[0], undef, "expect no glyph_name for \\x{20A1}");
+
+    # make sure a missing string parameter is handled correctly
+    eval {
+      $font->glyph_names();
+    };
+    isx($@, "", "correct error handling");
+    matchx(Imager->errstr, qr/no string parameter/, "error message");
   }
   else {
-    skipx(12, "Could not load test font");
+    skipx(15, "Could not load test font");
   }
 }
 
index c2dc3dfd6c6e1a9508523abe443eccd4dff68b6a..5e4055763faef266c7120a4d369feab67e5f8905 100644 (file)
@@ -7,7 +7,7 @@
 # (It may become useful if the test is moved to ./t subdirectory.)
 use strict;
 my $loaded;
-BEGIN { $| = 1; print "1..35\n"; }
+BEGIN { $| = 1; print "1..39\n"; }
 END {print "not ok 1\n" unless $loaded;}
 use Imager qw(:all);
 require "t/testtools.pl";
@@ -18,7 +18,7 @@ okx(1, "Loaded");
 init_log("testout/t35ttfont.log",2);
 
 unless (i_has_format("tt")) { 
-  skipx(34, "freetype 1.x unavailable or disabled");
+  skipx(38, "freetype 1.x unavailable or disabled");
   malloc_state();
   exit;
 }
@@ -29,7 +29,7 @@ my $fontname=$ENV{'TTFONTTEST'} || $deffont;
 
 if (! -f $fontname) {
   print "# cannot find fontfile for truetype test $fontname\n";
-  skipx(34, 'Cannot load test font');  
+  skipx(38, 'Cannot load test font');  
   exit;
 }
 
@@ -163,4 +163,24 @@ else {
 }
 undef $hcfont;
 
+my $name_font = "fontfiles/NameTest.ttf";
+$hcfont = Imager::Font->new(file=>$name_font);
+if (okx($hcfont, "loading name font")) {
+  # make sure a missing string parameter is handled correctly
+  eval {
+    $hcfont->glyph_names();
+  };
+  isx($@, "", "correct error handling");
+  matchx(Imager->errstr, qr/no string parameter/, "error message");
+
+  my $text = pack("C*", 0xE2, 0x80, 0x90); # "\x{2010}" as utf-8
+  my @names = $hcfont->glyph_names(string=>$text, utf8=>1);
+  isx($names[0], "hyphentwo", "check utf8 glyph name");
+}
+else {
+  skipx(3, "could not load name font $name_font");
+}
+
+undef $hcfont;
+
 okx(1, "end of code");
index 067d5d9e673078f2400f05ddb9c143b2dba67fb4..5f33a25c231e69aa2badbcbed6614c02c03b58ba 100644 (file)
@@ -18,7 +18,7 @@ okx(1, "loaded");
 init_log("testout/t38ft2font.log",2);
 
 if (!(i_has_format("ft2")) ) { 
-  skipx(115, "No freetype2 library found");
+  skipx(119, "No freetype2 library found");
   exit;
 }
 print "# has ft2\n";
@@ -26,7 +26,7 @@ print "# has ft2\n";
 $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
 
 if (! -f $fontname) {
-  skipx(124, "cannot find fontfile $fontname");
+  skipx(119, "cannot find fontfile $fontname");
   malloc_state();
   exit;
 }
index d5b2a242fba27d5fce29fb508f66d5ebd4ee4499..ad4886f97c3276046eb17025f48bac2d1a1d4299 100644 (file)
@@ -43,13 +43,13 @@ sub skipx {
   $TESTNUM += $count;
 }
 
-sub okx {
+sub okx ($$) {
   my ($ok, $comment) = @_;
 
   return okn($TESTNUM++, $ok, $comment);
 }
 
-sub okn {
+sub okn ($$$) {
   my ($num, $ok, $comment) = @_;
 
   defined $num or confess "No \$num supplied";