Skip to content

FontVariation

Inherits: Font < Resource < RefCounted < Object

A variation of a font with additional settings.

Provides OpenType variations, simulated bold / slant, and additional font settings like OpenType features and extra spacing.

To use simulated bold font variant:

var fv = new FontVariation();
fv.SetBaseFont(ResourceLoader.Load<FontFile>("res://BarlowCondensed-Regular.ttf"));
fv.SetVariationEmbolden(1.2);
GetEntity("Label").AddThemeFontOverride("font", fv);
GetEntity("Label").AddThemeFontSizeOverride("font_size", 64);

To set the coordinate of multiple variation axes:

Type Name Default
Font base_font
float baseline_offset 0.0
Dictionary opentype_features {}
PackedColorArray palette_custom_colors PackedColorArray()
int palette_index 0
int spacing_bottom 0
int spacing_glyph 0
int spacing_space 0
int spacing_top 0
float variation_embolden 0.0
int variation_face_index 0
Dictionary variation_opentype {}
Transform2D variation_transform Transform2D(1, 0, 0, 1, 0, 0)
Returns Method
void set_spacing(spacing: TextSystem.SpacingType, value: int)

base_font

Font base_font

Base font used to create a variation. If not set, default Theme font is used.

baseline_offset

float baseline_offset = 0.0

Extra baseline offset (as a fraction of font height).

opentype_features

Dictionary opentype_features = {}

A set of OpenType feature tags. More info: OpenType feature tags.

palette_custom_colors

PackedColorArray palette_custom_colors = PackedColorArray()

An array of colors to override predefined palette. Use Color(0, 0, 0, 0), to keep predefined palette color at specific position.

palette_index

int palette_index = 0

A palette index.

spacing_bottom

int spacing_bottom = 0

Extra spacing at the bottom of the line in pixels.

spacing_glyph

int spacing_glyph = 0

Extra spacing between graphical glyphs.

spacing_space

int spacing_space = 0

Extra width of the space glyphs.

spacing_top

int spacing_top = 0

Extra spacing at the top of the line in pixels.

variation_embolden

float variation_embolden = 0.0

If is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.

Note: Emboldened fonts might have self-intersecting outlines, which will prevent MSDF fonts and TextMesh from working correctly.

variation_face_index

int variation_face_index = 0

Active face index in the TrueType / OpenType collection file.

variation_opentype

Dictionary variation_opentype = {}

Font OpenType variation coordinates. More info: OpenType variation tags.

Note: This Dictionary uses OpenType tags as keys. Variation axes can be identified both by tags (int, e.g. 0x77678674) and names (String, e.g. wght). Some axes might be accessible by multiple names. For example, wght refers to the same axis as weight. Tags on the other hand are unique. To convert between names and tags, use TextSystem.name_to_tag() and TextSystem.tag_to_name().

Note: To get available variation axes of a font, use Font.get_supported_variation_list().

variation_transform

Transform2D variation_transform = Transform2D(1, 0, 0, 1, 0, 0)

2D transform, applied to the font outlines, can be used for slanting, flipping and rotating glyphs.

For example, to simulate italic typeface by slanting, apply the following transform Transform2D(1.0, slant, 0.0, 1.0, 0.0, 0.0).

set_spacing

void set_spacing(spacing: TextSystem.SpacingType, value: int)

Sets the spacing for spacing to value in pixels (not relative to the font size).