]> git.imager.perl.org - imager.git/commitdiff
implement standard font tests for Imager::Font::W32
authorTony Cook <tony@develop-help.com>
Mon, 25 Feb 2013 11:34:32 +0000 (22:34 +1100)
committerTony Cook <tony@develop-help.com>
Mon, 25 Feb 2013 11:34:32 +0000 (22:34 +1100)
MANIFEST
W32/MANIFEST
W32/W32.pm
W32/t/t90std.t [new file with mode: 0644]
W32/win32.c
lib/Imager/Test.pm

index 7dd8e13cec2c597bcd2935df8f4db3995a299032..55a9466d77640df85da8a51cf50bef785b702265 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -514,6 +514,7 @@ W32/lib/Imager/Font/Win32.pm
 W32/Makefile.PL
 W32/README
 W32/t/t10win32.t               Tests Win32 GDI font support
+W32/t/t90std.t                         Standard font tests for W32
 W32/W32.pm
 W32/W32.xs
 W32/win32.c                    Implements font support through Win32 GDI
index 1f8f3ffd7f135b944a2368334e58b8040439f3b7..2afa299458fffd9a9c9166583b1e8758934e05ae 100755 (executable)
@@ -1,13 +1,14 @@
-Changes\r
-fontfiles/ExistenceTest.ttf\r
-imw32.h\r
-inc/Devel/CheckLib.pm\r
-lib/Imager/Font/Win32.pm\r
-Makefile.PL\r
-MANIFEST                       This list of files\r
-MANIFEST.SKIP\r
-README\r
-t/t10win32.t\r
-W32.pm\r
-W32.xs\r
-win32.c\r
+Changes
+fontfiles/ExistenceTest.ttf
+imw32.h
+inc/Devel/CheckLib.pm
+lib/Imager/Font/Win32.pm
+Makefile.PL
+MANIFEST                       This list of files
+MANIFEST.SKIP
+README
+t/t10win32.t
+t/t90std.t                     Standard font tests for W32
+W32.pm
+W32.xs
+win32.c
index fbae40da6ce53a9a5d15b1b804da8721cd269213..d8da606762503e3ec77d1a93ea2cc778d0847b78 100644 (file)
@@ -5,7 +5,7 @@ use vars qw($VERSION @ISA);
 @ISA = qw(Imager::Font);
 
 BEGIN {
-  $VERSION = "0.85";
+  $VERSION = "0.86";
 
   require XSLoader;
   XSLoader::load('Imager::Font::W32', $VERSION);
@@ -30,6 +30,12 @@ sub _bounding_box {
   my ($self, %opts) = @_;
   
   my @bbox = i_wf_bbox($self->{face}, $opts{size}, $opts{string}, $opts{utf8});
+  unless (@bbox) {
+    Imager->_set_error(Imager->_error_as_msg);
+    return;
+  }
+
+  return @bbox;
 }
 
 sub _draw {
@@ -37,17 +43,15 @@ sub _draw {
 
   my %input = @_;
   if (exists $input{channel}) {
-    i_wf_cp($self->{face}, $input{image}{IMG}, $input{x}, $input{'y'},
+    return i_wf_cp($self->{face}, $input{image}{IMG}, $input{x}, $input{'y'},
            $input{channel}, $input{size},
            $input{string}, $input{align}, $input{aa}, $input{utf8});
   }
   else {
-    i_wf_text($self->{face}, $input{image}{IMG}, $input{x}, 
+    return i_wf_text($self->{face}, $input{image}{IMG}, $input{x}, 
              $input{'y'}, $input{color}, $input{size}, 
              $input{string}, $input{align}, $input{aa}, $input{utf8});
   }
-
-  return 1;
 }
 
 
@@ -55,6 +59,10 @@ sub utf8 {
   return 1;
 }
 
+sub can_glyph_names {
+  return;
+}
+
 1;
 
 __END__
diff --git a/W32/t/t90std.t b/W32/t/t90std.t
new file mode 100644 (file)
index 0000000..fb461db
--- /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();
+
+Imager->open_log(log => "testout/t90std.log");
+
+my $font = Imager::Font->new(face => "Times New Roman Bold",
+                            type => "w32");
+
+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" ],
+     });
+}
+Imager->close_log;
\ No newline at end of file
index 6da43946c056f098da3c0d4045cbaa777cfee022..f892c674f6ace7f35133efff489ef45215321cff 100644 (file)
@@ -543,7 +543,7 @@ render_text(const char *face, int size, const char *text, size_t length, int aa,
 static
 LPWSTR
 utf8_to_wide_string(char const *text, int text_len, int *wide_chars) {
-  int wide_count = MultiByteToWideChar(CP_UTF8, 0, text, text_len, NULL, 0);
+  int wide_count = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, text_len, NULL, 0);
   LPWSTR result;
 
   if (wide_count < 0) {
@@ -552,7 +552,7 @@ utf8_to_wide_string(char const *text, int text_len, int *wide_chars) {
   }
   ++wide_count;
   result = mymalloc(sizeof(WCHAR) * wide_count);
-  if (MultiByteToWideChar(CP_UTF8, 0, text, text_len, result, wide_count) < 0) {
+  if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text, text_len, result, wide_count) < 0) {
     i_push_errorf(0, "Could not convert utf8: %ld", GetLastError());
     return NULL;
   }
index 0793d91332a37d0e3b07b41fd240193c1c48ce8a..586a937a7848cba786cd0e4916b491da1f0fe07f 100644 (file)
@@ -809,11 +809,16 @@ sub std_font_tests {
       $base_cp->write(file => "testout/utf8bcp.ppm");
     }
 
-    Imager->log("magic: has_chars");
-    is_deeply([ $font->has_chars(string => $text) ], $has_chars,
-             "magic: has_chars with normal utf8 text");
-    is_deeply([ $font->has_chars(string => $over) ], $has_chars,
-             "magic: has_chars with magic utf8 text");
+  SKIP:
+    {
+      Imager->log("magic: has_chars\n");
+      $font->can("has_chars")
+       or skip "No has_chars aupport", 2;
+      is_deeply([ $font->has_chars(string => $text) ], $has_chars,
+               "magic: has_chars with normal utf8 text");
+      is_deeply([ $font->has_chars(string => $over) ], $has_chars,
+               "magic: has_chars with magic utf8 text");
+    }
 
     Imager->log("magic: bounding_box\n");
     my @base_bb = $font->bounding_box(string => $text, size => 30);
@@ -852,16 +857,26 @@ sub std_font_tests {
     ok(!$font->bounding_box(string => $bad_utf8, size => 30, utf8 => 1),
        "bounding_box() bad utf8 should fail");
     is(Imager->errstr, "invalid UTF8 character", "check error message");
-    Imager->_set_error("");
-    is_deeply([ $font->glyph_names(string => $bad_utf8, utf8 => 1) ],
-             [ ],
-             "glyph_names returns empty list for bad string");
-    is(Imager->errstr, "invalid UTF8 character", "check error message");
-    Imager->_set_error("");
-    is_deeply([ $font->has_chars(string => $bad_utf8, utf8 => 1) ],
-             [ ],
-             "has_chars returns empty list for bad string");
-    is(Imager->errstr, "invalid UTF8 character", "check error message");
+  SKIP:
+    {
+      $font->can_glyph_names
+       or skip "No glyph_names support", 2;
+      Imager->_set_error("");
+      is_deeply([ $font->glyph_names(string => $bad_utf8, utf8 => 1) ],
+               [ ],
+               "glyph_names returns empty list for bad string");
+      is(Imager->errstr, "invalid UTF8 character", "check error message");
+    }
+  SKIP:
+    {
+      $font->can("has_chars")
+       or skip "No has_chars support", 2;
+      Imager->_set_error("");
+      is_deeply([ $font->has_chars(string => $bad_utf8, utf8 => 1) ],
+               [ ],
+               "has_chars returns empty list for bad string");
+      is(Imager->errstr, "invalid UTF8 character", "check error message");
+    }
   }
 }