$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 {
$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 {
}
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 {
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
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()
README
t/t10ft2.t
t/t20thread.t
+t/t90std.t
typemap
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));
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");
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;
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;
*name_buf = '\0';
return 0;
}
+ if (strcmp(name_buf, ".notdef") == 0) {
+ *name_buf = 0;
+ return 0;
+ }
if (*name_buf) {
return strlen(name_buf) + 1;
}
}
}
else {
- i_push_error(0, "no glyph for that character");
*name_buf = 0;
return 0;
}
#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
}
#!perl -w
use strict;
-use Test::More tests => 204;
+use Test::More tests => 193;
use Cwd qw(getcwd abs_path);
use Imager qw(:all);
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 {
}
-package OverUtf8;
-use overload '""' => sub { chr 0x2010 };
--- /dev/null
+#!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" ],
+ });
+}
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