DynamicFont

    DynamicFont renders vector font files at runtime.

    DynamicFont renders vector font files (such as TTF or OTF) dynamically at runtime instead of using a prerendered texture atlas like . This trades the faster loading time of BitmapFonts for the ability to change font parameters like size and spacing during runtime. 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 FreeType library for rasterization.

    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 to do so. In FontForge, use File > Generate Fonts, click Options, choose the desired features then generate the font.

    Tutorials

    Methods

    void ( DynamicFontData data )
    get_available_chars ( ) const
    get_fallback ( idx ) const
    int ( ) const
    int ( int type ) const
    void ( int idx )
    void ( int idx, data )
    voidset_spacing ( type, int value )

    enum SpacingType:

    • SPACING_TOP = 0 —- Spacing at the top.
    • SPACING_CHAR = 2 —- Spacing for each character.
    • SPACING_SPACE = 3 —- Spacing for the space character.

    Property Descriptions

    • 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 spacing for each character in pixels.

    This can be a negative number to make the distance between characters smaller.


    • extra_spacing_space

    This can be a negative number to make the distance between words smaller.


    • int extra_spacing_top
    Default0
    Setterset_spacing(value)
    Getterget_spacing()

    Extra spacing at the top in pixels.


    • font_data
    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.


    • 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.


    Default
    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.


    • use_mipmaps
    Defaultfalse
    Setterset_use_mipmaps(value)
    Getterget_use_mipmaps()

    Adds a fallback font.


    • get_available_chars ( ) const

    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.


    Returns the fallback font at index idx.


    • int get_fallback_count ( ) const

    Returns the number of fallback fonts.


    • get_spacing ( int type ) const

    Returns the spacing for the given type (see ).


    • void remove_fallback ( int idx )

    Removes the fallback font at index idx.


    Sets the fallback font at index idx.