1 package Imager::Font::Truetype;
4 @ISA = qw(Imager::Font);
6 *_first = \&Imager::Font::_first;
10 my %hsh=(color=>Imager::Color->new(255,0,0,0),
15 $Imager::ERRSTR = "No font file specified";
18 unless (-e $hsh{file}) {
19 $Imager::ERRSTR = "Font file $hsh{file} not found";
22 unless ($Imager::formats{tt}) {
23 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
26 my $id = Imager::i_tt_new($hsh{file});
27 unless ($id >= 0) { # the low-level code may miss some error handling
28 $Imager::ERRSTR = "Could not load font ($id)";
45 # note that the string length parameter is ignored and calculated in
46 # XS with SvPV(), since we want the number of bytes rather than the
47 # number of characters, which is what we'd get in perl for a UTF8
48 # encoded string in 5.6 and later
50 if ( exists $input{channel} ) {
51 Imager::i_tt_cp($self->{id},$input{image}{IMG},
52 $input{'x'}, $input{'y'}, $input{channel}, $input{size},
53 $input{string}, length($input{string}),$input{aa},
56 Imager::i_tt_text($self->{id}, $input{image}{IMG},
57 $input{'x'}, $input{'y'}, $input{color},
58 $input{size}, $input{string},
59 length($input{string}), $input{aa}, $input{utf8});
66 return Imager::i_tt_bbox($self->{id}, $input{size},
67 $input{string}, length($input{string}),
73 # check if the font has the characters in the given string
75 my ($self, %hsh) = @_;
77 unless (defined $hsh{string} && length $hsh{string}) {
78 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
81 return Imager::i_tt_has_chars($self->{id}, $hsh{string}, $hsh{'utf8'} || 0);
87 Imager::i_tt_face_name($self->{id});
91 my ($self, %input) = @_;
93 my $string = $input{string};
95 or return Imager->_seterror("no string parameter passed to glyph_names");
96 my $utf8 = _first($input{utf8} || 0);
98 Imager::i_tt_glyph_name($self->{id}, $string, $utf8);
107 Imager::Font::Truetype - low-level functions for Truetype fonts
111 Imager::Font creates a Imager::Font::Truetype object when asked to create
112 a font object based on a .ttf file.
114 See Imager::Font to see how to use this type.
116 This class provides low-level functions that require the caller to
117 perform data validation.