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.
Luau
DrawFont:GetTextBounds(size: number, text: string) -> Vector2Parameters
Call this method with a DrawFont receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.
| Parameter | Type | Description |
|---|---|---|
size | number | Nonnegative font size in pixels. |
text | string | Text to estimate. |
Returns
Vector2A 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
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