1 package Imager::Font::Type1;
5 @ISA = qw(Imager::Font);
7 *_first = \&Imager::Font::_first;
11 # $T1AA is in there because for some reason (probably cache related) antialiasing
12 # is a system wide setting in t1 lib.
15 if (!defined $t1aa or $_[0] != $t1aa) {
16 Imager::i_t1_set_aa($_[0]);
23 my %hsh=(color=>Imager::Color->new(255,0,0,0),
28 $Imager::ERRSTR = "No font file specified";
31 unless (-e $hsh{file}) {
32 $Imager::ERRSTR = "Font file $hsh{file} not found";
35 unless ($Imager::formats{t1}) {
36 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
39 unless ($hsh{file} =~ m!^/! || $hsh{file} =~ m!^\./!) {
40 $hsh{file} = './' . $hsh{file};
44 unless (-e $hsh{afm}) {
45 $Imager::ERRSTR = "Afm file $hsh{afm} not found";
48 unless ($hsh{afm} =~ m!^/! || $hsh{afm} =~ m!^\./!) {
49 $hsh{file} = './' . $hsh{file};
55 my $id = Imager::i_t1_new($hsh{file},$hsh{afm});
56 unless ($id >= 0) { # the low-level code may miss some error handling
57 $Imager::ERRSTR = "Could not load font ($id)";
73 t1_set_aa_level($input{aa});
75 $flags .= 'u' if $input{underline};
76 $flags .= 's' if $input{strikethrough};
77 $flags .= 'o' if $input{overline};
78 if (exists $input{channel}) {
79 Imager::i_t1_cp($input{image}{IMG}, $input{'x'}, $input{'y'},
80 $input{channel}, $self->{id}, $input{size},
81 $input{string}, length($input{string}), $input{align},
82 $input{utf8}, $flags);
84 Imager::i_t1_text($input{image}{IMG}, $input{'x'}, $input{'y'},
85 $input{color}, $self->{id}, $input{size},
86 $input{string}, length($input{string}),
87 $input{align}, $input{utf8}, $flags);
97 $flags .= 'u' if $input{underline};
98 $flags .= 's' if $input{strikethrough};
99 $flags .= 'o' if $input{overline};
100 return Imager::i_t1_bbox($self->{id}, $input{size}, $input{string},
101 length($input{string}), $input{utf8}, $flags);
104 # check if the font has the characters in the given string
106 my ($self, %hsh) = @_;
108 unless (defined $hsh{string} && length $hsh{string}) {
109 $Imager::ERRSTR = "No string supplied to \$font->has_chars()";
112 return Imager::i_t1_has_chars($self->{id}, $hsh{string}, $hsh{'utf8'} || 0);
122 Imager::i_t1_face_name($self->{id});
126 my ($self, %input) = @_;
128 my $string = $input{string};
130 or return Imager->_seterror("no string parameter passed to glyph_names");
131 my $utf8 = _first($input{utf8} || 0);
133 Imager::i_t1_glyph_name($self->{id}, $string, $utf8);
143 Imager::Font::Type1 - low-level functions for Type1 fonts
147 Imager::Font creates a Imager::Font::Type1 object when asked to create
148 a font object based on a .pfb file.
150 See Imager::Font to see how to use this type.
152 This class provides low-level functions that require the caller to
153 perform data validation
155 By default Imager no longer creates the F<t1lib.log> log file. You
156 can re-enable that by calling Imager::init() with the C<t1log> option:
158 Imager::init(t1log=>1);
160 Currently specific to Imager::Font::Type1, you can use the following
161 flags when drawing text or calculating a bounding box:
167 Draw the text with an underline.
171 Draw the text with an overline.
175 Draw the text with a strikethrough.
179 Obviously, if you're calculating the bounding box the size of the line
180 is included in the box, and the line isn't drawn :)