1 package Imager::Font::FT2;
4 use vars qw($VERSION @ISA);
5 @ISA = qw(Imager::Font);
11 XSLoader::load('Imager::Font::FT2', $VERSION);
14 *_first = \&Imager::Font::_first;
18 my %hsh=(color=>Imager::Color->new(255,0,0,255),
23 $Imager::ERRSTR = "No font file specified";
26 unless (-e $hsh{file}) {
27 $Imager::ERRSTR = "Font file $hsh{file} not found";
30 unless ($Imager::formats{ft2}) {
31 $Imager::ERRSTR = "Freetype2 not supported in this build";
34 my $id = i_ft2_new($hsh{file}, $hsh{'index'} || 0);
35 unless ($id) { # the low-level code may miss some error handling
36 $Imager::ERRSTR = Imager::_error_as_msg();
47 vlayout => $hsh{vlayout},
54 if (exists $input{channel}) {
55 i_ft2_cp($self->{id}, $input{image}{IMG}, $input{'x'}, $input{'y'},
56 $input{channel}, $input{size}, $input{sizew} || 0,
57 $input{string}, , $input{align}, $input{aa}, $input{vlayout},
60 i_ft2_text($self->{id}, $input{image}{IMG},
61 $input{'x'}, $input{'y'},
62 $input{color}, $input{size}, $input{sizew} || 0,
63 $input{string}, $input{align}, $input{aa}, $input{vlayout},
72 return i_ft2_bbox($self->{id}, $input{size}, $input{sizew}, $input{string},
78 my @old = i_ft2_getdpi($self->{id});
82 unless ($hsh{xdpi} && $hsh{ydpi}) {
84 $hsh{xdpi} = $hsh{ydpi} = $hsh{dpi};
87 $Imager::ERRSTR = "dpi method requires xdpi and ydpi or just dpi";
90 i_ft2_setdpi($self->{id}, $hsh{xdpi}, $hsh{ydpi}) or return;
98 my ($self, %opts) = @_;
100 i_ft2_sethinting($self->{id}, $opts{hinting} || 0);
107 my $matrix = $hsh{matrix} or return undef;
109 return i_ft2_settransform($self->{id}, $matrix)
116 # check if the font has the characters in the given string
118 my ($self, %hsh) = @_;
120 unless (defined $hsh{string} && length $hsh{string}) {
121 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
124 return i_ft2_has_chars($self->{id}, $hsh{string},
125 _first($hsh{'utf8'}, $self->{utf8}, 0));
131 i_ft2_face_name($self->{id});
134 sub can_glyph_names {
135 i_ft2_can_do_glyph_names();
139 my ($self, %input) = @_;
141 my $string = $input{string};
143 or return Imager->_set_error("no string parameter passed to glyph_names");
144 my $utf8 = _first($input{utf8}, 0);
145 my $reliable_only = _first($input{reliable_only}, 1);
147 my @names = i_ft2_glyph_name($self->{id}, $string, $utf8, $reliable_only);
148 @names or return Imager->_set_error(Imager->_error_as_msg);
150 return @names if wantarray;
157 i_ft2_is_multiple_master($self->{id});
163 my ($num_axis, $num_design, @axes) =
164 i_ft2_get_multiple_masters($self->{id})
165 or return Imager->_set_error(Imager->_error_as_msg);
171 my ($self, %opts) = @_;
174 or return Imager->_set_error("Missing coords parameter");
175 ref($opts{coords}) && $opts{coords} =~ /ARRAY\(0x[\da-f]+\)$/
176 or return Imager->_set_error("coords parameter must be an ARRAY ref");
178 i_ft2_set_mm_coords($self->{id}, @{$opts{coords}})
179 or return Imager->_set_error(Imager->_error_as_msg);
189 Imager::Font::FT2 - font support using FreeType 2
195 my $img = Imager->new;
196 my $font = Imager::Font->new(file => "foo.ttf", type => "ft2");
198 $img->string(... font => $font);
202 This provides font support on FreeType 2.
206 Unfortunately, older versions of Imager would install
207 C<Imager::Font::FreeType2> even if FreeType 2 wasn't available, and if
208 no font was created would succeed in loading the module. This means
209 that an existing C<FreeType2.pm> could cause a probe success for
210 supported font files, so I've renamed it.
214 Tony Cook <tonyc@cpan.org>
218 Imager, Imager::Font.