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.
78 The offset from the selected drawing location to the right edge of the
79 last character drawn. Should always be positive.
81 You can use the alias pos_width() if you are used to the
82 bounding_box() documentation for list context.
94 =item global_descent()
96 The lowest position relative to the font baseline that any character
97 in the font reaches in the character cell. Normally negative.
99 At least one font we've seen has reported a positive number for this.
107 =item global_ascent()
109 The highest position relative to the font baseline that any character
110 in the font reaches in the character cell. Normally positive.
120 The lowest position relative to the font baseline that any character
121 in the supplied string reaches. Negative when any character's glyph
122 reaches below the baseline.
132 The highest position relative to the font baseline that any character
133 in the supplied string reaches. Positive if any character's glyph
134 reaches above the baseline.
142 =item advance_width()
144 The advance width of the string, if the driver supports that,
145 otherwise the same as end_offset.
152 @$self > 6 ? $self->[6] : $self->[2];
157 The total displayed width of the string.
164 $self->end_offset - $self->start_offset;
169 The maximum displayed height of any string using this font.
175 $self->global_ascent - $self->global_descent;
180 The displayed height of the supplied string.
187 $self->ascent - $self->descent;
192 The distance from the right of the last glyph to the end of the advance
195 If the glyph overflows the right side of the advance width this value
203 @$self >= 8 && return $self->[7]; # driver gives it to us
205 # otherwise the closest we have is the difference between the
206 # end_pos and advance_width
207 return $self->advance_width - $self->pos_width;
212 The distance from the left-most pixel of the left-most glyph to the
213 right-most pixel of the right-most glyph.
215 Equals advance_width - left_bearing - right_bearing (and implemented
223 $self->advance_width - $self->left_bearing - $self->right_bearing;
228 =head1 INTERNAL FUNCTIONS
234 Called by Imager::Font->bounding_box() to create the object.
240 return bless [ @_ ], $class;
247 Doesn't reproduce the functionality that you get using the x and y
248 parameters to Imager::Font->bounding_box(). I considered:
250 my ($left, $top, $right, $bottom) = $box->offset(x=>$x, y=>$y)
252 but this is about as clumsy as the original.
256 Tony Cook <tony@develop-help.com>
260 Imager(3), Imager::Font(3)