Namespace: font
Language: Lua
Type: Defold Lua
File: script_font.cpp
Source: engine/gamesys/src/gamesys/scripts/script_font.cpp
Functions, messages and properties used to manipulate font resources.
Type: FUNCTION associates a TTF or OTF resource to a .fontc file.
Notes
Parameters
fontc (string |
hash) - The path to the .fontc resource |
font (string |
hash) - The path to the .ttf or .otf resource |
Examples
local font_hash = hash("/assets/fonts/roboto.fontc")
local ttf_hash = hash("/assets/fonts/Roboto/Roboto-Bold.ttf")
font.add_font(font_hash, ttf_hash)
Type: STRUCT Associated font file information
Members
path (string) - path to the .ttf or .otf font filepath_hash (hash) - hashed font-file pathType: FUNCTION Gets information about a font, such as the associated font files
Parameters
fontc (string |
hash) - The path to the .fontc resource |
Returns
info (font.info) - font resource informationType: STRUCT Font resource information
Members
path (hash) - path hash of the .fontc resourcefonts (font.file_info[]) - associated font filesType: FUNCTION prepopulates the font glyph cache with rasterised glyphs
Parameters
fontc (string |
hash) - The path to the .fontc resource |
text (string) - The text to layoutcallback (fun(self:script_instance, request_id:integer, result:boolean, errstring?:string)) (optional) - (optional) A callback function that is called after the request is finishedself:script_instanceThe current script instance.</dd>
request_id:integerThe request id</dd>
result:booleanTrue if request was succesful</dd>
errstring:stringnil if the request was successful</dd>
</dl>
Returns
request_id (integer) - Returns the asynchronous request idExamples
local font_hash = hash("/assets/fonts/roboto.fontc")
font.prewarm_text(font_hash, "Some text", function (self, request_id, result, errstring)
-- cache is warm, show the text!
end)
Type: FUNCTION associates a TTF or OTF resource to a .fontc file
Notes
Parameters
fontc (string |
hash) - The path to the .fontc resource |
font (string |
hash) - The path to the .ttf or .otf resource |
Examples
local font_hash = hash("/assets/fonts/roboto.fontc")
local ttf_hash = hash("/assets/fonts/Roboto/Roboto-Bold.ttf")
font.remove_font(font_hash, ttf_hash)
Type: FUNCTION Named object styles are resolved by text layouts without reshaping text. A link tag uses link by default. Callers may select another named style, such as link:hover or link:active, in response to input. Font collections initially define these named styles. Each default contains a normalized RGBA face color and no effects. Style RGB overrides the base text color, while alpha uses the lower of the style and base text alpha. Gradients override RGB and use the lower alpha in the same way. Inline colors and gradients take precedence over object styles, which take precedence over the named base style. Nested color or gradient tags override enclosing RGB in inline markup and named style definitions. The default link style also uses a solid underline, which remains when hover or active colors are applied:
link: (0.10, 0.45, 0.90, 1.0), solid underline link:hover: (0.30, 0.65, 1.00, 1.0) link:active: (0.05, 0.30, 0.70, 1.0)
The definition is an opening-only sequence of rich-text tags. Tags are implicitly closed in reverse order. Calling this function replaces the named render properties and effects. Resource-defined decorations, such as the default link underline, remain unchanged.
Parameters
fontc (string |
hash) - The path to the .fontc resource. |
name (string) - Style name, for example link:hover.style (string) - Opening-only render-style markup.Examples
font.set_style("/fonts/ui.fontc", "link:hover",
"")