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 [Font]s 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.
[b]Note:[/b] A character is a symbol that represents an item (letter, digit etc.) in an abstract way.
[b]Note:[/b] 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.
[b]Note:[/b] 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.
[codeblocks]
[gdscript]
var f = load("res://BarlowCondensed-Bold.ttf")
$Label.add_theme_font_override("font", f)
$Label.add_theme_font_size_override("font_size", 64)
[/gdscript]
[csharp]
var f = ResourceLoader.Load<FontFile>("res://BarlowCondensed-Bold.ttf");
GetNode("Label").AddThemeFontOverride("font", f);
GetNode("Label").AddThemeFontSizeOverride("font_size", 64);
[/csharp]
[/codeblocks]
$DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html
Removes all font cache entries.
Removes all rendered glyphs information from the cache entry.
[b]Note:[/b] This function will not remove textures associated with the glyphs, use [method 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.
[b]Note:[/b] This function will not remove glyphs associated with the texture, use [method 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 [param glyph_index], or [code]0[/code] if [param glyph_index] is invalid. See [method get_glyph_index].
Returns embolden strength, if is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.
Returns extra baseline offset (as a fraction of font height).
Returns spacing for [param spacing] (see [enum TextServer.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).
[b]Note:[/b] Advance for glyphs outlines is the same as the base glyph advance and is not saved.
Returns the glyph index of a [param char], optionally modified by the [param 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 [code]true[/code] if support override is enabled for the [param language].
Returns list of language support overrides.
Returns [code]true[/code] if support override is enabled for the [param 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 [method Font.get_supported_variation_list] for more info.
Loads an AngelCode BMFont (.fnt, .font) bitmap font from file [param path].
[b]Warning:[/b] 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 [code]user://[/code] directory.
Loads a TrueType (.ttf), OpenType (.otf), WOFF (.woff), WOFF2 (.woff2) or Type 1 (.pfb, .pfm) dynamic font from file [param path].
[b]Warning:[/b] 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 [code]user://[/code] directory.
Removes specified font cache entry.
Removes specified rendered glyph information from the cache entry.
[b]Note:[/b] This function will not remove textures associated with the glyphs, use [method 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.
[b]Note:[/b] This function will not remove glyphs associated with the texture. Remove them manually using [method 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 extra baseline offset (as a fraction of font height).
Sets the spacing for [param spacing] (see [enum TextServer.SpacingType]) to [param 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).
[b]Note:[/b] 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 [method Font.is_language_supported].
Adds override for [method 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 [method Font.get_supported_variation_list] for more info.
If set to [code]true[/code], system fonts can be automatically used as fallbacks.
Font anti-aliasing mode.
Contents of the dynamic font source file.
If set to [code]true[/code], embedded font bitmap loading is disabled (bitmap-only and color fonts ignore this property).
Font size, used only for the bitmap fonts.
Scaling mode, used only for the bitmap fonts with [member fixed_size] greater than zero.
Font family name.
Font stretch amount, compared to a normal width. A percentage value between [code]50%[/code] and [code]200%[/code].
Font style flags, see [enum TextServer.FontStyle].
Weight (boldness) of the font. A value in the [code]100...999[/code] range, normal font weight is [code]400[/code], bold font weight is [code]700[/code].
If set to [code]true[/code], auto-hinting is supported and preferred over font built-in hinting. Used by dynamic fonts only (MSDF fonts don't support hinting).
If set to [code]true[/code], generate mipmaps for the font textures.
Font hinting mode. Used by dynamic fonts only.
The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, [member msdf_pixel_range] must be set to at least [i]twice[/i] the size of the largest font outline. The default [member msdf_pixel_range] value of [code]16[/code] allows outline sizes up to [code]8[/code] to look correct.
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.
If set to [code]true[/code], 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 [Control]s that are scaled down (or for [Label3D]s 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.
[b]Note:[/b] If using font outlines, [member msdf_pixel_range] must be set to at least [i]twice[/i] the size of the largest font outline.
[b]Note:[/b] 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.
Font oversampling factor. If set to [code]0.0[/code], the global oversampling factor is used instead. Used by dynamic fonts only (MSDF fonts ignore oversampling).
Font style name.
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 [constant TextServer.SUBPIXEL_POSITIONING_AUTO] to automatically enable it based on the font size.