On this page
font
Functions, messages and properties used to manipulate font resources.
Functions
font.add_font(fontc: string | Hash, ttf: string | Hash)font.remove_font(fontc: string | Hash, ttf: string | Hash)font.prewarm_text(fontc: string | Hash, text: string, callback?: function(self, request_id, result, errstring)): numberfont.get_info(fontc: string | Hash): Record<string | number, unknown>
font.add_font(fontc: string | Hash, ttf: string | Hash)
associates a ttf 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);
Parameters
fontc:string | Hash— The path to the .fontc resourcettf:string | Hash— The path to the .ttf resource
font.remove_font(fontc: string | Hash, ttf: string | Hash)
associates a ttf 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);
Parameters
fontc:string | Hash— The path to the .fontc resourcettf:string | Hash— The path to the .ttf resource
font.prewarm_text(fontc: string | Hash, text: string, callback?: function(self, request_id, result, errstring)): number
prepopulates the font glyph cache with rasterised 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!
});
Parameters
fontc:string | Hash— The path to the .fontc resourcetext:string— The text to layoutcallback?:function(self, request_id, result, errstring)— (optional) A callback function that is called after the request is finished
self
object The current object.
request_id
number The request id
result
boolean True if request was succesful
errstring
string nil if the request was successful
Returns
request_id:number— Returns the asynchronous request id
font.get_info(fontc: string | Hash): Record<string | number, unknown>
Gets information about a font, such as the associated font files
Parameters
fontc:string | Hash— The path to the .fontc resource
Returns
info:Record<string | number, unknown>— the information table contains these fields:
path
hash The path hash of the current file.
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
path_hash
hash The path of the font file