SDL_ttf

SDL_ttf > Functions > Attributes

Name

TTF_SizeUTF8 -- Get size of UTF8 text string as would be rendered

Synopsis

#include "SDL.h"

int TTF_SizeUTF8(TTF_Font *font, const char *text, int *w, int *h)

Description

font

text

w

h

Calculate the resulting surface size of the UTF8 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

Note that this example uses the same text as in the LATIN1 example, that is because plain ASCII is UTF8 compatible.

// 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_SizeUTF8(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_SizeText, TTF_SizeUNICODE, TTF_RenderUTF8_Solid, TTF_RenderUTF8_Shaded, TTF_RenderUTF8_Blended

SDL_ttf_copy/Functions/Attributes/TTF_SizeUTF8 (last edited 2009-02-25 23:12:18 by sign-4d0949c8)