SDL_ttf
SDL_ttf > Functions > Attributes
Name
TTF_SizeText -- Get size of LATIN1 text string as would be rendered
Synopsis
#include "SDL.h" int TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h)
Description
font
- The loaded font to use to calculate the size of the string with.
text
- The LATIN1 null terminated string to size up.
w
- pointer to int in which to fill the text width, or NULL for no desired return value.
h
- pointer to int in which to fill the text height, or NULL for no desired return value.
Calculate the resulting surface size of the LATIN1 encoded text rendered using font. No actual rendering is done, however correct kerning is done to get the actual width. The height returned in h is the same as you can get using TTF_FontHeight.
Return Value
Returns 0 on success with the ints pointed to by w and h set as appropriate, if they are not NULL. -1 is returned on errors, such as a glyph in the string not being found.
Note: Passing a NULL font into this function will cause a segfault. Passing a NULL text into this function will result in undefined behavior.
Example
// get the width and height of a string as it would be rendered in a loaded font
//TTF_Font *font;
int w,h;
if(TTF_SizeText(font,"Hello World!",&w,&h)) {
// perhaps print the current TTF_GetError(), the string can't be rendered...
} else {
printf("width=%d height=%d\n",w,h);
}
See Also
TTF_SizeUTF8, TTF_SizeUNICODE, TTF_RenderText_Solid, TTF_RenderText_Shaded, TTF_RenderText_Blended
