Font
This object represents a font resource loaded in memory.
Actual text is rendered on the screen using the canvas.
The font object can load .ttf fonts from file or pre-installed fonts from the user's system.
Figure 1: Font measurement functions
Constructors
- Font ( [font, size] )
Creates a new font object.
If the optional font and size parameters are supplied, it attempts to load the font.
Functions
- get_height ( )
Returns the loaded font's height from ascenders to descenders, in pixels
- get_size ( )
Returns the loaded font's size (cap height), in pixels
- get_width ( text )
Calculates and returns the width of a supplied string of characters, in pixels
- load_bmfont ( filename, size )
Loads a bitmap font. Bitmap fonts are in the .fnt format and include externally exported .png textures.
Returns true if successful or false otherwise
- load_file ( filename, size )
Loads a TrueType font from a supplied filename and size in pixels.
Returns true if successful or false otherwise
- load_file_codes ( filename, size, codes )
Loads a TrueType font from a supplied filename and size in pixels.
The codes parameter is a table list of UTF8 character codes.
Returns true if successful or false otherwise
- load_system ( fontname, size )
Loads a font installed on the user's system from a supplied typeface name and size in pixels.
Returns true if successful or false otherwise
- load_system_codes ( fontname, size, codes )
Loads a font installed on the user's system from a supplied typeface name and size in pixels.
The codes parameter is a table list of UTF8 character codes.
Returns true if successful or false otherwise
- unload ( )
Unloads an unused font releasing all relevant memory.
Returns true if successful or false otherwise