1 package Imager::Font::Type1;
4 use vars qw(@ISA $VERSION);
5 @ISA = qw(Imager::Font);
9 *_first = \&Imager::Font::_first;
13 # $T1AA is in there because for some reason (probably cache related) antialiasing
14 # is a system wide setting in t1 lib.
17 if (!defined $t1aa or $_[0] != $t1aa) {
18 Imager::i_t1_set_aa($_[0]);
25 my %hsh=(color=>Imager::Color->new(255,0,0,0),
30 $Imager::ERRSTR = "No font file specified";
33 unless (-e $hsh{file}) {
34 $Imager::ERRSTR = "Font file $hsh{file} not found";
37 unless ($Imager::formats{t1}) {
38 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
41 # we want to avoid T1Lib's file search mechanism
42 unless ($hsh{file} =~ m!^/!
43 || $hsh{file} =~ m!^\.\/?/!
44 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/) {
45 $hsh{file} = './' . $hsh{file};
49 unless (-e $hsh{afm}) {
50 $Imager::ERRSTR = "Afm file $hsh{afm} not found";
53 unless ($hsh{afm} =~ m!^/!
54 || $hsh{afm} =~ m!^\./!
55 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/) {
56 $hsh{file} = './' . $hsh{file};
62 my $id = Imager::i_t1_new($hsh{file},$hsh{afm});
63 unless ($id >= 0) { # the low-level code may miss some error handling
64 $Imager::ERRSTR = "Could not load font ($id)";
80 t1_set_aa_level($input{aa});
82 $flags .= 'u' if $input{underline};
83 $flags .= 's' if $input{strikethrough};
84 $flags .= 'o' if $input{overline};
85 if (exists $input{channel}) {
86 Imager::i_t1_cp($input{image}{IMG}, $input{'x'}, $input{'y'},
87 $input{channel}, $self->{id}, $input{size},
88 $input{string}, length($input{string}), $input{align},
89 $input{utf8}, $flags);
91 Imager::i_t1_text($input{image}{IMG}, $input{'x'}, $input{'y'},
92 $input{color}, $self->{id}, $input{size},
93 $input{string}, length($input{string}),
94 $input{align}, $input{utf8}, $flags);
104 $flags .= 'u' if $input{underline};
105 $flags .= 's' if $input{strikethrough};
106 $flags .= 'o' if $input{overline};
107 return Imager::i_t1_bbox($self->{id}, $input{size}, $input{string},
108 length($input{string}), $input{utf8}, $flags);
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 Imager::i_t1_has_chars($self->{id}, $hsh{string},
120 _first($hsh{'utf8'}, $self->{utf8}, 0));
130 Imager::i_t1_face_name($self->{id});
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);
141 Imager::i_t1_glyph_name($self->{id}, $string, $utf8);
151 Imager::Font::Type1 - low-level functions for Type1 fonts
155 Imager::Font creates a Imager::Font::Type1 object when asked to create
156 a font object based on a C<.pfb> file.
158 See Imager::Font to see how to use this type.
160 This class provides low-level functions that require the caller to
161 perform data validation
163 By default Imager no longer creates the F<t1lib.log> log file. You
164 can re-enable that by calling Imager::init() with the C<t1log> option:
166 Imager::init(t1log=>1);
168 This must be called before creating any fonts.
170 Currently specific to Imager::Font::Type1, you can use the following
171 flags when drawing text or calculating a bounding box:
173 =for stopwords overline strikethrough
179 C<underline> - Draw the text with an underline.
183 C<overline> - Draw the text with an overline.
187 C<strikethrough> - Draw the text with a strikethrough.
191 Obviously, if you're calculating the bounding box the size of the line
192 is included in the box, and the line isn't drawn :)