ttfxGetTextSubStringsForRange function ttf

List<TtfxSubString> ttfxGetTextSubStringsForRange(
  1. Pointer<TtfText> text,
  2. int offset,
  3. int length
)

Get the substrings of a text object that contain a range of text.

\param text the TTF_Text to query. \param offset a byte offset into the text string. \param length the length of the range being queried, in bytes, or -1 for the remainder of the string. \param count a pointer filled in with the number of substrings returned, may be NULL. \returns a NULL terminated array of substring pointers or NULL on failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.

\threadsafety This function should be called on the thread that created the text.

\since This function is available since SDL_ttf 3.0.0.

extern SDL_DECLSPEC TTF_SubString ** SDLCALL TTF_GetTextSubStringsForRange(TTF_Text *text, int offset, int length, int *count)

Implementation

List<TtfxSubString> ttfxGetTextSubStringsForRange(
  Pointer<TtfText> text,
  int offset,
  int length,
) {
  final result = <TtfxSubString>[];
  final countPointer = ffi.calloc<Int32>();
  final subStringsPointer = ttfGetTextSubStringsForRange(
    text,
    offset,
    length,
    countPointer,
  );
  if (subStringsPointer != nullptr) {
    for (var i = 0; i < countPointer.value; i++) {
      result.add(TtfxSubString()..loadFromPointer(subStringsPointer[i]));
    }
    sdlFree(subStringsPointer.cast<Void>());
  }
  countPointer.callocFree();
  return result;
}