DrawFont: GetTextBounds Synchronous
Estimate the space a text string needs at a requested font size. Use the estimate to reserve space for a label before drawing it. Leave margin for the actual font because this implementation does not measure individual glyphs.
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 | Non-negative font size in pixels. |
text | string | String whose approximate bounds are needed. |
Returns
Vector2A Vector2 containing estimated width and height. An empty string returns zero height.
Usage notes
The current implementation estimates width from the character count and font size. It does not measure the registered font’s glyphs, kerning, or line breaks; allow extra space when laying out text.
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
-- Put a valid font file at this workspace path first.
local font = DrawFont.Register(readfile("fonts/example.ttf"), { PixelSize = 18 })
if font then
local bounds = font:GetTextBounds(18, "Preview")
print("Estimated width:", bounds.X, "height:", bounds.Y)
end