Skip to Content
defold-typescript
Get startedGuidesAPILibraries
Defold

font

Functions, messages and properties used to manipulate font resources.

Functions

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 resource
  • font: 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 resource
  • text: string — The text to layout
  • callback?: (self: unknown, request_id: unknown, result: unknown, errstring: unknown) => void — (optional) A callback function that is called after the request is finished self script_instance The current script instance. request_id integer 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.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 resource
  • font: string | Hash — The path to the .ttf or .otf resource

On this page