FontData

Inherits: Resource < RefCounted < Object

Font source data and prerendered glyph cache, imported from dynamic or bitmap font.

Supported font formats:

  • Dynamic font importer: TrueType (.ttf), OpenType (.otf), WOFF (.woff), Type 1 (.pfb, .pfm).

  • Bitmap font importer: AngelCode BMFont (.fnt, .font), text and binary (version 3) format variants.

  • Monospace image font importer: All supported image formats.

Properties

bool

antialiased

true

PackedByteArray

data

PackedByteArray()

float

embolden

0.0

int

fixed_size

0

String

font_name

""

int

font_style

0

bool

force_autohinter

false

Hinting

hinting

1

int

msdf_pixel_range

16

int

msdf_size

48

bool

multichannel_signed_distance_field

false

Dictionary

opentype_feature_overrides

{}

float

oversampling

0.0

String

style_name

""

SubpixelPositioning

subpixel_positioning

1

Transform2D

transform

Transform2D(1, 0, 0, 1, 0, 0)

Methods

void

clear_cache ( )

void

clear_glyphs ( int cache_index, Vector2i size )

void

clear_kerning_map ( int cache_index, int size )

void

clear_size_cache ( int cache_index )

void

clear_textures ( int cache_index, Vector2i size )

RID

find_cache ( Dictionary variation_coordinates ) const

float

get_ascent ( int cache_index, int size ) const

int

get_cache_count ( ) const

RID

get_cache_rid ( int cache_index ) const

float

get_descent ( int cache_index, int size ) const

Vector2

get_glyph_advance ( int cache_index, int size, int glyph ) const

int

get_glyph_index ( int size, int char, int variation_selector ) const

Array

get_glyph_list ( int cache_index, Vector2i size ) const

Vector2

get_glyph_offset ( int cache_index, Vector2i size, int glyph ) const

Vector2

get_glyph_size ( int cache_index, Vector2i size, int glyph ) const

int

get_glyph_texture_idx ( int cache_index, Vector2i size, int glyph ) const

Rect2

get_glyph_uv_rect ( int cache_index, Vector2i size, int glyph ) const

Vector2

get_kerning ( int cache_index, int size, Vector2i glyph_pair ) const

Array

get_kerning_list ( int cache_index, int size ) const

bool

get_language_support_override ( String language ) const

PackedStringArray

get_language_support_overrides ( ) const

float

get_scale ( int cache_index, int size ) const

bool

get_script_support_override ( String script ) const

PackedStringArray

get_script_support_overrides ( ) const

Array

get_size_cache_list ( int cache_index ) const

int

get_spacing ( int cache_index, int size, SpacingType spacing_type ) const

String

get_supported_chars ( ) const

Dictionary

get_supported_feature_list ( ) const

Dictionary

get_supported_variation_list ( ) const

int

get_texture_count ( int cache_index, Vector2i size ) const

Image

get_texture_image ( int cache_index, Vector2i size, int texture_index ) const

PackedInt32Array

get_texture_offsets ( int cache_index, Vector2i size, int texture_index ) const

float

get_underline_position ( int cache_index, int size ) const

float

get_underline_thickness ( int cache_index, int size ) const

Dictionary

get_variation_coordinates ( int cache_index ) const

bool

has_char ( int char ) const

bool

is_language_supported ( String language ) const

bool

is_script_supported ( String script ) const

Error

load_bitmap_font ( String path )

Error

load_dynamic_font ( String path )

void

remove_cache ( int cache_index )

void

remove_glyph ( int cache_index, Vector2i size, int glyph )

void

remove_kerning ( int cache_index, int size, Vector2i glyph_pair )

void

remove_language_support_override ( String language )

void

remove_script_support_override ( String script )

void

remove_size_cache ( int cache_index, Vector2i size )

void

remove_texture ( int cache_index, Vector2i size, int texture_index )

void

render_glyph ( int cache_index, Vector2i size, int index )

void

render_range ( int cache_index, Vector2i size, int start, int end )

void

set_ascent ( int cache_index, int size, float ascent )

void

set_descent ( int cache_index, int size, float descent )

void

set_glyph_advance ( int cache_index, int size, int glyph, Vector2 advance )

void

set_glyph_offset ( int cache_index, Vector2i size, int glyph, Vector2 offset )

void

set_glyph_size ( int cache_index, Vector2i size, int glyph, Vector2 gl_size )

void

set_glyph_texture_idx ( int cache_index, Vector2i size, int glyph, int texture_idx )

void

set_glyph_uv_rect ( int cache_index, Vector2i size, int glyph, Rect2 uv_rect )

void

set_kerning ( int cache_index, int size, Vector2i glyph_pair, Vector2 kerning )

