Font

Inherits: Resource < Reference < Object

Inherited By: DynamicFont, BitmapFont

Category: Core

Brief Description

Internationalized font and text drawing support.

Member Functions

void draw ( RID canvas_item, Vector2 pos, String string, Color modulate=null, int clip_w=null ) const
float draw_char ( RID canvas_item, Vector2 pos, int char, int next=null, Color modulate=null ) const
float get_ascent ( ) const
float get_descent ( ) const
float get_height ( ) const
Vector2 get_string_size ( String string ) const
bool is_distance_field_hint ( ) const
void update_changes ( )

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. TODO check wikipedia for graph of ascent/baseline/descent/height/etc.

Member Function Description

Draw “string” into a canvas item using the font at a given “pos” position, with “modulate” color, and optionally clipping the width. “pos” specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis.

Draw character “char” into a canvas item using the font at a given “pos” position, with “modulate” color, and optionally kerning if “next” is passed. clipping the width. “pos” 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

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

  • float get_descent ( ) const

Return the font descent (number of pixels below the baseline).

  • float get_height ( ) const

Return the total font height (ascent plus descent) in pixels.

Return the size of a string, taking kerning and advance into account.

  • bool is_distance_field_hint ( ) const
  • void update_changes ( )

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