Skip to main content

Font

Description:

  Defines the shape of characters that can be drawn onto the screen.

release

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: Font): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

type

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: Font): string

Returns:

Return TypeDescription
stringThe type as a string.

Of

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: Font, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

getWidth

Type: Function.

Description:

  Determines the maximum width (accounting for newlines) taken by the given string.

Signature:

getWidth: function(self: Font, text: string): number

Parameters:

ParameterTypeDescription
textstringA string.

Returns:

Return TypeDescription
numberThe width of the text.

getHeight

Type: Function.

Description:

  Gets the height of the Font. The height of the font is the size including any spacing; the height which it will need.

Signature:

getHeight: function(self: Font): number

Returns:

Return TypeDescription
numberThe height of the Font in pixels.

getBaseline

Type: Function.

Description:

  Gets the baseline of the Font. Most scripts share the notion of a baseline: an imaginary horizontal line on which characters rest. In some scripts, parts of glyphs lie below the baseline.

Signature:

getBaseline: function(self: Font): number

Returns:

Return TypeDescription
numberThe baseline of the Font in pixels.

getAscent

Type: Function.

Description:

  Gets the ascent of the Font. The ascent spans the distance between the baseline and the top of the glyph that reaches farthest from the baseline.

Signature:

getAscent: function(self: Font): number

Returns:

Return TypeDescription
numberThe ascent of the Font in pixels.

getDescent

Type: Function.

Description:

  Gets the descent of the Font. The descent spans the distance between the baseline and the lowest descending glyph in a typeface.

Signature:

getDescent: function(self: Font): number

Returns:

Return TypeDescription
numberThe descent of the Font in pixels.

hasGlyphs

Type: Function.

Description:

  Gets whether the Font can render a character or string.

Signature:

hasGlyphs: function(self: Font, text_or_codepoint: string | integer, ...: string | integer): boolean

Parameters:

ParameterTypeDescription
text_or_codepointstring or integerA UTF-8 encoded unicode string.
...string or integerThe ... parameter.

Returns:

Return TypeDescription
booleanWhether the font can render all the UTF-8 characters in the string. Depending on the overload: Whether the font can render all the glyphs represented by the characters. Depending on the overload: Whether the font can render all the glyphs represented by the codepoint numbers.

getKerning

Type: Function.

Description:

  Gets the kerning between two characters in the Font. Kerning is normally handled automatically in love.graphics.print, Text objects, Font:getWidth, Font:getWrap, etc. This function is useful when stitching text together manually.

Signature:

getKerning: function(self: Font, left: string | integer, right: string | integer): number

Parameters:

ParameterTypeDescription
leftstring or integerThe left character. Depending on the overload: The unicode number for the left glyph.
rightstring or integerThe right character. Depending on the overload: The unicode number for the right glyph.

Returns:

Return TypeDescription
numberThe kerning amount to add to the spacing between the two characters. May be negative.

setFallbacks

Type: Function.

Description:

  Sets the fallback fonts. When the Font doesn't contain a glyph, it will substitute the glyph from the next subsequent fallback Fonts. This is akin to setting a 'font stack' in Cascading Style Sheets (CSS). Overload details:

  1. If this is called it should be before love.graphics.print, Font:getWrap, and other Font methods which use glyph positioning information are called. Every fallback Font must be created from the same file type as the primary Font. For example, a Font created from a .ttf file can only use fallback Fonts that were created from .ttf files.

Signature:

setFallbacks: function(self: Font, ...: Font)

Parameters:

ParameterTypeDescription
...FontThe ... parameter.

setLineHeight

Type: Function.

Description:

  Sets the line height. When rendering the font in lines the actual height will be determined by the line height multiplied by the height of the font. The default is 1.0.

Signature:

setLineHeight: function(self: Font, height: number)

Parameters:

ParameterTypeDescription
heightnumberThe new line height.

getLineHeight

Type: Function.

Description:

  Gets the line height. This will be the value previously set by Font:setLineHeight, or 1.0 by default.

Signature:

getLineHeight: function(self: Font): number

Returns:

Return TypeDescription
numberThe current line height.

getDPIScale

Type: Function.

Description:

  Gets the DPI scale factor of the Font. The DPI scale factor represents relative pixel density. A DPI scale factor of 2 means the font's glyphs have twice the pixel density in each dimension (4 times as many pixels in the same area) compared to a font with a DPI scale factor of 1. The font size of TrueType fonts is scaled internally by the font's specified DPI scale factor. By default, LÖVE uses the screen's DPI scale factor when creating TrueType fonts.

Signature:

getDPIScale: function(self: Font): number

Returns:

Return TypeDescription
numberThe DPI scale factor of the Font.

getFilter

Type: Function.

Description:

  Gets the filter mode for a font.

Signature:

getFilter: function(self: Font): string, string, number

Returns:

Return TypeDescription
stringFilter mode used when minifying the font.
stringFilter mode used when magnifying the font.
numberMaximum amount of anisotropic filtering used.

setFilter

Type: Function.

Description:

  Sets the filter mode for a font.

Signature:

setFilter: function(self: Font, min: string, mag?: string, anisotropy?: number)

Parameters:

ParameterTypeDescription
minstringHow to scale a font down.
magstringHow to scale a font up.
anisotropynumberMaximum amount of anisotropic filtering used. (Default: 1.)

getWrap

Type: Function.

Description:

  Gets formatting information for text, given a wrap limit. This function accounts for newlines correctly (i.e. '\n').

Signature:

getWrap: function(self: Font, text: string, wrap_limit: number): number, {string}

Parameters:

ParameterTypeDescription
textstringThe text that will be wrapped.
wrap_limitnumberThe maximum width in pixels of each line that ''text'' is allowed before wrapping.

Returns:

Return TypeDescription
numberThe maximum width of the wrapped text.
{string}A sequence containing each line of text that was wrapped.