DynamicFont

Inherits: Font < Resource < Reference < Object

DynamicFont renders vector font files at runtime.

Description

DynamicFont renders vector font files (such as TTF or OTF) dynamically at runtime instead of using a prerendered texture atlas like BitmapFont. This trades the faster loading time of BitmapFonts for the ability to change font parameters like size and spacing during runtime. DynamicFontData is used for referencing the font file paths. DynamicFont also supports defining one or more fallbacks fonts, which will be used when displaying a character not supported by the main font.

DynamicFont uses the FreeType library for rasterization.

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)

Methods

voidadd_fallback ( DynamicFontData data )
DynamicFontDataget_fallback ( int idx ) const
intget_fallback_count ( ) const
intget_spacing ( int type ) const
voidremove_fallback ( int idx )
voidset_fallback ( int idx, DynamicFontData data )
voidset_spacing ( int type, int value )

Enumerations

enum SpacingType:

  • SPACING_TOP = 0 — Spacing at the top.
  • SPACING_BOTTOM = 1 — Spacing at the bottom.
  • SPACING_CHAR = 2 — Character spacing.
  • SPACING_SPACE = 3 — Space spacing.

Property Descriptions

  • int extra_spacing_bottom
Default0
Setterset_spacing(value)
Getterget_spacing()

Extra spacing at the bottom in pixels.


  • int extra_spacing_char
Default0
Setterset_spacing(value)
Getterget_spacing()

Extra character spacing in pixels.


  • int extra_spacing_space
Default0
Setterset_spacing(value)
Getterget_spacing()

Extra space spacing in pixels.


  • int extra_spacing_top
Default0
Setterset_spacing(value)
Getterget_spacing()

Extra spacing at the top in pixels.


Setterset_font_data(value)
Getterget_font_data()

The font data.


DefaultColor( 1, 1, 1, 1 )
Setterset_outline_color(value)
Getterget_outline_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.


  • int outline_size
Default0
Setterset_outline_size(value)
Getterget_outline_size()

The font outline’s thickness in pixels (not relative to the font size).


Default16
Setterset_size(value)
Getterget_size()

The font size in pixels.


Defaultfalse
Setterset_use_filter(value)
Getterget_use_filter()

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.


Defaultfalse
Setterset_use_mipmaps(value)
Getterget_use_mipmaps()

If true, mipmapping is used. This improves the font’s appearance when downscaling it if font oversampling is disabled or ineffective.

Method Descriptions

Adds a fallback font.


Returns the fallback font at index idx.


  • int get_fallback_count ( ) const

Returns the number of fallback fonts.


  • int get_spacing ( int type ) const

Returns the spacing for the given type (see SpacingType).


  • void remove_fallback ( int idx )

Removes the fallback font at index idx.


Sets the fallback font at index idx.


  • void set_spacing ( int type, int value )

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

Doc ID missing

Disclaimer: This page has been automaticaly and directly extracted from the official Godot Docs website, the 1970-01-01 at 00:00:00. It’s the English Stable version because it’s what most Godot users should use. The Copyright owners are Juan Linietsky, Ariel Manzur and the Godot community. CC-BY 3.0. Thanks for your patience and generosity.