Defold
font
Functions, messages and properties used to manipulate font resources.
Functions
font.add_font(fontc: string | Hash, ttf: string | Hash): voidfont.get_info(fontc: string | Hash): { path: Hash; fonts: { path: string; path_hash: Hash }[] }font.prewarm_text(fontc: string | Hash, text: string, callback?: (self: unknown, request_id: unknown, result: unknown, errstring: unknown) => void): numberfont.remove_font(fontc: string | Hash, ttf: string | Hash): void
font.add_font(fontc: string | Hash, ttf: string | Hash): void
associates a TTF or OTF resource to a .fontc file.
const font_hash = hash("/assets/fonts/roboto.fontc");
const ttf_hash = hash("/assets/fonts/Roboto/Roboto-Bold.ttf");
font.add_font(font_hash, ttf_hash);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)Parameters
fontc:string | Hash— The path to the .fontc resourcefont:string | Hash— The path to the .ttf or .otf resource
font.get_info(fontc: string | Hash): { path: Hash; fonts: { path: string; path_hash: Hash }[] }
Gets information about a font, such as the associated font files
Parameters
fontc:string | Hash— The path to the .fontc resource
Returns
info:{ path: Hash; fonts: { path: string; path_hash: Hash }[] }— font resource information
font.prewarm_text(fontc: string | Hash, text: string, callback?: (self: unknown, request_id: unknown, result: unknown, errstring: unknown) => void): number
prepopulates the font glyph cache with generated glyphs
const font_hash = hash("/assets/fonts/roboto.fontc");
font.prewarm_text(font_hash, "Some text", (self, request_id, result, errstring) => {
// cache is warm, show the text!
});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)Parameters
fontc:string | Hash— The path to the .fontc resourcetext:string— The text to layoutcallback?:(self: unknown, request_id: unknown, result: unknown, errstring: unknown) => void— (optional) A callback function that is called after the request is finishedselfscript_instance The current script instance.request_idinteger The request idresultboolean True if request was succesfulerrstringstringnilif the request was successful
Returns
request_id:number— Returns the asynchronous request id
font.remove_font(fontc: string | Hash, ttf: string | Hash): void
associates a TTF or OTF resource to a .fontc file
const font_hash = hash("/assets/fonts/roboto.fontc");
const ttf_hash = hash("/assets/fonts/Roboto/Roboto-Bold.ttf");
font.remove_font(font_hash, ttf_hash);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)Parameters
fontc:string | Hash— The path to the .fontc resourcefont:string | Hash— The path to the .ttf or .otf resource