natiny_font_measure_text

C
void natiny_font_measure_text(NatinyFont font, const char* text,
                              float* width, float* height);

Writes the width and height of an unwrapped text block to optional output pointers.

Parameters

Name Type Description
font NatinyFont Font handle from natiny_font_create
text const char* Null-terminated UTF-8 text
width float* Receives the widest-line width in drawing units; may be NULL
height float* Receives the block height in drawing units; may be NULL

Example

C
float width = 0.0f;
float height = 0.0f;

natiny_font_measure_text(font, "Hello!", &width, &height);
natiny_render_text(font,
                   (800.0f - width) * 0.5f,
                   (600.0f - height) * 0.5f,
                   "Hello!");

Notes

  • \n starts a new line; the widest line determines the result.
  • Use natiny_font_measure_wrapped to add word wrapping.
  • Kerning, tab stops, letter spacing, and line spacing match natiny_render_text.
  • An empty string measures 0.0f wide and one line tall. Invalid handles or NULL text produce zero width and height.