1 package Imager::Font::T1;
4 use vars qw(@ISA $VERSION);
5 @ISA = qw(Imager::Font);
12 XSLoader::load('Imager::Font::T1', $VERSION);
16 *_first = \&Imager::Font::_first;
22 my %hsh=(color=>Imager::Color->new(255,0,0,255),
27 $Imager::ERRSTR = "No font file specified";
30 unless (-e $hsh{file}) {
31 $Imager::ERRSTR = "Font file $hsh{file} not found";
34 unless ($Imager::formats{t1}) {
35 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
38 # we want to avoid T1Lib's file search mechanism
39 unless ($hsh{file} =~ m!^/!
40 || $hsh{file} =~ m!^\.\/?/!
41 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/i) {
42 $hsh{file} = './' . $hsh{file};
46 unless (-e $hsh{afm}) {
47 $Imager::ERRSTR = "Afm file $hsh{afm} not found";
50 unless ($hsh{afm} =~ m!^/!
51 || $hsh{afm} =~ m!^\./!
52 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/i) {
53 $hsh{file} = './' . $hsh{file};
59 my $font = Imager::Font::T1xs->new($hsh{file},$hsh{afm});
60 unless ($font) { # the low-level code may miss some error handling
61 Imager->_set_error(Imager->_error_as_msg);
83 $flags .= 'u' if $input{underline};
84 $flags .= 's' if $input{strikethrough};
85 $flags .= 'o' if $input{overline};
86 my $aa = $input{aa} ? $self->{t1aa} : 0;
87 if (exists $input{channel}) {
88 $self->{t1font}->cp($input{image}{IMG}, $input{'x'}, $input{'y'},
89 $input{channel}, $input{size},
90 $input{string}, $input{align},
91 $input{utf8}, $flags, $aa)
94 $self->{t1font}->text($input{image}{IMG}, $input{'x'}, $input{'y'},
95 $input{color}, $input{size},
96 $input{string}, $input{align}, $input{utf8}, $flags, $aa)
111 $flags .= 'u' if $input{underline};
112 $flags .= 's' if $input{strikethrough};
113 $flags .= 'o' if $input{overline};
114 my @bbox = $self->{t1font}->bbox($input{size}, $input{string},
115 $input{utf8}, $flags);
117 Imager->_set_error(Imager->_error_as_msg);
124 # check if the font has the characters in the given string
126 my ($self, %hsh) = @_;
131 unless (defined $hsh{string}) {
132 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
136 my @result = $self->{t1font}
137 ->has_chars($hsh{string}, _first($hsh{'utf8'}, $self->{utf8}, 0));
139 Imager->_set_error(Imager->_error_as_msg);
146 my $result = $self->{t1font}
147 ->has_chars($hsh{string}, _first($hsh{'utf8'}, $self->{utf8}, 0));
148 unless (defined $result) {
149 Imager->_set_error(Imager->_error_as_msg);
160 sub can_glyph_names {
170 return $self->{t1font}->face_name();
174 my ($self, %input) = @_;
179 my $string = $input{string};
181 or return Imager->_set_error("no string parameter passed to glyph_names");
182 my $utf8 = _first($input{utf8} || 0);
184 my @result = $self->{t1font}->glyph_names($string, $utf8);
186 Imager->_set_error(Imager->_error_as_msg);
194 my ($self, $new_t1aa) = @_;
196 if (!defined $new_t1aa ||
197 ($new_t1aa != 1 && $new_t1aa != 2)) {
198 Imager->_set_error("set_aa_level: parameter must be 1 or 2");
206 $self->{t1aa} = $new_t1aa;
218 unless ($self->{t1font} && Scalar::Util::blessed($self->{t1font})) {
219 Imager->_set_error("font object was created in another thread");
232 Imager::Font::Type1 - low-level functions for Type1 fonts
236 =for stopwords Freetype
238 Imager::Font::T1 is deprecated.
240 F<T1Lib> is unmaintained and has serious bugs when built on 64-bit
241 systems. Freetype 2 has Type 1 font support and is supported by
242 Imager via L<Imager::Font::FT2>.
244 L<Imager::Font> creates a C<Imager::Font::Type1 object> when asked to create
245 a font object based on a C<.pfb> file.
247 See Imager::Font to see how to use this type.
249 This class provides low-level functions that require the caller to
250 perform data validation
252 By default Imager no longer creates the F<t1lib.log> log file. You
253 can re-enable that by calling Imager::init() with the C<t1log> option:
255 Imager::init(t1log=>1);
257 This must be called before creating any fonts.
259 Currently specific to Imager::Font::Type1, you can use the following
260 flags when drawing text or calculating a bounding box:
262 =for stopwords overline strikethrough
268 C<underline> - Draw the text with an underline.
272 C<overline> - Draw the text with an overline.
276 C<strikethrough> - Draw the text with a strikethrough.
280 Obviously, if you're calculating the bounding box the size of the line
281 is included in the box, and the line isn't drawn :)
285 T1Lib supports multiple levels of anti-aliasing, by default, if you
286 request anti-aliased output, Imager::Font::T1 will use the maximum
289 You can override this with the set_t1_aa() method:
297 $font->set_aa_level(1);
298 Imager::Font::T1->set_aa_level(2);
300 Sets the T1Lib anti-aliasing level either for the specified font, or
301 for new font objects.
303 The only parameter must be 1 or 2.
305 Returns true on success.