ttfGetStringSizeWrapped function

bool ttfGetStringSizeWrapped(
  1. Pointer<TtfFont> font,
  2. String? text,
  3. int length,
  4. int wrapWidth,
  5. Pointer<Int32> w,
  6. Pointer<Int32> h,
)

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.

Text is wrapped to multiple lines on line endings and on word boundaries if it extends beyond wrap_width in pixels.

If wrap_width is 0, this function will only wrap on newline characters.

\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 wrap_width the maximum width or 0 to wrap on newline characters. \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_GetStringSizeWrapped(TTF_Font *font, const char *text, size_t length, int wrap_width, int *w, int *h)

Implementation

bool ttfGetStringSizeWrapped(Pointer<TtfFont> font, String? text, int length,
    int wrapWidth, Pointer<Int32> w, Pointer<Int32> h) {
  final ttfGetStringSizeWrappedLookupFunction = libSdl3Ttf.lookupFunction<
      Uint8 Function(Pointer<TtfFont> font, Pointer<Utf8> text, Uint32 length,
          Int32 wrapWidth, Pointer<Int32> w, Pointer<Int32> h),
      int Function(
          Pointer<TtfFont> font,
          Pointer<Utf8> text,
          int length,
          int wrapWidth,
          Pointer<Int32> w,
          Pointer<Int32> h)>('TTF_GetStringSizeWrapped');
  final textPointer = text != null ? text.toNativeUtf8() : nullptr;
  final result = ttfGetStringSizeWrappedLookupFunction(
          font, textPointer, length, wrapWidth, w, h) ==
      1;
  calloc.free(textPointer);
  return result;
}