Modified i_line_aa to use a modified bresenham algorithm. This method
[imager.git] / lib / Imager / Font / Truetype.pm
CommitLineData
96190b6e
TC
1package Imager::Font::Truetype;
2use strict;
3use vars qw(@ISA);
4@ISA = qw(Imager::Font);
5
6sub new {
7 my $class = shift;
8 my %hsh=(color=>Imager::Color->new(255,0,0,0),
9 size=>15,
10 @_);
11
12 unless ($hsh{file}) {
13 $Imager::ERRSTR = "No font file specified";
14 return;
15 }
16 unless (-e $hsh{file}) {
17 $Imager::ERRSTR = "Font file $hsh{file} not found";
18 return;
19 }
20 unless ($Imager::formats{tt}) {
21 $Imager::ERRSTR = "Type 1 fonts not supported in this build";
22 return;
23 }
24 my $id = Imager::i_tt_new($hsh{file});
25 unless ($id >= 0) { # the low-level code may miss some error handling
26 $Imager::ERRSTR = "Could not load font ($id)";
27 return;
28 }
29 return bless {
30 id => $id,
31 aa => $hsh{aa} || 0,
32 file => $hsh{file},
33 type => 'tt',
34 size => $hsh{size},
35 color => $hsh{color},
36 }, $class;
37}
38
39sub _draw {
40 my $self = shift;
41 my %input = @_;
4f68b48f
TC
42
43 # note that the string length parameter is ignored and calculated in
44 # XS with SvPV(), since we want the number of bytes rather than the
45 # number of characters, which is what we'd get in perl for a UTF8
46 # encoded string in 5.6 and later
47
96190b6e
TC
48 if ( exists $input{channel} ) {
49 Imager::i_tt_cp($self->{id},$input{image}{IMG},
9d540150 50 $input{'x'}, $input{'y'}, $input{channel}, $input{size},
4f68b48f
TC
51 $input{string}, length($input{string}),$input{aa},
52 $input{utf8});
96190b6e
TC
53 } else {
54 Imager::i_tt_text($self->{id}, $input{image}{IMG},
9d540150 55 $input{'x'}, $input{'y'}, $input{color},
96190b6e 56 $input{size}, $input{string},
4f68b48f 57 length($input{string}), $input{aa}, $input{utf8});
96190b6e
TC
58 }
59}
60
61sub _bounding_box {
62 my $self = shift;
63 my %input = @_;
64 return Imager::i_tt_bbox($self->{id}, $input{size},
4f68b48f
TC
65 $input{string}, length($input{string}),
66 $input{utf8});
96190b6e
TC
67}
68
4f68b48f
TC
69sub utf8 { 1 }
70
96190b6e
TC
711;
72
73__END__
74
75=head1 NAME
76
77 Imager::Font::Truetype - low-level functions for Truetype fonts
78
79=head1 DESCRIPTION
80
81Imager::Font creates a Imager::Font::Truetype object when asked to create
82a font object based on a .ttf file.
83
84See Imager::Font to see how to use this type.
85
86This class provides low-level functions that require the caller to
87perform data validation.
88
89=head1 AUTHOR
90
91Addi, Tony
92
93=cut