font1 new
Functions, messages and properties used to manipulate font resources.
Functions
font.add_font(fontc: string | Hash, font: string | Hash): voidfont.get_info(fontc: string | Hash):font.Infofont.prewarm_text(fontc: string | Hash, text: string, callback?: (self: unknown, request_id: number, result: boolean, errstring?: string) => void): numberfont.remove_font(fontc: string | Hash, font: string | Hash): voidfont.set_style(fontc: string | Hash, name: string, style: string): voidN
font.add_font(fontc: string | Hash, font: 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): font.Info
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 information
font.prewarm_text(fontc: string | Hash, text: string, callback?: (self: unknown, request_id: number, result: boolean, errstring?: string) => 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: number, result: boolean, errstring?: string) => 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, font: 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
font.set_style(fontc: string | Hash, name: string, style: string): voidN
- Since Defold 1.13.2
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 underlinelink: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.
font.set_style("/fonts/ui.fontc", "link:hover", "<color=#66b3ff><outline color=#000000 size=1><shake amplitude=0.2>");font.set_style("/fonts/ui.fontc", "link:hover",
"<color=#66b3ff><outline color=#000000 size=1><shake amplitude=0.2>")Parameters
fontc:string | Hash— The path to the.fontcresource.name:string— Style name, for examplelink:hover.style:string— Opening-only render-style markup.