Font

Inherits: Resource < Reference < Object Inherited By: BitmapFont, DynamicFont Internationalized font and text drawing support.

Description

Font contains a Unicode-compatible character set, as well as the ability to draw it with variable width, ascent, descent and kerning. For creating fonts from TTF files (or other font formats), see the editor support for fonts. Note: If a DynamicFont doesn’t contain a character used in a string, the character in question will be replaced with codepoint 0xfffd if it’s available in the DynamicFont. If this replacement character isn’t available in the DynamicFont, the character will be hidden without displaying any replacement character in the string. Note: If a BitmapFont doesn’t contain a character used in a string, the character in question will be hidden without displaying any replacement character in the string. Note: Unicode characters after 0xffff (such as most emoji) are not supported on Windows. They will display as unknown characters instead. This will be resolved in Godot 4.0.

Methods

Method Descriptions

  • draw ( RID canvas_item, Vector2 position, String string, Color modulate=Color( 1, 1, 1, 1 ), int clip_w=-1, Color outline_modulate=Color( 1, 1, 1, 1 ) ) const string into a canvas item using the font at a given position, with modulate color, and optionally clipping the width. position specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis. CanvasItem.draw_string.

  • float draw_char ( RID canvas_item, Vector2 position, int char, int next=-1, Color modulate=Color( 1, 1, 1, 1 ), bool outline=false ) const char into a canvas item using the font at a given position, with modulate color, and optionally kerning if next is passed. clipping the width. position specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis. The width used by the character is returned, making this function useful for drawing strings character by character.

  • float get_ascent ( ) const Returns the font ascent (number of pixels above the baseline).

  • Vector2 get_char_size ( int char, int next=0 ) const get_height) and has no relation to the glyph height.

  • float get_descent ( ) const Returns the font descent (number of pixels below the baseline).

  • float get_height ( ) const Returns the total font height (ascent plus descent) in pixels.

  • Vector2 get_string_size ( String string ) const get_height) and has no relation to the string.

  • Vector2 get_wordwrap_string_size ( String string, float width ) const width.

  • bool has_outline ( ) const true if the font has an outline.

- bool is_distance_field_hint ( ) const

  • update_changes ( ) After editing a font (changing size, ascent, char rects, etc.). Call this function to propagate changes to controls that might use it.