al_get_glyph_dimensions - Allegro 5 API
#include <allegro5/allegro_font.h> bool al_get_glyph_dimensions(const ALLEGRO_FONT *f,
int codepoint, int *bbx, int *bby, int *bbw, int *bbh)
Sometimes, the al_get_glyph_width(3) or al_get_glyph_advance(3) functions are not enough for exact glyph placement, so this function returns some additional information, particularly if you want to draw the font vertically.
The function itself returns true if the character was present in font and false if the character was not present in font.
Returned variables (all in pixel):
- bbx, bby - Offset to upper left corner of bounding box.
- bbw, bbh - Dimensions of bounding box.
These values are the same as al_get_text_dimensions(3) would return for a string of a single character equal to the glyph passed to this function. Note that glyphs may go to the left and upwards of the X, in which case x and y will have negative values.
If you want to draw a string verticallly, for Japanese or as a game effect, then you should leave bby + bbh space between the glyphs in the y direction for a regular placement.
If you want to draw a string horizontally in an extra compact way,
then you should leave bbx + bbw space between the glyphs in the x direction for a compact placement.
In the figure below is an example of what bbx and bby may be like for a 2 glyph, and a g glyph of the same font compared to the result of al_get_glyph_width().
/ \ / \
bbx bbw bbx bbw
<-->+<------>+ <-->+<----->+ X baseline
^ | | ^ | | bby | | | bby | | |
v | | | | |
+---+--------+ | | |
^ | ***** | | | |
| |* ** | v | | bbh | | ** | bbh +---+-------+
| | ** | ^ | ***** |
v |********| | |* *|
+---+--------+ | | ***** |
| | *|
| | * *|
v | **** |
al_draw_glyph(3), al_get_glyph_width(3), al_get_glyph_advance(3).
|Allegro reference manual|