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 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.get_info

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

Parameters

Returns

path

hash The path hash of the current file.</dd>

fonts

table An array of associated font (e.g. .ttf) files. Each item is a table that contains:

path

string The path of the font file</dd>

path_hash

hash The path of the font file</dd> </dl>

</dl>

font.prewarm_text

Type: FUNCTION prepopulates the font glyph cache with rasterised glyphs

Parameters

  • fontc (string hash) - The path to the .fontc resource
  • text (string) - The text to layout
  • callback (function(self, request_id, result, errstring)) (optional) - (optional) A callback function that is called after the request is finished
self

object The current object.</dd>

request_id

number 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 (number) - 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 resource to a .fontc file

Notes

  • The reference count will decrease for the .ttf font

Parameters

  • fontc (string hash) - The path to the .fontc resource
  • ttf (string hash) - The path to the .ttf 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)