ttfGetStringSize function
Calculate the dimensions of a rendered string of UTF-8 text.
This will report the width and height, in pixels, of the space that the specified string will take to fully render.
\param font the font to query. \param text text to calculate, in UTF-8 encoding. \param length the length of the text, in bytes, or 0 for null terminated text. \param w will be filled with width, in pixels, on return. \param h will be filled with height, in pixels, on return. \returns true on success or false on failure; call SDL_GetError() for more information.
\threadsafety This function should be called on the thread that created the font.
\since This function is available since SDL_ttf 3.0.0.
extern SDL_DECLSPEC bool SDLCALL TTF_GetStringSize(TTF_Font *font, const char *text, size_t length, int *w, int *h)
Implementation
bool ttfGetStringSize(Pointer<TtfFont> font, String? text, int length,
Pointer<Int32> w, Pointer<Int32> h) {
final ttfGetStringSizeLookupFunction = libSdl3Ttf.lookupFunction<
Uint8 Function(Pointer<TtfFont> font, Pointer<Utf8> text, Uint32 length,
Pointer<Int32> w, Pointer<Int32> h),
int Function(Pointer<TtfFont> font, Pointer<Utf8> text, int length,
Pointer<Int32> w, Pointer<Int32> h)>('TTF_GetStringSize');
final textPointer = text != null ? text.toNativeUtf8() : nullptr;
final result =
ttfGetStringSizeLookupFunction(font, textPointer, length, w, h) == 1;
calloc.free(textPointer);
return result;
}