defold (official)
defold/extension-fontgen/fontgen
Functions to generate glyphs for fonts at runtime.
- GitHub: defold/extension-fontgen — pinned to
0.9(released while Defold 1.10.1 was current)- Pick a release from defold/extension-fontgen releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as fontgen from "fontgen"
- Pick a release from defold/extension-fontgen releases and add its Source code (zip) URL (or a packaged
Functions
fontgen.load_font(fontc_path: string, ttf_path: string, options: table, complete_function: function)
Creates a mapping between a .fontc file and a .ttf file. Increases the ref count for both resources.
Parameters
fontc_path:string— Path to a .fontc file in the projectttf_path:string— Path to a .ttf file in the projectoptions:table— Options for generating the glyphssdf_padding:number— The number of padding pixels [0-255]sdf_edge:number— Where the edge is decided to be [0-255]
complete_function:function— function to call when the animation has completedself:object— The context of the calling scriptfontc_hash:hash— The path hash of the .fontc resource
fontgen.unload_font(fontc_path_hash: hash)
Removes the generator mapping between the .fontc and .ttf file. Decreases the ref count for both resources. Does not remove the previously generated glyphs!
Parameters
fontc_path_hash:hash— Path hash of the .fontc file in the project
fontgen.add_glyphs(fontc_path_hash: hash, text: string, callback: function): integer
Asynchronoously sdds glyphs to the .fontc resource.
Parameters
fontc_path_hash:hash— Path hash of the .fontc file in the projecttext:string— Utf-8 string containing glyphs to add to the .fontc Note No checks for duplicate glyphs is done.callback:function— Function to be called after the last glyph was processed. May be nil.self:object— The script instance that calledadd_glyphsrequest:int— The request id returned byadd_glyphsresult:bool— True if all glyphs were added successfullyerrmsg:string— Error string if a glyph wasn't generated or added successfully
Returns
integer— Returns a request id, used in the callback
fontgen.remove_glyphs(fontc_path_hash: hash, text: string)
Removes glyphs from the .fontc resource
Parameters
fontc_path_hash:hash— Path hash of the .fontc file in the projecttext:string— Utf-8 string containing glyphs to remove from the .fontc