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 return i_ft2_bbox($self->{id}, $input{size}, $input{sizew}, $input{string},
90 my @old = i_ft2_getdpi($self->{id});
94 unless ($hsh{xdpi} && $hsh{ydpi}) {
96 $hsh{xdpi} = $hsh{ydpi} = $hsh{dpi};
99 $Imager::ERRSTR = "dpi method requires xdpi and ydpi or just dpi";
102 i_ft2_setdpi($self->{id}, $hsh{xdpi}, $hsh{ydpi}) or return;
110 my ($self, %opts) = @_;
115 i_ft2_sethinting($self->{id}, $opts{hinting} || 0);
125 my $matrix = $hsh{matrix} or return undef;
127 return i_ft2_settransform($self->{id}, $matrix)
134 # check if the font has the characters in the given string
136 my ($self, %hsh) = @_;
141 unless (defined $hsh{string} && length $hsh{string}) {
142 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
145 return i_ft2_has_chars($self->{id}, $hsh{string},
146 _first($hsh{'utf8'}, $self->{utf8}, 0));
155 i_ft2_face_name($self->{id});
158 sub can_glyph_names {
159 i_ft2_can_do_glyph_names();
163 my ($self, %input) = @_;
168 my $string = $input{string};
170 or return Imager->_set_error("no string parameter passed to glyph_names");
171 my $utf8 = _first($input{utf8}, 0);
172 my $reliable_only = _first($input{reliable_only}, 1);
174 my @names = i_ft2_glyph_name($self->{id}, $string, $utf8, $reliable_only);
175 @names or return Imager->_set_error(Imager->_error_as_msg);
177 return @names if wantarray;
187 i_ft2_is_multiple_master($self->{id});
196 my ($num_axis, $num_design, @axes) =
197 i_ft2_get_multiple_masters($self->{id})
198 or return Imager->_set_error(Imager->_error_as_msg);
204 my ($self, %opts) = @_;
210 or return Imager->_set_error("Missing coords parameter");
211 ref($opts{coords}) && $opts{coords} =~ /ARRAY\(0x[\da-f]+\)$/
212 or return Imager->_set_error("coords parameter must be an ARRAY ref");
214 i_ft2_set_mm_coords($self->{id}, @{$opts{coords}})
215 or return Imager->_set_error(Imager->_error_as_msg);
220 # objects may be invalidated on thread creation (or Win32 fork emulation)
224 unless ($self->{id} && Scalar::Util::blessed($self->{id})) {
225 Imager->_set_error("font object was created in another thread");
238 Imager::Font::FT2 - font support using FreeType 2
244 my $img = Imager->new;
245 my $font = Imager::Font->new(file => "foo.ttf", type => "ft2");
247 $img->string(... font => $font);
251 This provides font support on FreeType 2.
255 Unfortunately, older versions of Imager would install
256 C<Imager::Font::FreeType2> even if FreeType 2 wasn't available, and if
257 no font was created would succeed in loading the module. This means
258 that an existing C<FreeType2.pm> could cause a probe success for
259 supported font files, so I've renamed it.
263 Tony Cook <tonyc@cpan.org>
267 Imager, Imager::Font.