Skip to content

Commit

Permalink
implement standard font tests for Imager::Font::W32
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Feb 25, 2013
1 parent c732ffa commit 405c810
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 35 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 14 additions & 13 deletions W32/MANIFEST
Original file line number Diff line number Diff line change
@@ -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
18 changes: 13 additions & 5 deletions W32/W32.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -30,31 +30,39 @@ 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 {
my $self = shift;

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;
}


sub utf8 {
return 1;
}

sub can_glyph_names {
return;
}

1;

__END__
Expand Down
25 changes: 25 additions & 0 deletions W32/t/t90std.t
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions W32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
45 changes: 30 additions & 15 deletions lib/Imager/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}
}
}

Expand Down

0 comments on commit 405c810

Please sign in to comment.