1 package Imager::Font::FT2;
5 use vars qw($VERSION @ISA);
6 @ISA = qw(Imager::Font);
12 XSLoader::load('Imager::Font::FT2', $VERSION);
15 *_first = \&Imager::Font::_first;
19 my %hsh=(color=>Imager::Color->new(255,0,0,255),
24 $Imager::ERRSTR = "No font file specified";
27 unless (-e $hsh{file}) {
28 $Imager::ERRSTR = "Font file $hsh{file} not found";
31 unless ($Imager::formats{ft2}) {
32 $Imager::ERRSTR = "Freetype2 not supported in this build";
35 my $id = i_ft2_new($hsh{file}, $hsh{'index'} || 0);
36 unless ($id) { # the low-level code may miss some error handling
37 $Imager::ERRSTR = Imager::_error_as_msg();
48 vlayout => $hsh{vlayout},
59 if (exists $input{channel}) {
60 i_ft2_cp($self->{id}, $input{image}{IMG}, $input{'x'}, $input{'y'},
61 $input{channel}, $input{size}, $input{sizew} || 0,
62 $input{string}, , $input{align}, $input{aa}, $input{vlayout},
65 i_ft2_text($self->{id}, $input{image}{IMG},
66 $input{'x'}, $input{'y'},
67 $input{color}, $input{size}, $input{sizew} || 0,
68 $input{string}, $input{align}, $input{aa}, $input{vlayout},
80 my @result = i_ft2_bbox($self->{id}, $input{size}, $input{sizew},
81 $input{string}, $input{utf8});
83 Imager->_set_error(Imager->_error_as_msg);
96 my @old = i_ft2_getdpi($self->{id});
100 unless ($hsh{xdpi} && $hsh{ydpi}) {
102 $hsh{xdpi} = $hsh{ydpi} = $hsh{dpi};
105 $Imager::ERRSTR = "dpi method requires xdpi and ydpi or just dpi";
108 i_ft2_setdpi($self->{id}, $hsh{xdpi}, $hsh{ydpi}) or return;
116 my ($self, %opts) = @_;
121 i_ft2_sethinting($self->{id}, $opts{hinting} || 0);
131 my $matrix = $hsh{matrix} or return undef;
133 return i_ft2_settransform($self->{id}, $matrix)
140 # check if the font has the characters in the given string
142 my ($self, %hsh) = @_;
147 unless (defined $hsh{string} && length $hsh{string}) {
148 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
152 my @result = i_ft2_has_chars($self->{id}, $hsh{string},
153 _first($hsh{'utf8'}, $self->{utf8}, 0));
155 Imager->_set_error(Imager->_error_as_msg);
162 my $result = i_ft2_has_chars($self->{id}, $hsh{string},
163 _first($hsh{'utf8'}, $self->{utf8}, 0));
164 unless (defined $result) {
165 Imager->_set_error(Imager->_error_as_msg);
178 i_ft2_face_name($self->{id});
181 sub can_glyph_names {
184 i_ft2_can_do_glyph_names()
191 i_ft2_face_has_glyph_names($self->{id})
199 my ($self, %input) = @_;
204 my $string = $input{string};
206 or return Imager->_set_error("no string parameter passed to glyph_names");
207 my $utf8 = _first($input{utf8}, 0);
208 my $reliable_only = _first($input{reliable_only}, 1);
210 my @names = i_ft2_glyph_name($self->{id}, $string, $utf8, $reliable_only);
211 @names or return Imager->_set_error(Imager->_error_as_msg);
213 return @names if wantarray;
223 i_ft2_is_multiple_master($self->{id});
232 my ($num_axis, $num_design, @axes) =
233 i_ft2_get_multiple_masters($self->{id})
234 or return Imager->_set_error(Imager->_error_as_msg);
240 my ($self, %opts) = @_;
246 or return Imager->_set_error("Missing coords parameter");
247 ref($opts{coords}) && $opts{coords} =~ /ARRAY\(0x[\da-f]+\)$/
248 or return Imager->_set_error("coords parameter must be an ARRAY ref");
250 i_ft2_set_mm_coords($self->{id}, @{$opts{coords}})
251 or return Imager->_set_error(Imager->_error_as_msg);
256 # objects may be invalidated on thread creation (or Win32 fork emulation)
260 unless ($self->{id} && Scalar::Util::blessed($self->{id})) {
261 Imager->_set_error("font object was created in another thread");
274 Imager::Font::FT2 - font support using FreeType 2
280 my $img = Imager->new;
281 my $font = Imager::Font->new(file => "foo.ttf", type => "ft2");
283 $img->string(... font => $font);
287 This provides font support on FreeType 2.
291 Unfortunately, older versions of Imager would install
292 C<Imager::Font::FreeType2> even if FreeType 2 wasn't available, and if
293 no font was created would succeed in loading the module. This means
294 that an existing C<FreeType2.pm> could cause a probe success for
295 supported font files, so I've renamed it.
299 Tony Cook <tonyc@cpan.org>
303 Imager, Imager::Font.