1 package Imager::Font::FreeType2;
4 use vars qw(@ISA $VERSION);
5 @ISA = qw(Imager::Font);
9 *_first = \&Imager::Font::_first;
13 my %hsh=(color=>Imager::Color->new(255,0,0,0),
18 $Imager::ERRSTR = "No font file specified";
21 unless (-e $hsh{file}) {
22 $Imager::ERRSTR = "Font file $hsh{file} not found";
25 unless ($Imager::formats{ft2}) {
26 $Imager::ERRSTR = "Freetype2 not supported in this build";
29 my $id = i_ft2_new($hsh{file}, $hsh{'index'} || 0);
30 unless ($id) { # the low-level code may miss some error handling
31 $Imager::ERRSTR = Imager::_error_as_msg();
42 vlayout => $hsh{vlayout},
49 if (exists $input{channel}) {
50 i_ft2_cp($self->{id}, $input{image}{IMG}, $input{'x'}, $input{'y'},
51 $input{channel}, $input{size}, $input{sizew} || 0,
52 $input{string}, , $input{align}, $input{aa}, $input{vlayout},
55 i_ft2_text($self->{id}, $input{image}{IMG},
56 $input{'x'}, $input{'y'},
57 $input{color}, $input{size}, $input{sizew} || 0,
58 $input{string}, $input{align}, $input{aa}, $input{vlayout},
67 return i_ft2_bbox($self->{id}, $input{size}, $input{sizew}, $input{string},
73 my @old = i_ft2_getdpi($self->{id});
77 unless ($hsh{xdpi} && $hsh{ydpi}) {
79 $hsh{xdpi} = $hsh{ydpi} = $hsh{dpi};
82 $Imager::ERRSTR = "dpi method requires xdpi and ydpi or just dpi";
85 i_ft2_setdpi($self->{id}, $hsh{xdpi}, $hsh{ydpi}) or return;
93 my ($self, %opts) = @_;
95 i_ft2_sethinting($self->{id}, $opts{hinting} || 0);
102 my $matrix = $hsh{matrix} or return undef;
104 return i_ft2_settransform($self->{id}, $matrix)
111 # check if the font has the characters in the given string
113 my ($self, %hsh) = @_;
115 unless (defined $hsh{string} && length $hsh{string}) {
116 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
119 return i_ft2_has_chars($self->{id}, $hsh{string},
120 _first($hsh{'utf8'}, $self->{utf8}, 0));
126 i_ft2_face_name($self->{id});
129 sub can_glyph_names {
130 i_ft2_can_do_glyph_names();
134 my ($self, %input) = @_;
136 my $string = $input{string};
138 or return Imager->_set_error("no string parameter passed to glyph_names");
139 my $utf8 = _first($input{utf8}, 0);
140 my $reliable_only = _first($input{reliable_only}, 1);
142 my @names = i_ft2_glyph_name($self->{id}, $string, $utf8, $reliable_only);
143 @names or return Imager->_set_error(Imager->_error_as_msg);
145 return @names if wantarray;
152 i_ft2_is_multiple_master($self->{id});
158 my ($num_axis, $num_design, @axes) =
159 i_ft2_get_multiple_masters($self->{id})
160 or return Imager->_set_error(Imager->_error_as_msg);
166 my ($self, %opts) = @_;
169 or return Imager->_set_error("Missing coords parameter");
170 ref($opts{coords}) && $opts{coords} =~ /ARRAY\(0x[\da-f]+\)$/
171 or return Imager->_set_error("coords parameter must be an ARRAY ref");
173 i_ft2_set_mm_coords($self->{id}, @{$opts{coords}})
174 or return Imager->_set_error(Imager->_error_as_msg);
185 Imager::Font::FreeType2 - low-level functions for FreeType2 text output
189 Imager::Font creates a Imager::Font::FreeType2 object when asked to.
191 See Imager::Font to see how to use this type.
193 This class provides low-level functions that require the caller to
194 perform data validation.
196 This driver supports:
206 The following parameters:
226 =head2 Special behaviors
228 If you call transform() to set a transformation matrix, hinting will
229 be switched off. This prevents sudden jumps in the size of the text
230 caused by the hinting when the transformation is the identity matrix.
231 If for some reason you want hinting enabled, use
232 $font->hinting(hinting=>1) to re-enable hinting. This will need to be
233 called after I<each> call to transform().