Permalink
Browse files

use the standard font tests for FT2 too

  • Loading branch information...
1 parent e4b2e1a commit d6f02a59426ca36f7c81975e6fffa08e8e7b7ce9 @tonycoz committed Feb 23, 2013
Showing with 92 additions and 101 deletions.
  1. +41 −5 FT2/FT2.pm
  2. +9 −5 FT2/FT2.xs
  3. +1 −0 FT2/MANIFEST
  4. +14 −2 FT2/freetyp2.c
  5. +1 −89 FT2/t/t10ft2.t
  6. +25 −0 FT2/t/t90std.t
  7. +1 −0 MANIFEST
View
@@ -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 {
View
@@ -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()
View
@@ -17,4 +17,5 @@ MANIFEST.SKIP
README
t/t10ft2.t
t/t20thread.t
+t/t90std.t
typemap
View
@@ -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
}
View
@@ -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 };
View
@@ -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" ],
+ });
+}
View
@@ -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

0 comments on commit d6f02a5

Please sign in to comment.