ttfSizeText function

int ttfSizeText(
  1. Pointer<TtfFont> font,
  2. String? text,
  3. Pointer<Int32> w,
  4. Pointer<Int32> h,
)

Calculate the dimensions of a rendered string of Latin1 text.

This will report the width and height, in pixels, of the space that the specified string will take to fully render.

This does not need to render the string to do this calculation.

You almost certainly want TTF_SizeUTF8() unless you're sure you have a 1-byte Latin1 encoding. US ASCII characters will work with either function, but most other Unicode characters packed into a const char * will need UTF-8.

\param font the font to query. \param text text to calculate, in Latin1 encoding. \param w will be filled with width, in pixels, on return. \param h will be filled with height, in pixels, on return. \returns 0 if successful, -1 on error.

\since This function is available since SDL_ttf 2.0.12.

\sa TTF_SizeUTF8 \sa TTF_SizeUNICODE

extern DECLSPEC int SDLCALL TTF_SizeText(TTF_Font *font, const char *text, int *w, int *h)

Implementation

int ttfSizeText(
    Pointer<TtfFont> font, String? text, Pointer<Int32> w, Pointer<Int32> h) {
  final ttfSizeTextLookupFunction = libSdl2Ttf.lookupFunction<
      Int32 Function(Pointer<TtfFont> font, Pointer<Utf8> text,
          Pointer<Int32> w, Pointer<Int32> h),
      int Function(Pointer<TtfFont> font, Pointer<Utf8> text, Pointer<Int32> w,
          Pointer<Int32> h)>('TTF_SizeText');
  final textPointer = text != null ? text.toNativeUtf8() : nullptr;
  final result = ttfSizeTextLookupFunction(font, textPointer, w, h);
  calloc.free(textPointer);
  return result;
}