.. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead. .. _class_Font: Font ==== **Inherits:** :ref:`Resource` **<** :ref:`Reference` **<** :ref:`Object` **Category:** Core Brief Description ----------------- Internationalized font and text drawing support. Member Functions ---------------- +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`create_from_fnt` **(** :ref:`String` path **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_height` **(** :ref:`float` px **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_height` **(** **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_ascent` **(** :ref:`float` px **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_ascent` **(** **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_descent` **(** **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_kerning_pair` **(** :ref:`int` char_a, :ref:`int` char_b, :ref:`int` kerning **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_kerning_pair` **(** :ref:`int` char_a, :ref:`int` char_b **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_texture` **(** :ref:`Texture` texture **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`add_char` **(** :ref:`int` character, :ref:`int` texture, :ref:`Rect2` rect, :ref:`Vector2` align=Vector2(0,0), :ref:`float` advance=-1 **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_texture_count` **(** **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Texture` | :ref:`get_texture` **(** :ref:`int` idx **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_char_size` **(** :ref:`int` char, :ref:`int` next=0 **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_string_size` **(** :ref:`String` string **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_distance_field_hint` **(** :ref:`bool` enable **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_distance_field_hint` **(** **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear` **(** **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`draw` **(** :ref:`RID` canvas_item, :ref:`Vector2` pos, :ref:`String` string, :ref:`Color` modulate=Color(1,1,1,1), :ref:`int` clip_w=-1 **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`draw_char` **(** :ref:`RID` canvas_item, :ref:`Vector2` pos, :ref:`int` char, :ref:`int` next=-1, :ref:`Color` modulate=Color(1,1,1,1) **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_fallback` **(** :ref:`Object` fallback **)** | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Object` | :ref:`get_fallback` **(** **)** const | +--------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ Description ----------- Font contains an 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 --------------------------- .. _class_Font_create_from_fnt: - :ref:`int` **create_from_fnt** **(** :ref:`String` path **)** .. _class_Font_set_height: - void **set_height** **(** :ref:`float` px **)** Set the total font height (ascent plus descent) in pixels. .. _class_Font_get_height: - :ref:`float` **get_height** **(** **)** const Return the total font height (ascent plus descent) in pixels. .. _class_Font_set_ascent: - void **set_ascent** **(** :ref:`float` px **)** Set the font ascent (number of pixels above the baseline). .. _class_Font_get_ascent: - :ref:`float` **get_ascent** **(** **)** const Return the font ascent (number of pixels above the baseline). .. _class_Font_get_descent: - :ref:`float` **get_descent** **(** **)** const Return the font descent (number of pixels below the baseline). .. _class_Font_add_kerning_pair: - void **add_kerning_pair** **(** :ref:`int` char_a, :ref:`int` char_b, :ref:`int` kerning **)** Add a kerning pair to the :ref:`Font` as a difference. Kerning pairs are special cases where a typeface advance is determined by the next character. .. _class_Font_get_kerning_pair: - :ref:`int` **get_kerning_pair** **(** :ref:`int` char_a, :ref:`int` char_b **)** const Return a kerning pair as a difference. Kerning pairs are special cases where a typeface advance is determined by the next character. .. _class_Font_add_texture: - void **add_texture** **(** :ref:`Texture` texture **)** Add a texture to the :ref:`Font`. .. _class_Font_add_char: - void **add_char** **(** :ref:`int` character, :ref:`int` texture, :ref:`Rect2` rect, :ref:`Vector2` align=Vector2(0,0), :ref:`float` advance=-1 **)** Add a character to the font, where "character" is the unicode value, "texture" is the texture index, "rect" is the region in the texture (in pixels!), "align" is the (optional) alignment for the character and "advance" is the (optional) advance. .. _class_Font_get_texture_count: - :ref:`int` **get_texture_count** **(** **)** const .. _class_Font_get_texture: - :ref:`Texture` **get_texture** **(** :ref:`int` idx **)** const .. _class_Font_get_char_size: - :ref:`Vector2` **get_char_size** **(** :ref:`int` char, :ref:`int` next=0 **)** const Return the size of a character, optionally taking kerning into account if the next character is provided. .. _class_Font_get_string_size: - :ref:`Vector2` **get_string_size** **(** :ref:`String` string **)** const Return the size of a string, taking kerning and advance into account. .. _class_Font_set_distance_field_hint: - void **set_distance_field_hint** **(** :ref:`bool` enable **)** .. _class_Font_is_distance_field_hint: - :ref:`bool` **is_distance_field_hint** **(** **)** const .. _class_Font_clear: - void **clear** **(** **)** Clear all the font data. .. _class_Font_draw: - void **draw** **(** :ref:`RID` canvas_item, :ref:`Vector2` pos, :ref:`String` string, :ref:`Color` modulate=Color(1,1,1,1), :ref:`int` clip_w=-1 **)** const 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. .. _class_Font_draw_char: - :ref:`float` **draw_char** **(** :ref:`RID` canvas_item, :ref:`Vector2` pos, :ref:`int` char, :ref:`int` next=-1, :ref:`Color` modulate=Color(1,1,1,1) **)** const 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. .. _class_Font_set_fallback: - void **set_fallback** **(** :ref:`Object` fallback **)** .. _class_Font_get_fallback: - :ref:`Object` **get_fallback** **(** **)** const