Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implement standard font tests for Imager::Font::W32

  • Loading branch information...
commit 405c810505277cb256d6d53fdf167ded4b58491c 1 parent c732ffa
@tonycoz authored
View
1  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
View
27 W32/MANIFEST
@@ -1,13 +1,14 @@
-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
-W32.pm
-W32.xs
-win32.c
+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
View
18 W32/W32.pm
@@ -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__
View
25 W32/t/t90std.t
@@ -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;
View
4 W32/win32.c
@@ -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;
}
View
45 lib/Imager/Test.pm
@@ -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");
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.