Up to date
This page is up to date for Godot 4.1
.
If you still find outdated information, please open an issue.
Font¶
Inherits: Resource < RefCounted < Object
Inherited By: FontFile, FontVariation, SystemFont
Abstract base class for fonts and font variations.
Description¶
Abstract base class for different font types. It has methods for drawing text and font character introspection.
Methods¶
draw_char ( RID canvas_item, Vector2 pos, int char, int font_size, Color modulate=Color(1, 1, 1, 1) ) const |
|
draw_char_outline ( RID canvas_item, Vector2 pos, int char, int font_size, int size=-1, Color modulate=Color(1, 1, 1, 1) ) const |
|
void |
draw_multiline_string ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int max_lines=-1, Color modulate=Color(1, 1, 1, 1), BitField<LineBreakFlag> brk_flags=3, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const |
void |
draw_multiline_string_outline ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int max_lines=-1, int size=1, Color modulate=Color(1, 1, 1, 1), BitField<LineBreakFlag> brk_flags=3, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const |
void |
draw_string ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, Color modulate=Color(1, 1, 1, 1), BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const |
void |
draw_string_outline ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int size=1, Color modulate=Color(1, 1, 1, 1), BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const |
find_variation ( Dictionary variation_coordinates, int face_index=0, float strength=0.0, Transform2D transform=Transform2D(1, 0, 0, 1, 0, 0) ) const |
|
get_ascent ( int font_size=16 ) const |
|
get_char_size ( int char, int font_size ) const |
|
get_descent ( int font_size=16 ) const |
|
get_face_count ( ) const |
|
get_fallbacks ( ) const |
|
get_font_name ( ) const |
|
get_font_stretch ( ) const |
|
BitField<FontStyle> |
get_font_style ( ) const |
get_font_style_name ( ) const |
|
get_font_weight ( ) const |
|
get_height ( int font_size=16 ) const |
|
get_multiline_string_size ( String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int max_lines=-1, BitField<LineBreakFlag> brk_flags=3, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const |
|
get_opentype_features ( ) const |
|
get_ot_name_strings ( ) const |
|
get_rids ( ) const |
|
get_spacing ( SpacingType spacing ) const |
|
get_string_size ( String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const |
|
get_supported_chars ( ) const |
|
get_supported_feature_list ( ) const |
|
get_supported_variation_list ( ) const |
|
get_underline_position ( int font_size=16 ) const |
|
get_underline_thickness ( int font_size=16 ) const |
|
is_language_supported ( String language ) const |
|
is_script_supported ( String script ) const |
|
void |
set_cache_capacity ( int single_line, int multi_line ) |
void |
set_fallbacks ( Font[] fallbacks ) |
Method Descriptions¶
float draw_char ( RID canvas_item, Vector2 pos, int char, int font_size, Color modulate=Color(1, 1, 1, 1) ) const
Draw a single Unicode character char
into a canvas item using the font, at a given position, with modulate
color. pos
specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis.
Note: Do not use this function to draw strings character by character, use draw_string or TextLine instead.
float draw_char_outline ( RID canvas_item, Vector2 pos, int char, int font_size, int size=-1, Color modulate=Color(1, 1, 1, 1) ) const
Draw a single Unicode character char
outline into a canvas item using the font, at a given position, with modulate
color and size
outline size. pos
specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis.
Note: Do not use this function to draw strings character by character, use draw_string or TextLine instead.
void draw_multiline_string ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int max_lines=-1, Color modulate=Color(1, 1, 1, 1), BitField<LineBreakFlag> brk_flags=3, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const
Breaks text
into lines using rules specified by brk_flags
and draws it into a canvas item using the font, at a given position, with modulate
color, optionally clipping the width and aligning horizontally. pos
specifies the baseline of the first line, not the top. To draw from the top, ascent must be added to the Y axis.
See also CanvasItem.draw_multiline_string.
void draw_multiline_string_outline ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int max_lines=-1, int size=1, Color modulate=Color(1, 1, 1, 1), BitField<LineBreakFlag> brk_flags=3, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const
Breaks text
to the lines using rules specified by brk_flags
and draws text outline into a canvas item using the font, at a given position, with modulate
color and size
outline size, optionally clipping the width and aligning horizontally. pos
specifies the baseline of the first line, not the top. To draw from the top, ascent must be added to the Y axis.
See also CanvasItem.draw_multiline_string_outline.
void draw_string ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, Color modulate=Color(1, 1, 1, 1), BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const
Draw text
into a canvas item using the font, at a given position, with modulate
color, optionally clipping the width and aligning horizontally. pos
specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis.
See also CanvasItem.draw_string.
void draw_string_outline ( RID canvas_item, Vector2 pos, String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int size=1, Color modulate=Color(1, 1, 1, 1), BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const
Draw text
outline into a canvas item using the font, at a given position, with modulate
color and size
outline size, optionally clipping the width and aligning horizontally. pos
specifies the baseline, not the top. To draw from the top, ascent must be added to the Y axis.
See also CanvasItem.draw_string_outline.
RID find_variation ( Dictionary variation_coordinates, int face_index=0, float strength=0.0, Transform2D transform=Transform2D(1, 0, 0, 1, 0, 0) ) const
Returns TextServer RID of the font cache for specific variation.
float get_ascent ( int font_size=16 ) const
Returns the average font ascent (number of pixels above the baseline).
Note: Real ascent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the ascent of empty line).
Vector2 get_char_size ( int char, int font_size ) const
Returns the size of a character. Does not take kerning into account.
Note: Do not use this function to calculate width of the string character by character, use get_string_size or TextLine instead. The height returned is the font height (see also get_height) and has no relation to the glyph height.
float get_descent ( int font_size=16 ) const
Returns the average font descent (number of pixels below the baseline).
Note: Real descent of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the descent of empty line).
int get_face_count ( ) const
Returns number of faces in the TrueType / OpenType collection.
Font[] get_fallbacks ( ) const
Returns array of fallback Fonts.
String get_font_name ( ) const
Returns font family name.
int get_font_stretch ( ) const
Returns font stretch amount, compared to a normal width. A percentage value between 50%
and 200%
.
BitField<FontStyle> get_font_style ( ) const
Returns font style flags, see FontStyle.
String get_font_style_name ( ) const
Returns font style name.
int get_font_weight ( ) const
Returns weight (boldness) of the font. A value in the 100...999
range, normal font weight is 400
, bold font weight is 700
.
float get_height ( int font_size=16 ) const
Returns the total average font height (ascent plus descent) in pixels.
Note: Real height of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate (e.g. as the height of empty line).
Vector2 get_multiline_string_size ( String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, int max_lines=-1, BitField<LineBreakFlag> brk_flags=3, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const
Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account.
See also draw_multiline_string.
Dictionary get_opentype_features ( ) const
Returns a set of OpenType feature tags. More info: OpenType feature tags.
Dictionary get_ot_name_strings ( ) const
Returns Dictionary with OpenType font name strings (localized font names, version, description, license information, sample text, etc.).
RID[] get_rids ( ) const
Returns Array of valid Font RIDs, which can be passed to the TextServer methods.
int get_spacing ( SpacingType spacing ) const
Returns the spacing for the given type
(see SpacingType).
Vector2 get_string_size ( String text, HorizontalAlignment alignment=0, float width=-1, int font_size=16, BitField<JustificationFlag> justification_flags=3, Direction direction=0, Orientation orientation=0 ) const
Returns the size of a bounding box of a single-line string, taking kerning, advance and subpixel positioning into account. See also get_multiline_string_size and draw_string.
For example, to get the string size as displayed by a single-line Label, use:
var string_size = $Label.get_theme_font("font").get_string_size($Label.text, HORIZONTAL_ALIGNMENT_LEFT, -1, $Label.get_theme_font_size("font_size"))