]>
Commit | Line | Data |
---|---|---|
96190b6e TC |
1 | package Imager::Font::Truetype; |
2 | use strict; | |
3 | use vars qw(@ISA); | |
4 | @ISA = qw(Imager::Font); | |
5 | ||
6 | sub 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 | ||
39 | sub _draw { | |
40 | my $self = shift; | |
41 | my %input = @_; | |
42 | if ( exists $input{channel} ) { | |
43 | Imager::i_tt_cp($self->{id},$input{image}{IMG}, | |
44 | $input{x}, $input{'y'}, $input{channel}, $input{size}, | |
45 | $input{string}, length($input{string}),$input{aa}); | |
46 | } else { | |
47 | Imager::i_tt_text($self->{id}, $input{image}{IMG}, | |
48 | $input{x}, $input{'y'}, $input{color}, | |
49 | $input{size}, $input{string}, | |
50 | length($input{string}), $input{aa}); | |
51 | } | |
52 | } | |
53 | ||
54 | sub _bounding_box { | |
55 | my $self = shift; | |
56 | my %input = @_; | |
57 | return Imager::i_tt_bbox($self->{id}, $input{size}, | |
58 | $input{string}, length($input{string})); | |
59 | } | |
60 | ||
61 | 1; | |
62 | ||
63 | __END__ | |
64 | ||
65 | =head1 NAME | |
66 | ||
67 | Imager::Font::Truetype - low-level functions for Truetype fonts | |
68 | ||
69 | =head1 DESCRIPTION | |
70 | ||
71 | Imager::Font creates a Imager::Font::Truetype object when asked to create | |
72 | a font object based on a .ttf file. | |
73 | ||
74 | See Imager::Font to see how to use this type. | |
75 | ||
76 | This class provides low-level functions that require the caller to | |
77 | perform data validation. | |
78 | ||
79 | =head1 AUTHOR | |
80 | ||
81 | Addi, Tony | |
82 | ||
83 | =cut |