This function is used to retrieve information for the given font. You supply a font index (which can be an asset added through the Asset Browser or a font added at runtime) and the function returns a struct with the following variables:


Variable Name Data Type Description
ascenderOffset real The maximum offset from the baseline to the top of the font (in pixels)
size real The approximate size of the font (in pixels)
spriteIndex asset (real) The sprite index for the font if it was created from a sprite, otherwise -1
texture asset (real) -1 if the font was created from a sprite, otherwise the texture ID of the font
name string The name of the font
bold boolean true if the font is bold, otherwise false (see NOTE below)
italic boolean true if the font is italic, otherwise false (see NOTE below)
glyphs struct A struct containing information for each glyph in the font (more information is given below)

NOTE: The bold and italic variables only reflect the user's settings for the font, so they may not be accurate for fonts that are bold or italic by default.

If the supplied font doesn't exist, the function will return undefined.

Also note that changing the values of any of these variables, or any variables contained within the glyphs struct, will not change how the font is rendered, so this information should be considered read-only.

Glyphs Struct

The glyphs variable in the returned struct will be a struct on its own, containing information for each glyph included in the font. Each variable in this struct will be a glyph's character name, which will hold a struct containing information for that glyph. You can imagine these nested structs in the following format (starting from the main struct):

        A: {},
        B: {},
        C: {},
        // ...other glyphs
    // ...other font info

You can use a glyph's character name to retrieve its information from the struct, such as in the following code:

var _font_info = font_get_info(Font1);

var _info_A = _font_info.glyphs[$ "A"]; // $ is a struct accessor


The code above gets the glyph struct for the "A" character and prints it to the output log. You can also replace the string ("A") with a variable that holds a string, which will allow you to get information for any glyph through that variable at runtime.

The struct returned for a glyph will contain the following variables:

NOTE: On HTML5, the glyphs struct will be empty for any loaded file fonts (such as *.ttf or *.otf) as the runtime will not have information on those glyphs.

Variable Name Data Type Description
char real If the font was created from a sprite, this will be the image index of the glyph from that sprite, otherwise it will be its Unicode character number

Note: All variables below this will not be present in the struct if the font was created from a sprite
x real The X position of the glyph on the texture page (in texels)
y real The Y position of the glyph on the texture page (in texels)
w real The width of the glyph on the texture page (in texels)
h real The height of the glyph on the texture page (in texels)
shift real The number of pixels to shift right when advancing to the next character (can be negative for shifting left)
offset real The number of pixels to horizontally offset the rendering of this glyph (can be positive or negative)
kerning array An array of integers containing kerning information in pairs (or groups of 2). The first integer in a pair is the Unicode value for a character, and the second integer is the amount to add to that character's shift value (can be positive or negative) if it is preceeded by this glyph's character.

NOTE: For file fonts loaded at runtime, the x and y values for a glyph may be -1 if it hasn't been rendered yet, as it will have no position on the texture page used for caching.




Argument Description
font The font for which information should be retrieved.



Struct (or undefined)



var _info = font_get_info(my_font);

if (_info != undefined && _info.bold)
    image_xscale *= 2;
    image_yscale *= 2;

This code retrieves information for the font stored in the my_font variable. If the returned value is not undefined and the given font is bold, the instance's scale is doubled.