DrawFont
Registers and measures fonts used by Drawing text APIs.
Syntax
DrawFont.Register(data: string, options: DrawFontOptions) -> DrawFont?
font:GetTextBounds(size: number, text: string) -> Vector2DrawFontOptions
| Field | Type | Description |
|---|---|---|
PixelSize | number | Required rasterization size |
Glyphs | {{number}}? | Optional nested arrays of Unicode code points to include |
Description
DrawFont.Register loads font bytes from memory and yields while rebuilding the font atlas. It returns nil if the font data is invalid. A DrawFont is read-only and exposes only GetTextBounds.
Example
local fontData = readfile("fonts/example.ttf")
local font = assert(DrawFont.Register(fontData, {
PixelSize = 18,
Glyphs = {
{32, 33, 34, 35},
{65, 66, 67, 68},
},
}), "Font data was invalid")
local bounds = font:GetTextBounds(18, "ABCD")
print(bounds.X, bounds.Y)
local text = Drawing.new("Text")
text.Font = font
text.Size = 18
text.Text = "ABCD"
text.Visible = true