void

set_language_support_override ( String language, bool supported )

void

set_scale ( int cache_index, int size, float scale )

void

set_script_support_override ( String script, bool supported )

void

set_spacing ( int cache_index, int size, SpacingType spacing_type, int value )

void

set_texture_image ( int cache_index, Vector2i size, int texture_index, Image image )

void

set_texture_offsets ( int cache_index, Vector2i size, int texture_index, PackedInt32Array offset )

void

set_underline_position ( int cache_index, int size, float underline_position )

void

set_underline_thickness ( int cache_index, int size, float underline_thickness )

void

set_variation_coordinates ( int cache_index, Dictionary variation_coordinates )

Property Descriptions

Default

true

Setter

set_antialiased(value)

Getter

is_antialiased()

If set to true, font 8-bit anitialiased glyph rendering is supported and enabled.


Default

PackedByteArray()

Setter

set_data(value)

Getter

get_data()

Contents of the dynamic font source file.


Default

0.0

Setter

set_embolden(value)

Getter

get_embolden()

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


  • int fixed_size

Default

0

Setter

set_fixed_size(value)

Getter

get_fixed_size()

Font size, used only for the bitmap fonts.


Default

""

Setter

set_font_name(value)

Getter

get_font_name()

Font family name.


  • int font_style

Default

0

Setter

set_font_style(value)

Getter

get_font_style()

Font style flags, see FontStyle.


  • bool force_autohinter

Default

false

Setter

set_force_autohinter(value)

Getter

is_force_autohinter()

If set to true, auto-hinting is supported and preferred over font built-in hinting. Used by dynamic fonts only.


Default

1

Setter

set_hinting(value)

Getter

get_hinting()

Font hinting mode. Used by dynamic fonts only.


  • int msdf_pixel_range

Default

16

Setter

set_msdf_pixel_range(value)

Getter

get_msdf_pixel_range()

The width of the range around the shape between the minimum and maximum representable signed distance.


  • int msdf_size

Default

48

Setter

set_msdf_size(value)

Getter

get_msdf_size()

Source font size used to generate MSDF textures.


  • bool multichannel_signed_distance_field

Default

false

Setter

set_multichannel_signed_distance_field(value)

Getter

is_multichannel_signed_distance_field()

If set to true, glyphs of all sizes are rendered using single multichannel signed distance field generated from the dynamic font vector data.


Default

{}

Setter

set_opentype_feature_overrides(value)

Getter

get_opentype_feature_overrides()

Font OpenType feature set override.


Default

0.0

Setter

set_oversampling(value)

Getter

get_oversampling()

Font oversampling factor, if set to 0.0 global oversampling factor is used instead. Used by dynamic fonts only.


Default

""

Setter

set_font_style_name(value)

Getter

get_font_style_name()

Font style name.


Default

1

Setter

set_subpixel_positioning(value)

Getter

get_subpixel_positioning()

Font glyph sub-pixel positioning mode. Subpixel positioning provides shaper text and better kerning for smaller font sizes, at the cost of memory usage and font rasterization speed. Use TextServer.SUBPIXEL_POSITIONING_AUTO to automatically enable it based on the font size.


Default

Transform2D(1, 0, 0, 1, 0, 0)

Setter

set_transform(value)

Getter

get_transform()

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

Method Descriptions

  • void clear_cache ( )

Removes all font cache entries.


Removes all rendered glyphs information from the cache entry.

Note: This function will not remove textures associated with the glyphs, use remove_texture to remove them manually.


  • void clear_kerning_map ( int cache_index, int size )

Removes all kerning overrides.


  • void clear_size_cache ( int cache_index )

Removes all font sizes from the cache entry


  • void clear_textures ( int cache_index, Vector2i size )

Removes all textures from font cache entry.

Note: This function will not remove glyphs associated with the texture, use remove_glyph to remove them manually.


Returns existing or creates a new font cache entry for the specified variation coordinates.


Returns the font ascent (number of pixels above the baseline).


  • int get_cache_count ( ) const

Returns number of the font cache entries.


  • RID get_cache_rid ( int cache_index ) const

Returns text server font cache entry resource id.


  • float get_descent ( int cache_index, int size ) const

Returns font descent (number of pixels below the baseline).


Returns glyph advance (offset of the next glyph).

Note: Advance for glyphs outlines is the same as the base glyph advance and is not saved.


  • int get_glyph_index ( int size, int char, int variation_selector ) const

Returns the glyph index of a char, optionally modified by the variation_selector.


Returns list of rendered glyphs in the cache entry.


Returns glyph offset from the baseline.


Returns glyph size.


Returns index of the cache texture containing the glyph.


Returns rectangle in the cache texture containing the glyph.


