1 package Imager::Font::Truetype;
3 use vars qw(@ISA $VERSION);
4 @ISA = qw(Imager::Font);
8 *_first = \&Imager::Font::_first;
12 my %hsh=(color=>Imager::Color->new(255,0,0,255),
17 $Imager::ERRSTR = "No font file specified";
20 unless (-e $hsh{file}) {
21 $Imager::ERRSTR = "Font file $hsh{file} not found";
24 unless ($Imager::formats{tt}) {
25 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
28 my $id = Imager::i_tt_new($hsh{file});
29 unless ($id) { # the low-level code may miss some error handling
30 $Imager::ERRSTR = Imager::_error_as_msg();
47 if ( exists $input{channel} ) {
48 Imager::i_tt_cp($self->{id},$input{image}{IMG},
49 $input{'x'}, $input{'y'}, $input{channel}, $input{size},
50 $input{string}, $input{aa},
51 $input{utf8}, $input{align});
53 Imager::i_tt_text($self->{id}, $input{image}{IMG},
54 $input{'x'}, $input{'y'}, $input{color},
55 $input{size}, $input{string},
56 $input{aa}, $input{utf8},
65 Imager::i_tt_bbox($self->{id}, $input{size}, $input{string}, $input{utf8});
67 Imager->_set_error(Imager->_error_as_msg);
76 # check if the font has the characters in the given string
78 my ($self, %hsh) = @_;
80 unless (defined $hsh{string}) {
81 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
85 my @result = Imager::i_tt_has_chars($self->{id}, $hsh{string},
86 _first($hsh{'utf8'}, $self->{utf8}, 0));
88 Imager->_set_error(Imager->_error_as_msg);
94 my $result = Imager::i_tt_has_chars($self->{id}, $hsh{string},
95 _first($hsh{'utf8'}, $self->{utf8}, 0));
96 unless (defined $result) {
97 Imager->_set_error(Imager->_error_as_msg);
108 Imager::i_tt_face_name($self->{id});
111 sub can_glyph_names {
116 my ($self, %input) = @_;
118 my $string = $input{string};
120 or return Imager->_set_error("no string parameter passed to glyph_names");
121 my $utf8 = _first($input{utf8} || 0);
123 my @names = Imager::i_tt_glyph_name($self->{id}, $string, $utf8);
125 Imager->_set_error(Imager->_error_as_msg);
138 Imager::Font::Truetype - low-level functions for Truetype fonts
142 Imager::Font creates a Imager::Font::Truetype object when asked to
143 create a font object based on a F<.ttf> file.
145 See Imager::Font to see how to use this type.
147 This class provides low-level functions that require the caller to
148 perform data validation.