1 package Imager::Font::T1;
4 use vars qw(@ISA $VERSION);
5 @ISA = qw(Imager::Font);
12 XSLoader::load('Imager::Font::T1', $VERSION);
16 push @ISA, 'DynaLoader';
17 bootstrap Imager::Font::T1 $VERSION;
22 *_first = \&Imager::Font::_first;
26 # $T1AA is in there because for some reason (probably cache related) antialiasing
27 # is a system wide setting in t1 lib.
30 if (!defined $t1aa or $_[0] != $t1aa) {
38 my %hsh=(color=>Imager::Color->new(255,0,0,0),
43 $Imager::ERRSTR = "No font file specified";
46 unless (-e $hsh{file}) {
47 $Imager::ERRSTR = "Font file $hsh{file} not found";
50 unless ($Imager::formats{t1}) {
51 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
54 # we want to avoid T1Lib's file search mechanism
55 unless ($hsh{file} =~ m!^/!
56 || $hsh{file} =~ m!^\.\/?/!
57 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/) {
58 $hsh{file} = './' . $hsh{file};
62 unless (-e $hsh{afm}) {
63 $Imager::ERRSTR = "Afm file $hsh{afm} not found";
66 unless ($hsh{afm} =~ m!^/!
67 || $hsh{afm} =~ m!^\./!
68 || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/) {
69 $hsh{file} = './' . $hsh{file};
75 my $id = i_t1_new($hsh{file},$hsh{afm});
76 unless ($id >= 0) { # the low-level code may miss some error handling
77 $Imager::ERRSTR = "Could not load font ($id)";
93 t1_set_aa_level($input{aa});
95 $flags .= 'u' if $input{underline};
96 $flags .= 's' if $input{strikethrough};
97 $flags .= 'o' if $input{overline};
98 if (exists $input{channel}) {
99 i_t1_cp($input{image}{IMG}, $input{'x'}, $input{'y'},
100 $input{channel}, $self->{id}, $input{size},
101 $input{string}, length($input{string}), $input{align},
102 $input{utf8}, $flags);
104 i_t1_text($input{image}{IMG}, $input{'x'}, $input{'y'},
105 $input{color}, $self->{id}, $input{size},
106 $input{string}, length($input{string}),
107 $input{align}, $input{utf8}, $flags);
117 $flags .= 'u' if $input{underline};
118 $flags .= 's' if $input{strikethrough};
119 $flags .= 'o' if $input{overline};
120 return i_t1_bbox($self->{id}, $input{size}, $input{string},
121 length($input{string}), $input{utf8}, $flags);
124 # check if the font has the characters in the given string
126 my ($self, %hsh) = @_;
128 unless (defined $hsh{string} && length $hsh{string}) {
129 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
132 return i_t1_has_chars($self->{id}, $hsh{string},
133 _first($hsh{'utf8'}, $self->{utf8}, 0));
143 i_t1_face_name($self->{id});
147 my ($self, %input) = @_;
149 my $string = $input{string};
151 or return Imager->_set_error("no string parameter passed to glyph_names");
152 my $utf8 = _first($input{utf8} || 0);
154 i_t1_glyph_name($self->{id}, $string, $utf8);
164 Imager::Font::Type1 - low-level functions for Type1 fonts
168 Imager::Font creates a Imager::Font::Type1 object when asked to create
169 a font object based on a C<.pfb> file.
171 See Imager::Font to see how to use this type.
173 This class provides low-level functions that require the caller to
174 perform data validation
176 By default Imager no longer creates the F<t1lib.log> log file. You
177 can re-enable that by calling Imager::init() with the C<t1log> option:
179 Imager::init(t1log=>1);
181 This must be called before creating any fonts.
183 Currently specific to Imager::Font::Type1, you can use the following
184 flags when drawing text or calculating a bounding box:
186 =for stopwords overline strikethrough
192 C<underline> - Draw the text with an underline.
196 C<overline> - Draw the text with an overline.
200 C<strikethrough> - Draw the text with a strikethrough.
204 Obviously, if you're calculating the bounding box the size of the line
205 is included in the box, and the line isn't drawn :)