Font

    Inherited By: BitmapFont,

    Internationalized font and text drawing support.

    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 doesn’t contain a character used in a string, the character in question will be replaced with codepoint 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 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.

    enum ContourPointTag:

    • CONTOUR_CURVE_TAG_OFF_CONIC = 0 —- Contour point isn’t on the curve, but serves as a control point for a conic (quadratic) Bézier arc.

    • CONTOUR_CURVE_TAG_OFF_CUBIC = 2 —- Contour point isn’t on the curve, but serves as a control point for a cubic Bézier arc.

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

    See also .


    • float draw_char ( canvas_item, Vector2 position, char, int next=-1, modulate=Color( 1, 1, 1, 1 ), bool outline=false ) const

    Draw character char into a canvas item using the font at a given position, with 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.


    • get_ascent ( ) const

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


    Returns outline contours of the glyph as a Dictionary with the following contents:

    points - , containing outline points. x and are point coordinates. z is the type of the point, using the ContourPointTag values.

    contours - , containing indices the end points of each contour.

    orientation - bool, contour orientation. If true, clockwise contours must be filled.


    • get_char_size ( int char, next=0 ) const

    Returns the size of a character, optionally taking kerning into account if the next character is provided. Note that the height returned is the font height (see get_height) and has no relation to the glyph height.


    • get_char_texture ( int char, next=0, bool outline=false ) const

    Returns resource id of the cache texture containing the char.


    • get_char_texture_size ( int char, next=0, bool outline=false ) const

    Returns size of the cache texture containing the char.


    • get_char_tx_offset ( int char, next=0, bool outline=false ) const

    Returns char offset from the baseline.


    Returns size of the char.


    • get_char_tx_uv_rect ( int char, next=0, bool outline=false ) const

    Returns rectangle in the cache texture containing the char.


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


    • get_string_size ( String string ) const

    Returns the size of a string, taking kerning and advance into account. Note that the height returned is the font height (see ) and has no relation to the string.


    • Vector2 get_wordwrap_string_size ( string, float width ) const

    Returns the size that the string would have with word wrapping enabled with a fixed width.


    • has_outline ( ) const

    • bool is_distance_field_hint ( ) const

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