- fix a few compiler warnings
[imager.git] / lib / Imager / Font / BBox.pm
CommitLineData
3799c4d1
TC
1package Imager::Font::BBox;
2use strict;
3
4=head1 NAME
5
6Imager::Font::BBox - objects representing the bounding box of a string.
7
8=head1 SYNOPSIS
9
10 use Imager::Font;
11
12 # get the object
13 my $font = Imager::Font->new(...);
14 my $bbox = $font->bounding_box(string=>$text, size=>$size);
15
16 # methods
17 my $start = $bbox->start_offset;
18 my $end = $bbox->end_offset;
19 my $gdescent = $box->global_descent;
20 my $gascent = $bbox->global_ascent;
21 my $ascent = $bbox->ascent;
22 my $decent = $bbox->descent;
23 my $total_width = $bbox->total_width;
24 my $fheight = $bbox->font_height;
25 my $theight = $bbox->text_height;
26
27=head1 DESCRIPTION
28
29Objects of this class are returned by the Imager::Font bounding_box()
30method when it is called in scalar context.
31
32This will hopefully make the information from this method more
33accessible.
34
35=head1 METHODS
36
37=over
38
39=item start_offset()
40
41Returns the horizonatal offset from the selected drawing location to
42the left edge of the first character drawn. If this is positive, the
43first glyph is to the right of the drawing location.
44
45The alias neg_width() is present to match the bounding_box()
46documentation for list context.
47
48=cut
49
50sub start_offset {
51 return $_[0][0];
52}
53
54sub neg_width {
55 return $_[0][0];
56}
57
58=item end_offset()
59
60The offset from the selected drawing location to the right edge of the
61last character drawn. Should always be positive.
62
63You can use the alias pos_width() if you are used to the
64bounding_box() documentation for list context.
65
66=cut
67
68sub end_offset {
69 return $_[0][2];
70}
71
72sub pos_width {
73 return $_[0][2];
74}
75
76=item global_descent()
77
78The lowest position relative to the font baseline that any character
79in the font reaches in the character cell. Normally negative.
80
81At least one font we've seen has reported a positive number for this.
82
83=cut
84
85sub global_descent {
86 return $_[0][1];
87}
88
89=item global_ascent()
90
91The highest position relative to the font baseline that any character
92in the font reaches in the character cell. Normally positive.
93
94=cut
95
96sub global_ascent {
97 return $_[0][3];
98}
99
100=item descent()
101
102The lowest position relative to the font baseline that any character
103in the supplied string reaches. Negative when any character's glyph
104reaches below the baseline.
105
106=cut
107
108sub descent {
109 return $_[0][4];
110}
111
112=item ascent()
113
114The highest position relative to the font baseline that any character
115in the supplied string reaches. Positive if any character's glyph
116reaches above the baseline.
117
118=cut
119
120sub ascent {
121 return $_[0][5];
122}
123
124=item advance_width()
125
35891892
TC
126The advance width of the string, if the driver supports that,
127otherwise the same as end_offset.
128
3799c4d1
TC
129=cut
130
131sub advance_width {
132 my $self = shift;
133
134 @$self > 6 ? $self->[6] : $self->[5];
135}
136
137=item total_width()
138
139The total displayed width of the string.
140
141=cut
142
143sub total_width {
144 my $self = shift;
145
146 $self->end_offset - $self->start_offset;
147}
148
149=item font_height()
150
151The maximum displayed height of any string using this font.
152
153=cut
154
155sub font_height {
156 my $self = shift;
157 $self->global_ascent - $self->global_descent;
158}
159
160=item text_height()
161
162The displayed height of the supplied string.
163
164=cut
165
166sub text_height {
167 my $self = shift;
168
169 $self->ascent - $self->descent;
170}
171
172=back
173
174=head1 INTERNAL FUNCTIONS
175
176=over
177
178=item new(...)
179
180Called by Imager::Font->bounding_box() to create the object.
181
182=cut
183
184sub new {
185 my $class = shift;
186 return bless [ @_ ], $class;
187}
188
189=back
190
191=head1 BUGS
192
193Doesn't reproduce the functionality that you get using the x and y
194parameters to Imager::Font->bounding_box(). I considered:
195
196 my ($left, $top, $right, $bottom) = $box->offset(x=>$x, y=>$y)
197
198but this is about as clumsy as the original.
199
200=head1 AUTHOR
201
202Tony Cook <tony@develop-help.com>
203
204=head1 SEE ALSO
205
206Imager(3), Imager::Font(3)
207
208=cut
209
2101;
211