Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

FontFile

Inherits: Font < Resource < RefCounted < Object

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

Description

FontFile contains a set of glyphs to represent Unicode characters imported from a font file, as well as a cache of rasterized glyphs, and a set of fallback Fonts to use.

Use FontVariation to access specific OpenType variation of the font, create simulated bold / slanted version, and draw lines of text.

For more complex text processing, use FontVariation in conjunction with TextLine or TextParagraph.

Supported font formats:

  • Dynamic font importer: TrueType (.ttf), TrueType collection (.ttc), OpenType (.otf), OpenType collection (.otc), WOFF (.woff), WOFF2 (.woff2), 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.

Note: A character is a symbol that represents an item (letter, digit etc.) in an abstract way.

Note: A glyph is a bitmap or a shape used to draw one or more characters in a context-dependent manner. Glyph indices are bound to the specific font data source.

Note: If none of the font data sources contain glyphs for a character used in a string, the character in question will be replaced with a box displaying its hexadecimal code.

var f = load("res://BarlowCondensed-Bold.ttf")
$Label.add_theme_font_override("font", f)
$Label.add_theme_font_size_override("font_size", 64)

Tutorials

Properties

bool

allow_system_fallback

true

FontAntialiasing

antialiasing

1

PackedByteArray

data

PackedByteArray()

int

fixed_size

0

FixedSizeScaleMode

fixed_size_scale_mode

0

String

font_name

""

int

font_stretch

100

BitField<FontStyle>

font_style

0

int

font_weight

400

bool

force_autohinter

false

bool

generate_mipmaps

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

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 )

float

get_cache_ascent ( int cache_index, int size ) const

int

get_cache_count ( ) const

float

get_cache_descent ( int cache_index, int size ) const

float

get_cache_scale ( int cache_index, int size ) const

float

get_cache_underline_position ( int cache_index, int size ) const

float

get_cache_underline_thickness ( int cache_index, int size ) const

int

get_char_from_glyph_index ( int size, int glyph_index ) const

float

get_embolden ( int cache_index ) const

int

get_extra_spacing ( int cache_index, SpacingType spacing ) const

int

get_face_index ( int cache_index ) 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

PackedInt32Array

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

Vector2i[]

get_kerning_list ( int cache_index, int size ) const

bool

get_language_support_override ( String language ) const

PackedStringArray

get_language_support_overrides ( ) const

bool

get_script_support_override ( String script ) const

PackedStringArray

get_script_support_overrides ( ) const

Vector2i[]

get_size_cache_list ( int cache_index ) 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

Transform2