Returns kerning for the pair of glyphs.


  • Array get_kerning_list ( int cache_index, int size ) const

Returns list of the kerning overrides.


  • bool get_language_support_override ( String language ) const

Returns true if support override is enabled for the language.


Returns list of language support overrides.


Returns scaling factor of the color bitmap font.


  • bool get_script_support_override ( String script ) const

Returns true if support override is enabled for the script.


Returns list of script support overrides.


  • Array get_size_cache_list ( int cache_index ) const

Returns list of the font sizes in the cache. Each size is Vector2i with font size and outline size.


Returns extra spacing added between glyphs in pixels.


  • String get_supported_chars ( ) const

Returns a string containing all the characters available in the font.


Returns list of OpenType features supported by font.


  • Dictionary get_supported_variation_list ( ) const

Returns list of supported variation coordinates, each coordinate is returned as tag: Vector3i(min_value,max_value,default_value).

Font variations allow for continuous change of glyph characteristics along some given design axis, such as weight, width or slant.


Returns number of textures used by font cache entry.


Returns a copy of the font cache texture image.


Returns a copy of the array containing the first free pixel in the each column of texture. Should be the same size as texture width or empty.


  • float get_underline_position ( int cache_index, int size ) const

Returns pixel offset of the underline below the baseline.


  • float get_underline_thickness ( int cache_index, int size ) const

Returns thickness of the underline in pixels.


Returns variation coordinates for the specified font cache entry. See get_supported_variation_list for more info.


Returns true if a Unicode char is available in the font.


  • bool is_language_supported ( String language ) const

Returns true, if font supports given language (ISO 639 code).


  • bool is_script_supported ( String script ) const

Returns true, if font supports given script (ISO 15924 code).


Loads an AngelCode BMFont (.fnt, .font) bitmap font from file path.

Warning: This method should only be used in the editor or in cases when you need to load external fonts at run-time, such as fonts located at the user:// directory.


Loads a TrueType (.ttf), OpenType (.otf), WOFF (.woff) or Type 1 (.pfb, .pfm) dynamic font from file path.

Warning: This method should only be used in the editor or in cases when you need to load external fonts at run-time, such as fonts located at the user:// directory.


  • void remove_cache ( int cache_index )

Removes specified font cache entry.


Removes specified rendered glyph information from the cache entry.

Note: This function will not remove textures associated with the glyphs, use remove_texture to remove them manually.


  • void remove_kerning ( int cache_index, int size, Vector2i glyph_pair )

Removes kerning override for the pair of glyphs.


  • void remove_language_support_override ( String language )

Remove language support override.


  • void remove_script_support_override ( String script )

Removes script support override.


  • void remove_size_cache ( int cache_index, Vector2i size )

Removes specified font size from the cache entry.


  • void remove_texture ( int cache_index, Vector2i size, int texture_index )

Removes specified texture from font cache entry.

Note: This function will not remove glyphs associated with the texture, remove them manually, using remove_glyph.


Renders specified glyph the the font cache texture.


Renders the range of characters to the font cache texture.


  • void set_ascent ( int cache_index, int size, float ascent )

Sets the font ascent (number of pixels above the baseline).


  • void set_descent ( int cache_index, int size, float descent )

Sets the font descent (number of pixels below the baseline).


  • void set_glyph_advance ( int cache_index, int size, int glyph, Vector2 advance )

Sets glyph advance (offset of the next glyph).

Note: Advance for glyphs outlines is the same as the base glyph advance and is not saved.


Sets glyph offset from the baseline.


Sets glyph size.


  • void set_glyph_texture_idx ( int cache_index, Vector2i size, int glyph, int texture_idx )

Sets index of the cache texture containing the glyph.


Sets rectangle in the cache texture containing the glyph.


Sets kerning for the pair of glyphs.


  • void set_language_support_override ( String language, bool supported )

Adds override for is_language_supported.


  • void set_scale ( int cache_index, int size, float scale )

Sets scaling factor of the color bitmap font.


  • void set_script_support_override ( String script, bool supported )

Adds override for is_script_supported.


Sets extra spacing added between glyphs in pixels.


Sets font cache texture image.


Sets array containing the first free pixel in the each column of texture. Should be the same size as texture width or empty (for the fonts without dynamic glyph generation support).


  • void set_underline_position ( int cache_index, int size, float underline_position )

Sets pixel offset of the underline below the baseline.


  • void set_underline_thickness ( int cache_index, int size, float underline_thickness )

Sets thickness of the underline in pixels.


  • void set_variation_coordinates ( int cache_index, Dictionary variation_coordinates )

Sets variation coordinates for the specified font cache entry. See get_supported_variation_list for more info.