DrawFont. Register Synchronous
Create a custom font handle from font-file bytes. Assign the result to a Text drawing’s Font property to use that font. Use it to give a label a bundled font instead of a built-in font ID. Load the font bytes once, check for nil, and reuse the returned handle for matching labels.
DrawFont.Register(bytes: string, options: {PixelSize: number}) -> DrawFont?Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | string | Font file contents, for example readfile("fonts/interface.ttf"). |
options | {PixelSize: number} | Required table with PixelSize set to a positive, finite number. |
Returns
DrawFont?A DrawFont handle, or nil when the font data fails validation.
Usage notes
A missing or invalid PixelSize raises an error. A valid handle confirms the native font checks succeeded; rendering still depends on Android supporting the font.
Check the result before assigning it. Drawing.new("Font") is a separate font-resource API.
Differences from Volt
Volt describes loading font data while rebuilding a font atlas. Kawaii returns its handle synchronously after validating the input; registration alone does not establish that the Android renderer supports every feature of the font.
Example
local font = DrawFont.Register(readfile("fonts/interface.ttf"), { PixelSize = 18 })
if font then
local label = Drawing.new("Text")
label.Font = font
label.Text = "Custom font"
label.Size = 18
label.Position = Vector2.new(40, 40)
label.Transparency = 1
label.Visible = true
task.delay(5, function() label:Remove() end)
end