Font

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.

API

font.add_font

Type: FUNCTION associates a TTF or OTF resource to a .fontc file.

Notes

Parameters

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)

font.file_info

Type: STRUCT Associated font file information

Members

font.get_info

Type: FUNCTION Gets information about a font, such as the associated font files

Parameters

Returns

font.info

Type: STRUCT Font resource information

Members

font.prewarm_text

Type: FUNCTION prepopulates the font glyph cache with rasterised glyphs

Parameters

self:script_instance

The current script instance.</dd>

request_id:integer

The request id</dd>

result:boolean

True if request was succesful</dd>

errstring:string

nil if the request was successful</dd> </dl>

Returns

  • request_id (integer) - Returns the asynchronous request id

Examples

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)

font.remove_font

Type: FUNCTION associates a TTF or OTF resource to a .fontc file

Notes

  • The reference count will decrease for the .ttf or .otf font

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)

font.set_style

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",
    "")