SDL_ttf
SDL_ttf > Functions > Attributes
TTF_GlyphMetrics
int TTF_GlyphMetrics(TTF_Font *font, Uint16 ch, int *minx, int *maxx, int *miny, int *maxy, int *advance)
font
- The loaded font to get the glyph metric from.
ch
- The character to get the metrics from.
minx
- The left side of the glyph.
maxx
- The right side of the glyph.
miny
- The bottom of the glyph.
maxy
- The top of the glyph.
advance
- The amount to advance the pen forward after drawing (ie the width of the glyph with spacing on both sides).
Gets the glyph metrics from the font file.
NOTE: Passing a NULL font into this function will cause a segfault.
NOTE: This image may help understand the different metrics.
(from the FreeType page).
Returns:
// get the character's metrics from the loaded font
//TTF_Font *font;
int error;
int minx, maxx, miny, maxy, advance;
char c = 'x';
error=TTF_GlyphMetrics(font, c, &minx, &maxx, &miny, &maxy, &advance);
if(error)
printf("Error, could not find character %c.", c);
else
printf("x = %i to %i, y = %i to %i, advance = %i.", minx, maxx, miny, maxy, advance);
