]> git.imager.perl.org - imager.git/commitdiff
use the standard font tests for FT2 too
authorTony Cook <tony@develop-help.com>
Sat, 23 Feb 2013 03:29:18 +0000 (14:29 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 23 Feb 2013 03:29:18 +0000 (14:29 +1100)
FT2/FT2.pm
FT2/FT2.xs
FT2/MANIFEST
FT2/freetyp2.c
FT2/t/t10ft2.t
FT2/t/t90std.t [new file with mode: 0644]
MANIFEST

index d8d471ff567b0a9e2b6c6187a160fff72aec45ec..3a0886bd2931585955822b138c6f3122c24c87eb 100644 (file)
@@ -77,8 +77,14 @@ sub _bounding_box {
   $self->_valid
     or return;
 
-  return i_ft2_bbox($self->{id}, $input{size}, $input{sizew}, $input{string}, 
-                   $input{utf8});
+  my @result =  i_ft2_bbox($self->{id}, $input{size}, $input{sizew},
+                          $input{string}, $input{utf8});
+  unless (@result) {
+    Imager->_set_error(Imager->_error_as_msg);
+    return;
+  }
+
+  return @result;
 }
 
 sub dpi {
@@ -142,8 +148,25 @@ sub has_chars {
     $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
     return;
   }
-  return i_ft2_has_chars($self->{id}, $hsh{string}, 
-                        _first($hsh{'utf8'}, $self->{utf8}, 0));
+  if (wantarray) {
+    my @result =  i_ft2_has_chars($self->{id}, $hsh{string}, 
+                                 _first($hsh{'utf8'}, $self->{utf8}, 0));
+    unless (@result) {
+      Imager->_set_error(Imager->_error_as_msg);
+      return;
+    }
+
+    return @result;
+  }
+  else {
+    my $result =  i_ft2_has_chars($self->{id}, $hsh{string}, 
+                                 _first($hsh{'utf8'}, $self->{utf8}, 0));
+    unless (defined $result) {
+      Imager->_set_error(Imager->_error_as_msg);
+      return;
+    }
+    return $result;
+  }
 }
 
 sub face_name {
@@ -156,7 +179,20 @@ sub face_name {
 }
 
 sub can_glyph_names {
-  i_ft2_can_do_glyph_names();
+  my ($self) = @_;
+
+  i_ft2_can_do_glyph_names()
+    or return;
+
+  if (ref $self) {
+    $self->_valid
+      or return;
+
+    i_ft2_face_has_glyph_names($self->{id})
+      or return;
+  }
+
+  return 1;
 }
 
 sub glyph_names {
index f382cbd83d88e8f2a8e4553d0a18f03a8800cd92..c4f2c3b6904b03f8635e5e003e557f2129b1aebd 100644 (file)
@@ -281,7 +281,9 @@ i_ft2_glyph_name(handle, text_sv, utf8 = 0, reliable_only = 1)
         STRLEN work_len;
         size_t len;
         char name[255];
+       SSize_t count;
       PPCODE:
+        i_clear_error();
         text = SvPV(text_sv, work_len);
         len = work_len;
 #ifdef SvUTF8
@@ -294,22 +296,24 @@ i_ft2_glyph_name(handle, text_sv, utf8 = 0, reliable_only = 1)
             ch = i_utf8_advance(&text, &len);
             if (ch == ~0UL) {
               i_push_error(0, "invalid UTF8 character");
-              break;
+              XSRETURN_EMPTY;
             }
           }
           else {
             ch = *text++;
             --len;
           }
-          EXTEND(SP, 1);
+          EXTEND(SP, count);
           if (i_ft2_glyph_name(handle, ch, name, sizeof(name), 
                                          reliable_only)) {
-            PUSHs(sv_2mortal(newSVpv(name, 0)));
+            ST(count) = sv_2mortal(newSVpv(name, 0));
           }
           else {
-            PUSHs(&PL_sv_undef);
-          } 
+            ST(count) = &PL_sv_undef;
+          }
+         ++count;
         }
+       XSRETURN(count);
 
 int
 i_ft2_can_do_glyph_names()
index 4e4becf8637d202ac54b0d2fdc873fb2be306c91..10dc0aaf8f298770fc3a9933ae5416e23e4c0e9d 100644 (file)
@@ -17,4 +17,5 @@ MANIFEST.SKIP
 README
 t/t10ft2.t
 t/t20thread.t
+t/t90std.t
 typemap
