split Imager::Font into base *::Type1 and *::Truetype, which should
[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);
6use File::Spec;
7
8my $t1aa;
9
10# $T1AA is in there because for some reason (probably cache related) antialiasing
11# is a system wide setting in t1 lib.
12
13sub t1_set_aa_level {
14 if (!defined $t1aa or $_[0] != $t1aa) {
15 Imager::i_t1_set_aa($_[0]);
16 $t1aa=$_[0];
17 }
18}
19
20sub new {
21 my $class = shift;
22 my %hsh=(color=>Imager::Color->new(255,0,0,0),
23 size=>15,
24 @_);
25
26 unless ($hsh{file}) {
27 $Imager::ERRSTR = "No font file specified";
28 return;
29 }
30 unless (-e $hsh{file}) {
31 $Imager::ERRSTR = "Font file $hsh{file} not found";
32 return;
33 }
34 unless ($Imager::formats{t1}) {
35 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
36 return;
37 }
38 unless ($hsh{file} =~ m!^/! || $hsh{file} =~ m!^\./!) {
39 $hsh{file} = File::Spec->catfile(File::Spec->curdir, $hsh{file});
40 }
41 my $id = Imager::i_t1_new($hsh{file});
42 unless ($id >= 0) { # the low-level code may miss some error handling
43 $Imager::ERRSTR = "Could not load font ($id)";
44 return;
45 }
46 return bless {
47 id => $id,
48 aa => $hsh{aa} || 0,
49 file => $hsh{file},
50 type => 't1',
51 size => $hsh{size},
52 color => $hsh{color},
53 }, $class;
54}
55
56sub _draw {
57 my $self = shift;
58 my %input = @_;
59 t1_set_aa_level($input{aa});
60 if (exists $input{channel}) {
61 Imager::i_t1_cp($input{image}{IMG}, $input{x}, $input{'y'},
62 $input{channel}, $self->{id}, $input{size},
63 $input{string}, length($input{string}), $input{align});
64 } else {
65 Imager::i_t1_text($input{image}{IMG}, $input{x}, $input{'y'},
66 $input{color}, $self->{id}, $input{size},
67 $input{string}, length($input{string}),
68 $input{align});
69 }
70
71 return $self;
72}
73
74sub _bounding_box {
75 my $self = shift;
76 my %input = @_;
77 return Imager::i_t1_bbox($self->{id}, $input{size}, $input{string},
78 length($input{string}));
79}
80
811;
82
83__END__
84
85=head1 NAME
86
87 Imager::Font::Type1 - low-level functions for Type1 fonts
88
89=head1 DESCRIPTION
90
91Imager::Font creates a Imager::Font::Type1 object when asked to create
92a font object based on a .pfb file.
93
94See Imager::Font to see how to use this type.
95
96This class provides low-level functions that require the caller to
97perform data validation
98
99=head1 AUTHOR
100
101Addi, Tony
102
103=cut