From 405c810505277cb256d6d53fdf167ded4b58491c Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 25 Feb 2013 22:34:32 +1100 Subject: [PATCH] implement standard font tests for Imager::Font::W32 --- MANIFEST | 1 + W32/MANIFEST | 27 ++++++++++++++------------- W32/W32.pm | 18 +++++++++++++----- W32/t/t90std.t | 25 +++++++++++++++++++++++++ W32/win32.c | 4 ++-- lib/Imager/Test.pm | 45 ++++++++++++++++++++++++++++++--------------- 6 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 W32/t/t90std.t diff --git a/MANIFEST b/MANIFEST index 7dd8e13c..55a9466d 100644 --- 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 diff --git a/W32/MANIFEST b/W32/MANIFEST index 1f8f3ffd..2afa2994 100755 --- a/W32/MANIFEST +++ b/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 diff --git a/W32/W32.pm b/W32/W32.pm index fbae40da..d8da6067 100644 --- a/W32/W32.pm +++ b/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__ diff --git a/W32/t/t90std.t b/W32/t/t90std.t new file mode 100644 index 00000000..fb461dbd --- /dev/null +++ b/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; \ No newline at end of file diff --git a/W32/win32.c b/W32/win32.c index 6da43946..f892c674 100644 --- a/W32/win32.c +++ b/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; } diff --git a/lib/Imager/Test.pm b/lib/Imager/Test.pm index 0793d913..586a937a 100644 --- a/lib/Imager/Test.pm +++ b/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"); + } } } -- 2.39.5