index 3af21fdef439611b098fa1b46fbd772f23613121..a1eb7f791241431dcd3643396f0dba63a14952df 100644 (file)
@@ -424,6 +424,8 @@ i_ft2_bbox(FT2_Fonthandle *handle, double cheight, double cwidth,
   int loadFlags = FT_LOAD_DEFAULT;
   int rightb = 0;
 
+  i_clear_error();
+
   mm_log((1, "i_ft2_bbox(handle %p, cheight %f, cwidth %f, text %p, len %u, bbox %p)\n",
          handle, cheight, cwidth, text, (unsigned)len, bbox));
 
@@ -747,6 +749,8 @@ i_ft2_text(FT2_Fonthandle *handle, i_img *im, i_img_dim tx, i_img_dim ty, const
   mm_log((1, "i_ft2_text(handle %p, im %p, (tx,ty) (" i_DFp "), cl %p, cheight %f, cwidth %f, text %p, len %u, align %d, aa %d, vlayout %d, utf8 %d)\n",
          handle, im, i_DFcp(tx, ty), cl, cheight, cwidth, text, (unsigned)len, align, aa, vlayout, utf8));
 
+  i_clear_error();
+
   if (vlayout) {
     if (!FT_HAS_VERTICAL(handle->face)) {
       i_push_error(0, "face has no vertical metrics");
@@ -890,6 +894,8 @@ i_ft2_cp(FT2_Fonthandle *handle, i_img *im, i_img_dim tx, i_img_dim ty, int chan
   mm_log((1, "i_ft2_cp(handle %p, im %p, (tx, ty) (" i_DFp "), channel %d, cheight %f, cwidth %f, text %p, len %u, align %d, aa %d, vlayout %d, utf8 %d)\n", 
          handle, im, i_DFcp(tx, ty), channel, cheight, cwidth, text, (unsigned)len, align, aa, vlayout, utf8));
 
+  i_clear_error();
+
   if (vlayout && !FT_HAS_VERTICAL(handle->face)) {
     i_push_error(0, "face has no vertical metrics");
     return 0;
@@ -940,6 +946,8 @@ i_ft2_has_chars(FT2_Fonthandle *handle, char const *text, size_t len,
   mm_log((1, "i_ft2_has_chars(handle %p, text %p, len %u, utf8 %d)\n", 
          handle, text, (unsigned)len, utf8));
 
+  i_clear_error();
+
   while (len) {
     unsigned long c;
     int index;
@@ -1131,6 +1139,10 @@ i_ft2_glyph_name(FT2_Fonthandle *handle, unsigned long ch, char *name_buf,
       *name_buf = '\0';
       return 0;
     }
+    if (strcmp(name_buf, ".notdef") == 0) {
+      *name_buf = 0;
+      return 0;
+    }
     if (*name_buf) {
       return strlen(name_buf) + 1;
     }
@@ -1139,7 +1151,6 @@ i_ft2_glyph_name(FT2_Fonthandle *handle, unsigned long ch, char *name_buf,
     }
   }
   else {
-    i_push_error(0, "no glyph for that character");
     *name_buf = 0;
     return 0;
   }
@@ -1160,7 +1171,8 @@ i_ft2_face_has_glyph_names(FT2_Fonthandle *handle) {
 #ifdef FT_CONFIG_OPTION_NO_GLYPH_NAMES
   return 0;
 #else
-  return FT_Has_PS_Glyph_Names(handle->face);
+  return FT_HAS_GLYPH_NAMES(handle->face);
+  /* return FT_Has_PS_Glyph_Names(handle->face);*/
 #endif
 }
 
index f37bf203bdf07d3a04ddea1d9797ca19c8b4bc66..3810014a5fc893d8edd5dbae1ed4f2e8628e9bc5 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 204;
+use Test::More tests => 193;
 use Cwd qw(getcwd abs_path);
 
 use Imager qw(:all);
@@ -536,92 +536,6 @@ SKIP:
       isnt_image($work, $cmp, "make sure something was drawn");
     }
   }
-
- SKIP:
-  { # check magic is handled correctly
-    # https://rt.cpan.org/Ticket/Display.html?id=83438
-    skip("no native UTF8 support in this version of perl", 11)
-      unless $] >= 5.006;
-    Imager->log("utf8 magic tests\n");
-    my $over = bless {}, "OverUtf8";
-    my $text = chr(0x2010);
-    my $white = Imager::Color->new("#FFF");
-    my $base_draw = Imager->new(xsize => 80, ysize => 20);
-    ok($base_draw->string(font => $oof,
-                         text => $text,
-                         x => 2,
-                         y => 18,
-                         size => 15,
-                         color => $white,
-                         aa => 1),
-       "magic: make a base image");
-    my $test_draw = Imager->new(xsize => 80, ysize => 20);
-    ok($test_draw->string(font => $oof,
-                         text => $over,
-                         x => 2,
-                         y => 18,
-                         size => 15,
-                         color => $white,
-                         aa => 1),
-       "magic: draw with overload");
-    is_image($base_draw, $test_draw, "check they match");
-    $test_draw->write(file => "testout/utf8tdr.ppm");
-    $base_draw->write(file => "testout/utf8bdr.ppm");
-
-    my $base_cp = Imager->new(xsize => 80, ysize => 20);
-    $base_cp->box(filled => 1, color => "#808080");
-    my $test_cp = $base_cp->copy;
-    ok($base_cp->string(font => $oof,
-                       text => $text,
-                       y => 2,
-                       y => 18,
-                       size => 16,
-                       channel => 2,
-                       aa => 1),
-       "magic: make a base image (channel)");
-    Imager->log("magic: draw to channel with overload\n");
-    ok($test_cp->string(font => $oof,
-                       text => $over,
-                       y => 2,
-                       y => 18,
-                       size => 16,
-                       channel => 2,
-                       aa => 1),
-       "magic: draw with overload (channel)");
-    is_image($test_cp, $base_cp, "check they match");
-    #$test_cp->write(file => "testout/utf8tcp.ppm");
-    #$base_cp->write(file => "testout/utf8bcp.ppm");
-
-    Imager->log("magic: has_chars");
-    is_deeply([ $oof->has_chars(string => $text) ], [ 1 ],
-             "magic: has_chars with normal utf8 text");
-    is_deeply([ $oof->has_chars(string => $over) ], [ 1 ],
-             "magic: has_chars with magic utf8 text");
-
-    Imager->log("magic: bounding_box\n");
-    my @base_bb = $oof->bounding_box(string => $text, size => 30);
-    is_deeply([ $oof->bounding_box(string => $over, size => 30) ],
-             \@base_bb,
-             "check bounding box magic");
-
-  SKIP:
-    {
-      my $nf = Imager::Font->new(file => "fontfiles/NameTest.ttf",
-                                type => "ft2")
-       or diag "Loading fontfiles/NameTest.ttf: ", Imager->errstr;
-      $nf
-       or skip("Cannot load NameTest.ttf", 2);
-      $nf->can_glyph_names()
-       or skip("Your FT2 lib can't glyph_names", 2);
-      Imager->log("magic: glyph_names\n");
-      is_deeply([ $nf->glyph_names(string => $text, reliable_only => 0) ],
-               [ "hyphentwo" ],
-               "magic: glyph_names with normal utf8 text");
-      is_deeply([ $nf->glyph_names(string => $over, reliable_only => 0) ],
-               [ "hyphentwo" ],
-               "magic: glyph_names with magic utf8 text");
-    }
-  }
 }
 
 sub align_test {
@@ -692,6 +606,4 @@ sub cross {
   
 }
 
-package OverUtf8;
-use overload '""' => sub { chr 0x2010 };
 
diff --git a/FT2/t/t90std.t b/FT2/t/t90std.t
new file mode 100644 (file)
index 0000000..9368ca7
--- /dev/null
@@ -0,0 +1,25 @@
+#!perl -w
+use strict;
+use Imager::Test qw(std_font_tests std_font_test_count);
+use Imager::Font;
+use Test::More tests => std_font_test_count();
+
+my $font = Imager::Font->new(file => "fontfiles/dodge.ttf",
+                            type => "ft2");
+my $name_font =
+  Imager::Font->new(file => "fontfiles/ImUgly.ttf",
+                   type => "ft2");
+
+SKIP:
+{
+  $font
+    or skip "Cannot load font", std_font_test_count();
+  std_font_tests
+    ({
+      font => $font,
+      has_chars => [ 1, 1, 1 ],
+      files => 1,
+      glyph_name_font => $name_font,
+      glyph_names => [ "A", "uni2010", "A" ],
+     });
+}
index 14a74e1b4fcdaa90b033e5af6538476ceaeec8a9..b2271b25eb8c6ba3b318717bb1cb3d52a9ac2f3e 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -70,6 +70,7 @@ FT2/Makefile.PL
 FT2/README
 FT2/t/t10ft2.t
 FT2/t/t20thread.t
+FT2/t/t90std.t                 Standard font tests for FT2
 FT2/typemap
 gaussian.im
 GIF/GIF.pm