1 package Imager::Font::FT2;
4 use vars qw($VERSION @ISA);
5 @ISA = qw(Imager::Font);
12 XSLoader::load('Imager::Font::FT2', $VERSION);
16 push @ISA, 'DynaLoader';
17 bootstrap Imager::Font::FT2 $VERSION;
21 *_first = \&Imager::Font::_first;
25 my %hsh=(color=>Imager::Color->new(255,0,0,0),
30 $Imager::ERRSTR = "No font file specified";
33 unless (-e $hsh{file}) {
34 $Imager::ERRSTR = "Font file $hsh{file} not found";
37 unless ($Imager::formats{ft2}) {
38 $Imager::ERRSTR = "Freetype2 not supported in this build";
41 my $id = i_ft2_new($hsh{file}, $hsh{'index'} || 0);
42 unless ($id) { # the low-level code may miss some error handling
43 $Imager::ERRSTR = Imager::_error_as_msg();
54 vlayout => $hsh{vlayout},
61 if (exists $input{channel}) {
62 i_ft2_cp($self->{id}, $input{image}{IMG}, $input{'x'}, $input{'y'},
63 $input{channel}, $input{size}, $input{sizew} || 0,
64 $input{string}, , $input{align}, $input{aa}, $input{vlayout},
67 i_ft2_text($self->{id}, $input{image}{IMG},
68 $input{'x'}, $input{'y'},
69 $input{color}, $input{size}, $input{sizew} || 0,
70 $input{string}, $input{align}, $input{aa}, $input{vlayout},
79 return i_ft2_bbox($self->{id}, $input{size}, $input{sizew}, $input{string},
85 my @old = i_ft2_getdpi($self->{id});
89 unless ($hsh{xdpi} && $hsh{ydpi}) {
91 $hsh{xdpi} = $hsh{ydpi} = $hsh{dpi};
94 $Imager::ERRSTR = "dpi method requires xdpi and ydpi or just dpi";
97 i_ft2_setdpi($self->{id}, $hsh{xdpi}, $hsh{ydpi}) or return;
105 my ($self, %opts) = @_;
107 i_ft2_sethinting($self->{id}, $opts{hinting} || 0);
114 my $matrix = $hsh{matrix} or return undef;
116 return i_ft2_settransform($self->{id}, $matrix)
123 # check if the font has the characters in the given string
125 my ($self, %hsh) = @_;
127 unless (defined $hsh{string} && length $hsh{string}) {
128 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
131 return i_ft2_has_chars($self->{id}, $hsh{string},
132 _first($hsh{'utf8'}, $self->{utf8}, 0));
138 i_ft2_face_name($self->{id});
141 sub can_glyph_names {
142 i_ft2_can_do_glyph_names();
146 my ($self, %input) = @_;
148 my $string = $input{string};
150 or return Imager->_set_error("no string parameter passed to glyph_names");
151 my $utf8 = _first($input{utf8}, 0);
152 my $reliable_only = _first($input{reliable_only}, 1);
154 my @names = i_ft2_glyph_name($self->{id}, $string, $utf8, $reliable_only);
155 @names or return Imager->_set_error(Imager->_error_as_msg);
157 return @names if wantarray;
164 i_ft2_is_multiple_master($self->{id});
170 my ($num_axis, $num_design, @axes) =
171 i_ft2_get_multiple_masters($self->{id})
172 or return Imager->_set_error(Imager->_error_as_msg);
178 my ($self, %opts) = @_;
181 or return Imager->_set_error("Missing coords parameter");
182 ref($opts{coords}) && $opts{coords} =~ /ARRAY\(0x[\da-f]+\)$/
183 or return Imager->_set_error("coords parameter must be an ARRAY ref");
185 i_ft2_set_mm_coords($self->{id}, @{$opts{coords}})
186 or return Imager->_set_error(Imager->_error_as_msg);
196 Imager::Font::FT2 - font support using FreeType 2
202 my $img = Imager->new;
203 my $font = Imager::Font->new(file => "foo.ttf", type => "ft2");
205 $img->string(... font => $font);
209 This provides font support on FreeType 2.
213 Unfortunately, older versions of Imager would install
214 C<Imager::Font::FreeType2> even if FreeType 2 wasn't available, and if
215 no font was created would succeed in loading the module. This means
216 that an existing C<FreeType2.pm> could cause a probe success for
217 supported font files, so I've renamed it.
221 Tony Cook <tonyc@cpan.org>
225 Imager, Imager::Font.