1 package Imager::Font::FreeType2;
5 @ISA = qw(Imager::Font);
7 *_first = \&Imager::Font::_first;
11 my %hsh=(color=>Imager::Color->new(255,0,0,0),
16 $Imager::ERRSTR = "No font file specified";
19 unless (-e $hsh{file}) {
20 $Imager::ERRSTR = "Font file $hsh{file} not found";
23 unless ($Imager::formats{ft2}) {
24 $Imager::ERRSTR = "Freetype2 not supported in this build";
27 my $id = i_ft2_new($hsh{file}, $hsh{'index'} || 0);
28 unless ($id) { # the low-level code may miss some error handling
29 $Imager::ERRSTR = Imager::_error_as_msg();
40 vlayout => $hsh{vlayout},
47 if (exists $input{channel}) {
48 i_ft2_cp($self->{id}, $input{image}{IMG}, $input{'x'}, $input{'y'},
49 $input{channel}, $input{size}, $input{sizew} || 0,
50 $input{string}, , $input{align}, $input{aa}, $input{vlayout},
53 i_ft2_text($self->{id}, $input{image}{IMG},
54 $input{'x'}, $input{'y'},
55 $input{color}, $input{size}, $input{sizew} || 0,
56 $input{string}, $input{align}, $input{aa}, $input{vlayout},
65 return i_ft2_bbox($self->{id}, $input{size}, $input{sizew}, $input{string},
71 my @old = i_ft2_getdpi($self->{id});
75 unless ($hsh{xdpi} && $hsh{ydpi}) {
77 $hsh{xdpi} = $hsh{ydpi} = $hsh{dpi};
80 $Imager::ERRSTR = "dpi method requires xdpi and ydpi or just dpi";
83 i_ft2_setdpi($self->{id}, $hsh{xdpi}, $hsh{ydpi}) or return;
91 my ($self, %opts) = @_;
93 i_ft2_sethinting($self->{id}, $opts{hinting} || 0);
100 my $matrix = $hsh{matrix} or return undef;
102 return i_ft2_settransform($self->{id}, $matrix)
109 # check if the font has the characters in the given string
111 my ($self, %hsh) = @_;
113 unless (defined $hsh{string} && length $hsh{string}) {
114 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
117 return i_ft2_has_chars($self->{id}, $hsh{string}, $hsh{'utf8'} || 0);
123 i_ft2_face_name($self->{id});
126 sub can_glyph_names {
127 i_ft2_can_do_glyph_names();
131 my ($self, %input) = @_;
133 my $string = $input{string};
135 or return Imager->_set_error("no string parameter passed to glyph_names");
136 my $utf8 = _first($input{utf8}, 0);
137 my $reliable_only = _first($input{reliable_only}, 1);
139 my @names = i_ft2_glyph_name($self->{id}, $string, $utf8, $reliable_only);
140 @names or return Imager->_set_error(Imager->_error_as_msg);
142 return @names if wantarray;
149 i_ft2_is_multiple_master($self->{id});
155 my ($num_axis, $num_design, @axes) =
156 i_ft2_get_multiple_masters($self->{id})
157 or return Imager->_set_error(Imager->_error_as_msg);
163 my ($self, %opts) = @_;
166 or return Imager->_set_error("Missing coords parameter");
167 ref($opts{coords}) && $opts{coords} =~ /ARRAY\(0x[\da-f]+\)$/
168 or return Imager->_set_error("coords parameter must be an ARRAY ref");
170 i_ft2_set_mm_coords($self->{id}, @{$opts{coords}})
171 or return Imager->_set_error(Imager->_error_as_msg);
182 Imager::Font::FreeType2 - low-level functions for FreeType2 text output
186 Imager::Font creates a Imager::Font::FreeType2 object when asked to.
188 See Imager::Font to see how to use this type.
190 This class provides low-level functions that require the caller to
191 perform data validation.
193 This driver supports:
203 The following parameters:
217 =head2 Special behaviors
219 If you call transform() to set a transformation matrix, hinting will
220 be switched off. This prevents sudden jumps in the size of the text
221 caused by the hinting when the transformation is the identity matrix.
222 If for some reason you want hinting enabled, use
223 $font->hinting(hinting=>1) to re-enable hinting. This will need to be
224 called after I<each> call to transform().