natiny.font.create
Lua
natiny.font.create(resource, size) -> font
Creates a font from loaded font data.
Parameters
| Name |
Type |
Description |
resource |
number |
Resource handle containing TrueType font data |
size |
number |
Font size in drawing units; values at or below 0 use 16 |
Returns
| Type |
Description |
number |
Font handle; raises an error if the font cannot be created |
Example
Lua
local res = natiny.resource.load("data/fonts/roboto.ttf")
local font = natiny.font.create(res, 24)
Notes
- Load
resource with natiny.resource.load. The font
copies its data, so the resource may be destroyed after this call.
- Text is decoded as UTF-8. Glyphs are cached in the font atlas on demand,
and unsupported code points use the font's missing-glyph symbol.
- In
natiny.window.SCALE_MODE_HIDPI, glyphs are rasterized at the display
scale while font metrics remain in drawing units.
- Changing a window's scale mode may rebuild live font atlases. The spacings,
the fallback and the filtering set on a font survive that rebuild.
- Destroy the handle with
natiny.font.destroy.