---
name: "TTF_MeasureString"
section: "3"
platform: "linux"
package: "libsdl3-ttf-doc"
version: "3.2.2+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/TTF_MeasureString"
---

# TTF\_MeasureString(3)

Calculate how much of a UTF-8 string will fit in a given width.

## NAME

TTF\_MeasureString - Calculate how much of a UTF-8 string will fit in a given width.

## HEADER FILE

Defined in SDL3\_ttf/SDL\_ttf.h

## SYNOPSIS

```
#include "SDL3_ttf/SDL_ttf.h"
```

**bool TTF\_MeasureString(TTF\_Font \*font, const char \*text, size\_t length, int max\_width, int \*measured\_width, size\_t \*measured\_length);**

## DESCRIPTION

This reports the number of characters that can be rendered before reaching **max\_width** .

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

## FUNCTION PARAMETERS

- *font*

  the font to query.

- *text*

  text to calculate, in UTF-8 encoding.

- *length*

  the length of the text, in bytes, or 0 for null terminated text.

- *max\_width*

  maximum width, in pixels, available for the string, or 0 for unbounded width.

- *measured\_width*

  a pointer filled in with the width, in pixels, of the string that will fit, may be NULL.

- *measured\_length*

  a pointer filled in with the length, in bytes, of the string that will fit, may be NULL.

## RETURN VALUE

Returns true on success or false on failure; call SDL\_GetError() for more information.

## THREAD SAFETY

This function should be called on the thread that created the font.

## AVAILABILITY

This function is available since SDL\_ttf 3.0.0.
