1 package Imager::Font::BBox;
9 Imager::Font::BBox - objects representing the bounding box of a string.
16 my $font = Imager::Font->new(...);
17 my $bbox = $font->bounding_box(string=>$text, size=>$size);
20 my $start = $bbox->start_offset;
21 my $left_bearing = $bbox->left_bearing;
22 my $right_bearing = $bbox->right_bearing;
23 my $end = $bbox->end_offset;
24 my $gdescent = $box->global_descent;
25 my $gascent = $bbox->global_ascent;
26 my $ascent = $bbox->ascent;
27 my $decent = $bbox->descent;
28 my $total_width = $bbox->total_width;
29 my $fheight = $bbox->font_height;
30 my $theight = $bbox->text_height;
31 my $display_width = $bbox->display_width;
35 Objects of this class are returned by the Imager::Font bounding_box()
36 method when it is called in scalar context.
38 This will hopefully make the information from this method more
51 Returns the horizonatal offset from the selected drawing location to
52 the left edge of the first character drawn. If this is positive, the
53 first glyph is to the right of the drawing location.
55 The alias neg_width() is present to match the bounding_box()
56 documentation for list context.
58 The alias left_bearing() is present to match font terminology.
76 The advance width of the string, if the driver supports that,
77 otherwise the same as end_offset.
84 @$self > 6 ? $self->[6] : $self->[2];
89 The distance from the right of the last glyph to the end of the advance
92 If the glyph overflows the right side of the advance width this value
100 @$self >= 8 && return $self->[7]; # driver gives it to us
102 # otherwise the closest we have is the difference between the
103 # end_pos and advance_width
104 return $self->advance_width - $self->pos_width;
109 The distance from the left-most pixel of the left-most glyph to the
110 right-most pixel of the right-most glyph.
112 Equals advance_width - left_bearing - right_bearing (and implemented
120 $self->advance_width - $self->left_bearing - $self->right_bearing;
123 =item global_descent()
125 The lowest position relative to the font baseline that any character
126 in the font reaches in the character cell. Normally negative.
128 At least one font we've seen has reported a positive number for this.
136 =item global_ascent()
138 The highest position relative to the font baseline that any character
139 in the font reaches in the character cell. Normally positive.
149 The lowest position relative to the font baseline that any character
150 in the supplied string reaches. Negative when any character's glyph
151 reaches below the baseline.
161 The highest position relative to the font baseline that any character
162 in the supplied string reaches. Positive if any character's glyph
163 reaches above the baseline.
173 The maximum displayed height of any string using this font.
179 $self->global_ascent - $self->global_descent;
184 The displayed height of the supplied string.
191 $self->ascent - $self->descent;
196 =head1 OBSOLETE METHODS
198 These methods include bugs kept for backwards compatibility and
199 shouldn't be used in new code.
205 The total displayed width of the string.
207 New code should use display_width().
209 This depends on end_offset(), and is limited by it's backward
217 $self->end_offset - $self->start_offset;
224 The offset from the selected drawing location to the right edge of the
225 last character drawn. Should always be positive.
227 You can use the alias pos_width() if you are used to the
228 bounding_box() documentation for list context.
230 For backwards compatibility this method returns the maximum of the
231 advance width and the offset of the right edge of the last glyph.
245 =head1 INTERNAL FUNCTIONS
251 Called by Imager::Font->bounding_box() to create the object.
257 return bless [ @_ ], $class;
264 Doesn't reproduce the functionality that you get using the x and y
265 parameters to Imager::Font->bounding_box(). I considered:
267 my ($left, $top, $right, $bottom) = $box->offset(x=>$x, y=>$y)
269 but this is about as clumsy as the original.
273 Tony Cook <tony@develop-help.com>
277 Imager(3), Imager::Font(3)