has_chars() support for freetype 1.x
[imager.git] / lib / Imager / Font / Type1.pm
CommitLineData
96190b6e
TC
1package Imager::Font::Type1;
2use strict;
3use Imager::Color;
4use vars qw(@ISA);
5@ISA = qw(Imager::Font);
96190b6e
TC
6
7my $t1aa;
8
9# $T1AA is in there because for some reason (probably cache related) antialiasing
10# is a system wide setting in t1 lib.
11
12sub t1_set_aa_level {
13 if (!defined $t1aa or $_[0] != $t1aa) {
14 Imager::i_t1_set_aa($_[0]);
15 $t1aa=$_[0];
16 }
17}
18
19sub new {
20 my $class = shift;
21 my %hsh=(color=>Imager::Color->new(255,0,0,0),
22 size=>15,
23 @_);
24
25 unless ($hsh{file}) {
26 $Imager::ERRSTR = "No font file specified";
27 return;
28 }
29 unless (-e $hsh{file}) {
30 $Imager::ERRSTR = "Font file $hsh{file} not found";
31 return;
32 }
33 unless ($Imager::formats{t1}) {
34 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
35 return;
36 }
37 unless ($hsh{file} =~ m!^/! || $hsh{file} =~ m!^\./!) {
9d540150 38 $hsh{file} = './' . $hsh{file};
96190b6e 39 }
6b012d62
TC
40
41 if($hsh{afm}) {
42 unless (-e $hsh{afm}) {
43 $Imager::ERRSTR = "Afm file $hsh{afm} not found";
44 return;
45 }
46 unless ($hsh{afm} =~ m!^/! || $hsh{afm} =~ m!^\./!) {
47 $hsh{file} = './' . $hsh{file};
48 }
49 } else {
50 $hsh{afm} = 0;
51 }
52
53 my $id = Imager::i_t1_new($hsh{file},$hsh{afm});
96190b6e
TC
54 unless ($id >= 0) { # the low-level code may miss some error handling
55 $Imager::ERRSTR = "Could not load font ($id)";
56 return;
57 }
58 return bless {
59 id => $id,
60 aa => $hsh{aa} || 0,
61 file => $hsh{file},
62 type => 't1',
63 size => $hsh{size},
64 color => $hsh{color},
65 }, $class;
66}
67
68sub _draw {
69 my $self = shift;
70 my %input = @_;
71 t1_set_aa_level($input{aa});
72 if (exists $input{channel}) {
9d540150 73 Imager::i_t1_cp($input{image}{IMG}, $input{'x'}, $input{'y'},
96190b6e
TC
74 $input{channel}, $self->{id}, $input{size},
75 $input{string}, length($input{string}), $input{align});
76 } else {
9d540150 77 Imager::i_t1_text($input{image}{IMG}, $input{'x'}, $input{'y'},
96190b6e
TC
78 $input{color}, $self->{id}, $input{size},
79 $input{string}, length($input{string}),
80 $input{align});
81 }
82
83 return $self;
84}
85
86sub _bounding_box {
87 my $self = shift;
88 my %input = @_;
89 return Imager::i_t1_bbox($self->{id}, $input{size}, $input{string},
90 length($input{string}));
91}
92
931;
94
95__END__
96
97=head1 NAME
98
99 Imager::Font::Type1 - low-level functions for Type1 fonts
100
101=head1 DESCRIPTION
102
103Imager::Font creates a Imager::Font::Type1 object when asked to create
104a font object based on a .pfb file.
105
106See Imager::Font to see how to use this type.
107
108This class provides low-level functions that require the caller to
109perform data validation
110
21aa4e10
TC
111By default Imager no longer creates the F<t1lib.log> log file. You
112can re-enable that by calling Imager::init() with the C<t1log> option:
113
114 Imager::init(t1log=>1);
115
96190b6e
TC
116=head1 AUTHOR
117
118Addi, Tony
119
120=cut