DrawFont:GetTextBounds Synchronous

Estimate the space needed for a string at a chosen size. It can help reserve a label area before drawing, but leave some margin around the result.

Syntax
Luau
DrawFont:GetTextBounds(size: number, text: string) -> Vector2

Parameters

Call this method with a DrawFont receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.

Function parameters
ParameterTypeDescription
sizenumberNonnegative font size in pixels.
textstringText to estimate.

Returns

Vector2

A Vector2 with estimated width and height; empty text has zero height.

Usage notes

This calculation uses character count and size. It does not measure glyph widths, kerning, or multiple rendered lines.

Differences from Volt

Volt presents this as font measurement. Kawaii currently estimates width from character count and requested size, with a size-based height; it does not measure glyph shapes, kerning, or multiline layout.

Example

Example
Luau
if isfile("fonts/interface.ttf") then
    local font = DrawFont.Register(readfile("fonts/interface.ttf"), { PixelSize = 18 })
    if font then
        local bounds = font:GetTextBounds(18, "Preview")
        print(bounds.X, bounds.Y)
    end
end
Kawaii documentation