Inherits: Font < Resource < RefCounted < Object
Holds font source data and prerendered glyph cache, imported from a dynamic or a bitmap font.
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:
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)
C#var f = ResourceLoader.Load<FontFile>("res://BarlowCondensed-Bold.ttf");
GetNode("Label").AddThemeFontOverride("font", f);
GetNode("Label").AddThemeFontSizeOverride("font_size", 64);
| ||
| ||
| ||
| ||
| ||
| ||
| ||
BitField<FontStyle> |
| |
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
| ||
|
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 ) |
get_cache_ascent ( int cache_index, int size ) const | |
get_cache_count ( ) const | |
get_cache_descent ( int cache_index, int size ) const | |
get_cache_scale ( int cache_index, int size ) const | |
get_cache_underline_position ( int cache_index, int size ) const | |
get_cache_underline_thickness ( int cache_index, int size ) const | |
get_char_from_glyph_index ( int size, int glyph_index ) const | |
get_embolden ( int cache_index ) const | |
get_extra_spacing ( int cache_index, SpacingType spacing ) const | |
get_face_index ( int cache_index ) const | |
get_glyph_advance ( int cache_index, int size, int glyph ) const | |
get_glyph_index ( int size, int char, int variation_selector ) const | |
get_glyph_list ( int cache_index, Vector2i size ) const | |
get_glyph_offset ( int cache_index, Vector2i size, int glyph ) const | |
get_glyph_size ( int cache_index, Vector2i size, int glyph ) const | |
get_glyph_texture_idx ( int cache_index, Vector2i size, int glyph ) const | |
get_glyph_uv_rect ( int cache_index, Vector2i size, int glyph ) const | |
get_kerning ( int cache_index, int size, Vector2i glyph_pair ) const | |
get_kerning_list ( int cache_index, int size ) const | |
get_language_support_override ( String language ) const | |
get_language_support_overrides ( ) const | |
get_script_support_override ( String script ) const | |
get_script_support_overrides ( ) const | |
get_size_cache_list ( int cache_index ) const | |
get_texture_count ( int cache_index, Vector2i size ) const | |
get_texture_image ( int cache_index, Vector2i size, int texture_index ) const | |
get_texture_offsets ( int cache_index, Vector2i size, int texture_index ) const | |
get_transform ( int cache_index ) const | |
get_variation_coordinates ( int cache_index ) const | |
load_bitmap_font ( String path ) | |
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_cache_ascent ( int cache_index, int size, float ascent ) |
void | set_cache_descent ( int cache_index, int size, float descent ) |
void | set_cache_scale ( int cache_index, int size, float scale ) |
void | set_cache_underline_position ( int cache_index, int size, float underline_position ) |
void | set_cache_underline_thickness ( int cache_index, int size, float underline_thickness ) |
void | set_embolden ( int cache_index, float strength ) |
void | set_extra_spacing ( int cache_index, SpacingType spacing, int value ) |
void | set_face_index ( int cache_index, int face_index ) |
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_script_support_override ( String script, bool supported ) |
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_transform ( int cache_index, Transform2D transform ) |
void | set_variation_coordinates ( int cache_index, Dictionary variation_coordinates ) |
true
If set to true, system fonts can be automatically used as fallbacks.
1
Font anti-aliasing mode.
PackedByteArray()
Contents of the dynamic font source file.
0
Font size, used only for the bitmap fonts.
0
Scaling mode, used only for the bitmap fonts with fixed_size greater than zero.
""
Font family name.
100
Font stretch amount, compared to a normal width. A percentage value between 50% and 200%.
0
Font style flags, see FontStyle.
400
Weight (boldness) of the font. A value in the 100...999 range, normal font weight is 400, bold font weight is 700.
false
If set to true, auto-hinting is supported and preferred over font built-in hinting. Used by dynamic fonts only (MSDF fonts don't support hinting).
false
If set to true, generate mipmaps for the font textures.
1
Font hinting mode. Used by dynamic fonts only.
16
The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, msdf_pixel_range must be set to at least twice the size of the largest font outline. The default msdf_pixel_range value of 16 allows outline sizes up to 8 to look correct.
48
Source font size used to generate MSDF textures. Higher values allow for more precision, but are slower to render and require more memory. Only increase this value if you notice a visible lack of precision in glyph rendering.
false
If set to true, glyphs of all sizes are rendered using single multichannel signed distance field (MSDF) generated from the dynamic font vector data. Since this approach does not rely on rasterizing the font every time its size changes, this allows for resizing the font in real-time without any performance penalty. Text will also not look grainy for Controls that are scaled down (or for Label3Ds viewed from a long distance). 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: If using font outlines, msdf_pixel_range must be set to at least twice the size of the largest font outline.
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.
{}
Font OpenType feature set override.
0.0
Font oversampling factor. If set to 0.0, the global oversampling factor is used instead. Used by dynamic fonts only (MSDF fonts ignore oversampling).
""
Font style name.
1
Font glyph subpixel positioning mode. Subpixel positioning provides shaper text and better kerning for smaller font sizes, at the cost of higher memory usage and lower font rasterization speed. Use TextServer.SUBPIXEL_POSITIONING_AUTO to automatically enable it based on the font size.
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.
Removes all kerning overrides.
Removes all font sizes from the cache entry
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 the font ascent (number of pixels above the baseline).
Returns number of the font cache entries.
Returns the font descent (number of pixels below the baseline).
Returns scaling factor of the color bitmap font.
Returns pixel offset of the underline below the baseline.
Returns thickness of the underline in pixels.
Returns character code associated with glyph_index, or 0 if glyph_index is invalid. See get_glyph_index.
Returns embolden strength, if is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.
Returns spacing for spacing (see SpacingType) in pixels (not relative to the font size).
Returns an active face index in the TrueType / OpenType collection.
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.
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.
Returns list of the kerning overrides.
Returns true if support override is enabled for the language.
Returns list of language support overrides.
Returns true if support override is enabled for the script.
Returns list of script support overrides.
Returns list of the font sizes in the cache. Each size is Vector2i with font size and outline size.
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 glyph packing data.
Returns 2D transform, applied to the font outlines, can be used for slanting, flipping and rotating glyphs.
Returns variation coordinates for the specified font cache entry. See Font.get_supported_variation_list for more info.
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), WOFF2 (.woff2) 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.
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.
Removes kerning override for the pair of glyphs.
Remove language support override.
Removes script support override.
Removes specified font size from the cache entry.
Removes specified texture from the cache entry.
Note: This function will not remove glyphs associated with the texture. Remove them manually using remove_glyph.
Renders specified glyph to the font cache texture.
Renders the range of characters to the font cache texture.
Sets the font ascent (number of pixels above the baseline).
Sets the font descent (number of pixels below the baseline).
Sets scaling factor of the color bitmap font.
Sets pixel offset of the underline below the baseline.
Sets thickness of the underline in pixels.
Sets embolden strength, if is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.
Sets the spacing for spacing (see SpacingType) to value in pixels (not relative to the font size).
Sets an active face index in the TrueType / OpenType collection.
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.
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.
Adds override for Font.is_language_supported.
Adds override for Font.is_script_supported.
Sets font cache texture image.
Sets array containing glyph packing data.
Sets 2D transform, applied to the font outlines, can be used for slanting, flipping and rotating glyphs.
Sets variation coordinates for the specified font cache entry. See Font.get_supported_variation_list for more info.
© 2014–present Juan Linietsky, Ariel Manzur and the Godot community
Licensed under the Creative Commons Attribution Unported License v3.0.
https://docs.godotengine.org/en/4.2/classes/class_fontfile.html