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.

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

PackedByteArray

get_data ( ) 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 char, int variation_selector, int arg2 ) 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

Hinting

get_hinting ( ) 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

int

get_msdf_pixel_range ( ) const

int

get_msdf_size ( ) const

float

get_oversampling ( ) 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 arg2 ) 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_antialiased ( ) const

bool

is_force_autohinter ( ) const

bool

is_language_supported ( String language ) const

bool

is_multichannel_signed_distance_field ( ) const

bool

is_script_supported ( String script ) const

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_antialiased ( bool antialiased )

void

set_ascent ( int cache_index, int size, float ascent )

void

set_data ( PackedByteArray data )

void

set_descent ( int cache_index, int size, float descent )

void

set_force_autohinter ( bool force_autohinter )

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_hinting ( Hinting hinting )

void

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

void

set_language_support_override ( String language, bool supported )

void

set_msdf_pixel_range ( int msdf_pixel_range )

void

set_msdf_size ( int msdf_size )

void

set_multichannel_signed_distance_field ( bool msdf )

void

set_oversampling ( float oversampling )

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, int arg3 )

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 )

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.


Returns contents of the dynamic font source file.


  • 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 char, int variation_selector, int arg2 ) 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 the font hinting mode. Used by dynamic fonts only.


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.


  • int get_msdf_pixel_range ( ) const

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


  • int get_msdf_size ( ) const

Returns source font size used to generate MSDF textures.


  • float get_oversampling ( ) const

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


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

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


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


  • bool is_antialiased ( ) const

Returns true if font 8-bit anitialiased glyph rendering is supported and enabled.


  • bool is_force_autohinter ( ) const

Returns true if auto-hinting is supported and preffered over font built-in hinting. Used by dynamic fonts only.


  • bool is_language_supported ( String language ) const

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


  • bool is_multichannel_signed_distance_field ( ) const

Returns true if glyphs of all sizes are rendered using single multichannel signed distance field generated from the dynamic font vector data.


  • bool is_script_supported ( String script ) const

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


  • 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_antialiased ( bool antialiased )

If set to true, 8-bit antialiased glyph rendering is used, otherwise 1-bit rendering is used. Used by dynamic fonts only.


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

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


Sets font source data, e.g contents of the dynamic font source file.


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

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


  • void set_force_autohinter ( bool force_autohinter )

If set to true auto-hinting is preffered over font built-in hinting.


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


  • void set_hinting ( Hinting hinting )

Sets font hinting mode. Used by dynamic fonts only.


Sets kerning for the pair of glyphs.


  • void set_language_support_override ( String language, bool supported )

Adds override for is_language_supported.


  • void set_msdf_pixel_range ( int msdf_pixel_range )

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


  • void set_msdf_size ( int msdf_size )

Sets source font size used to generate MSDF textures.


  • void set_multichannel_signed_distance_field ( bool msdf )

If set to true, glyphs of all sizes are rendered using single multichannel signed distance field (MSDF) generated from the dynamic font vector data. MSDF rendering allows displaying the font at any scaling factor without blurriness, and without incurring a CPU cost when the font size changes (since the font no longer needs to be rasterized on the CPU). As a downside, font hinting is not available with MSDF. The lack of font hinting may result in less crisp and less readable fonts at small sizes.

Note: MSDF font rendering does not render glyphs with overlapping shapes correctly. Overlapping shapes are not valid per the OpenType standard, but are still commonly found in many font files, especially those converted by Google Fonts. To avoid issues with overlapping glyphs, consider downloading the font file directly from the type foundry instead of relying on Google Fonts.


  • void set_oversampling ( float oversampling )

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


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