1 package Imager::Font::T1;
4 use vars qw(@ISA $VERSION);
5 @ISA = qw(Imager::Font);
11 XSLoader::load('Imager::Font::T1', $VERSION);
15 *_first = \&Imager::Font::_first;
19 # $T1AA is in there because for some reason (probably cache related) antialiasing
20 # is a system wide setting in t1 lib.
23 if (!defined $t1aa or $_[0] != $t1aa) {
31 my %hsh=(color=>Imager::Color->new(255,0,0,255),
36 $Imager::ERRSTR = "No font file specified";
39 unless (-e $hsh{file}) {
40 $Imager::ERRSTR = "Font file $hsh{file} not found";
43 unless ($Imager::formats{t1}) {
44 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
47 # we want to avoid T1Lib's file search mechanism
48 unless ($hsh{file} =~ m!^/!
49 || $hsh{file} =~ m!^\.\/?/!
50 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/i) {
51 $hsh{file} = './' . $hsh{file};
55 unless (-e $hsh{afm}) {
56 $Imager::ERRSTR = "Afm file $hsh{afm} not found";
59 unless ($hsh{afm} =~ m!^/!
60 || $hsh{afm} =~ m!^\./!
61 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/i) {
62 $hsh{file} = './' . $hsh{file};
68 my $id = i_t1_new($hsh{file},$hsh{afm});
69 unless ($id >= 0) { # the low-level code may miss some error handling
70 Imager->_set_error(Imager->_error_as_msg);
86 t1_set_aa_level($input{aa});
88 $flags .= 'u' if $input{underline};
89 $flags .= 's' if $input{strikethrough};
90 $flags .= 'o' if $input{overline};
91 if (exists $input{channel}) {
92 i_t1_cp($input{image}{IMG}, $input{'x'}, $input{'y'},
93 $input{channel}, $self->{id}, $input{size},
94 $input{string}, length($input{string}), $input{align},
95 $input{utf8}, $flags);
97 i_t1_text($input{image}{IMG}, $input{'x'}, $input{'y'},
98 $input{color}, $self->{id}, $input{size},
99 $input{string}, length($input{string}),
100 $input{align}, $input{utf8}, $flags);
110 $flags .= 'u' if $input{underline};
111 $flags .= 's' if $input{strikethrough};
112 $flags .= 'o' if $input{overline};
113 return i_t1_bbox($self->{id}, $input{size}, $input{string},
114 length($input{string}), $input{utf8}, $flags);
117 # check if the font has the characters in the given string
119 my ($self, %hsh) = @_;
121 unless (defined $hsh{string} && length $hsh{string}) {
122 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
125 return i_t1_has_chars($self->{id}, $hsh{string},
126 _first($hsh{'utf8'}, $self->{utf8}, 0));
136 i_t1_face_name($self->{id});
140 my ($self, %input) = @_;
142 my $string = $input{string};
144 or return Imager->_set_error("no string parameter passed to glyph_names");
145 my $utf8 = _first($input{utf8} || 0);
147 i_t1_glyph_name($self->{id}, $string, $utf8);
157 Imager::Font::Type1 - low-level functions for Type1 fonts
161 Imager::Font creates a Imager::Font::Type1 object when asked to create
162 a font object based on a C<.pfb> file.
164 See Imager::Font to see how to use this type.
166 This class provides low-level functions that require the caller to
167 perform data validation
169 By default Imager no longer creates the F<t1lib.log> log file. You
170 can re-enable that by calling Imager::init() with the C<t1log> option:
172 Imager::init(t1log=>1);
174 This must be called before creating any fonts.
176 Currently specific to Imager::Font::Type1, you can use the following
177 flags when drawing text or calculating a bounding box:
179 =for stopwords overline strikethrough
185 C<underline> - Draw the text with an underline.
189 C<overline> - Draw the text with an overline.
193 C<strikethrough> - Draw the text with a strikethrough.
197 Obviously, if you're calculating the bounding box the size of the line
198 is included in the box, and the line isn't drawn :)