natiny_font_measure_wrapped

C
void natiny_font_measure_wrapped(NatinyFont font, const char* text,
                                 float max_width, float* width,
                                 float* height, uint32_t* lines);

Lays text out and reports the size of the block it makes, without drawing it.

Parameters

Name Type Description
font NatinyFont Font handle from natiny_font_create
text const char* Null-terminated UTF-8 text
max_width float Wrap width in drawing units; values at or below 0.0f do not wrap
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
lines uint32_t* Receives the line count; may be NULL

Example

C
float    w = 0.0f, h = 0.0f;
uint32_t lines = 0;

natiny_font_measure_wrapped(font, message, 300.0f, &w, &h, &lines);
natiny_render_rectangle(20.0f, 20.0f, w + 16.0f, h + 16.0f);

Notes

  • Lines break at spaces and tabs, at \n, and between Han, kana and Hangul characters, which are written without spaces. A word longer than max_width is cut where it stops fitting rather than allowed to overflow.