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->_seterror("no string parameter passed to glyph_names");
136 my $utf8 = _first($input{utf8} || 0);
138 i_ft2_glyph_name($self->{id}, $string, $utf8);
147 Imager::Font::FreeType2 - low-level functions for FreeType2 text output
151 Imager::Font creates a Imager::Font::FreeType2 object when asked to.
153 See Imager::Font to see how to use this type.
155 This class provides low-level functions that require the caller to
156 perform data validation.
158 This driver supports:
168 The following parameters:
182 =head2 Special behaviors
184 If you call transform() to set a transformation matrix, hinting will
185 be switched off. This prevents sudden jumps in the size of the text
186 caused by the hinting when the transformation is the identity matrix.
187 If for some reason you want hinting enabled, use
188 $font->hinting(hinting=>1) to re-enable hinting. This will need to be
189 called after I<each> call to transform().