Skip to main content
Version: 9.0.2

gre.get_string_size

gre.get_string_size(
font,
font_size,
str,
width,
data
)

Calculate the area in pixels which the given string will occupy on the screen.

This call can only be made from the main Lua action execution thread.

Parameters

ParameterTypeDescription
font#stringThe name of the font to render
font_size#numberThe size of the font to render
str#stringThe string to render
width#numberA clipping width (in pixels) for the string, used to calculate how many characters fit
data#tableA table containing additional options. Valid

Set String Size Options

KeyTypeDescription
length#numberThe number of characters to process.
spacing#numberThe letter spacing text render extension property.
wrapping#booleanA boolean to activate wrapping logic

Returns

A #table with the following:

KeyTypeDescription
width#numberThe width of the widest line in the body of text.
height#numberThe total height of the wrapped text in pixels.
n_lines#numberThe number of lines the text fills when wrapped.

Example

local t = gre.get_string_size('fonts/Roboto-ThinItalic.ttf', 72, 'How long is this string?', 600, {["wrapping"] = true} )