DynamicFont renders vector font files dynamically at runtime instead of using a prerendered texture atlas like godot.BitmapFont
. This trades the faster loading time of godot.BitmapFont
s for the ability to change font parameters like size and spacing during runtime. godot.DynamicFontData
is used for referencing the font file paths. DynamicFont also supports defining one or more fallback fonts, which will be used when displaying a character not supported by the main font.
DynamicFont uses the [https://www.freetype.org/](FreeType) library for rasterization. Supported formats are TrueType (.ttf
), OpenType (.otf
) and Web Open Font Format 1 (.woff
). Web Open Font Format 2 (.woff2
) is not supported.
var dynamic_font = DynamicFont.new()
dynamic_font.font_data = load("res://BarlowCondensed-Bold.ttf")
dynamic_font.size = 64
$"Label".set("custom_fonts/font", dynamic_font)
Note: DynamicFont doesn't support features such as kerning, right-to-left typesetting, ligatures, text shaping, variable fonts and optional font features yet. If you wish to "bake" an optional font feature into a TTF font file, you can use [https://fontforge.org/](FontForge) to do so. In FontForge, use File > Generate Fonts, click Options, choose the desired features then generate the font.
Constructor
Variables
extraSpacingChar:Int
Extra spacing for each character in pixels.
This can be a negative number to make the distance between characters smaller.
extraSpacingSpace:Int
Extra spacing for the space character (in addition to godot.DynamicFont.extraSpacingChar
) in pixels.
This can be a negative number to make the distance between words smaller.
outlineColor:Color
The font outline's color.
Note: It's recommended to leave this at the default value so that you can adjust it in individual controls. For example, if the outline is made black here, it won't be possible to change its color using a Label's font outline modulate theme item.
useFilter:Bool
If true
, filtering is used. This makes the font blurry instead of pixelated when scaling it if font oversampling is disabled or ineffective. It's recommended to enable this when using the font in a control whose size changes over time, unless a pixel art aesthetic is desired.
useMipmaps:Bool
If true
, mipmapping is used. This improves the font's appearance when downscaling it if font oversampling is disabled or ineffective.
Methods
getAvailableChars():String
Returns a string containing all the characters available in the main and all the fallback fonts.
If a given character is included in more than one font, it appears only once in the returned string.
setSpacing(type:Int, value:Int):Void
Sets the spacing for type
(see godot.DynamicFont_SpacingType
) to value
in pixels (not relative to the font size).