natiny.font.measure_text

Lua
natiny.font.measure_text(font, text) -> width, height

Returns the width and height of an unwrapped text block.

Parameters

Name Type Description
font number Font handle from natiny.font.create
text string UTF-8 text to measure

Returns

Type Description
number Width of the widest line in drawing units
number Height of the text block in drawing units

Example

Lua
local text = "Hello!"
local w, h = natiny.font.measure_text(font, text)

natiny.render.text(font, (800 - w) / 2, (600 - h) / 2, text)

Notes