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.
Properties
|
Methods
draw_char(canvas_item:RID, pos:Vector2, char:int, font_size:int, modulate:Color = Color(1, 1, 1, 1))const | |
draw_char_outline(canvas_item:RID, pos:Vector2, char:int, font_size:int, size:int = -1, modulate:Color = Color(1, 1, 1, 1))const | |
draw_multiline_string(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, max_lines:int = -1, modulate:Color = Color(1, 1, 1, 1), brk_flags:BitField[LineBreakFlag] = 3, justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const | |
draw_multiline_string_outline(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, max_lines:int = -1, size:int = 1, modulate:Color = Color(1, 1, 1, 1), brk_flags:BitField[LineBreakFlag] = 3, justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const | |
draw_string(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, modulate:Color = Color(1, 1, 1, 1), justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const | |
draw_string_outline(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, size:int = 1, modulate:Color = Color(1, 1, 1, 1), justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const | |
find_variation(variation_coordinates:Dictionary, face_index:int = 0, strength:float = 0.0, transform:Transform2D = Transform2D(1, 0, 0, 1, 0, 0), spacing_top:int = 0, spacing_bottom:int = 0, spacing_space:int = 0, spacing_glyph:int = 0, baseline_offset:float = 0.0)const | |
get_ascent(font_size:int = 16)const | |
get_char_size(char:int, font_size:int)const | |
get_descent(font_size:int = 16)const | |
get_height(font_size:int = 16)const | |
get_multiline_string_size(text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, max_lines:int = -1, brk_flags:BitField[LineBreakFlag] = 3, justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const | |
get_spacing(spacing:SpacingType)const | |
get_string_size(text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const | |
get_underline_position(font_size:int = 16)const | |
get_underline_thickness(font_size:int = 16)const | |
is_language_supported(language:String)const | |
is_script_supported(script:String)const | |
set_cache_capacity(single_line:int, multi_line:int) |
Property Descriptions
Array of fallbackFonts to use as a substitute if a glyph is not found in this currentFont.
If this array is empty in aFontVariation, theFontVariation.base_font's fallbacks are used instead.
Method Descriptions
floatdraw_char(canvas_item:RID, pos:Vector2, char:int, font_size:int, modulate:Color = Color(1, 1, 1, 1))const🔗
Draw a single Unicode characterchar
into a canvas item using the font, at a given position, withmodulate
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, usedraw_string() orTextLine instead.
floatdraw_char_outline(canvas_item:RID, pos:Vector2, char:int, font_size:int, size:int = -1, modulate:Color = Color(1, 1, 1, 1))const🔗
Draw a single Unicode characterchar
outline into a canvas item using the font, at a given position, withmodulate
color andsize
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, usedraw_string() orTextLine instead.
voiddraw_multiline_string(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, max_lines:int = -1, modulate:Color = Color(1, 1, 1, 1), brk_flags:BitField[LineBreakFlag] = 3, justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const🔗
Breakstext
into lines using rules specified bybrk_flags
and draws it into a canvas item using the font, at a given position, withmodulate
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 alsoCanvasItem.draw_multiline_string().
voiddraw_multiline_string_outline(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, max_lines:int = -1, size:int = 1, modulate:Color = Color(1, 1, 1, 1), brk_flags:BitField[LineBreakFlag] = 3, justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const🔗
Breakstext
to the lines using rules specified bybrk_flags
and draws text outline into a canvas item using the font, at a given position, withmodulate
color andsize
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 alsoCanvasItem.draw_multiline_string_outline().
voiddraw_string(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, modulate:Color = Color(1, 1, 1, 1), justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const🔗
Drawtext
into a canvas item using the font, at a given position, withmodulate
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 alsoCanvasItem.draw_string().
voiddraw_string_outline(canvas_item:RID, pos:Vector2, text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, size:int = 1, modulate:Color = Color(1, 1, 1, 1), justification_flags:BitField[JustificationFlag] = 3, direction:Direction = 0, orientation:Orientation = 0)const🔗
Drawtext
outline into a canvas item using the font, at a given position, withmodulate
color andsize
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 alsoCanvasItem.draw_string_outline().
RIDfind_variation(variation_coordinates:Dictionary, face_index:int = 0, strength:float = 0.0, transform:Transform2D = Transform2D(1, 0, 0, 1, 0, 0), spacing_top:int = 0, spacing_bottom:int = 0, spacing_space:int = 0, spacing_glyph:int = 0, baseline_offset:float = 0.0)const🔗
ReturnsTextServer RID of the font cache for specific variation.
floatget_ascent(font_size:int = 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).
Vector2get_char_size(char:int, font_size:int)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, useget_string_size() orTextLine instead. The height returned is the font height (see alsoget_height()) and has no relation to the glyph height.
floatget_descent(font_size:int = 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).
Returns number of faces in the TrueType / OpenType collection.
Returns font family name.
Returns font stretch amount, compared to a normal width. A percentage value between50%
and200%
.
BitField[FontStyle]get_font_style()const🔗
Returns font style flags, seeFontStyle.
Stringget_font_style_name()const🔗
Returns font style name.
Returns weight (boldness) of the font. A value in the100...999
range, normal font weight is400
, bold font weight is700
.
floatget_height(font_size:int = 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).
Vector2get_multiline_string_size(text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, max_lines:int = -1, brk_flags:BitField[LineBreakFlag] = 3, justification_flags:BitField[JustificationFlag] = 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 alsodraw_multiline_string().
Dictionaryget_opentype_features()const🔗
Returns a set of OpenType feature tags. More info:OpenType feature tags.
Dictionaryget_ot_name_strings()const🔗
ReturnsDictionary with OpenType font name strings (localized font names, version, description, license information, sample text, etc.).
ReturnsArray of validFontRIDs, which can be passed to theTextServer methods.
intget_spacing(spacing:SpacingType)const🔗
Returns the spacing for the giventype
(seeSpacingType).
Vector2get_string_size(text:String, alignment:HorizontalAlignment = 0, width:float = -1, font_size:int = 16, justification_flags:BitField[JustificationFlag] = 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 alsoget_multiline_string_size() anddraw_string().
For example, to get the string size as displayed by a single-line Label, use:
varstring_size=$Label.get_theme_font("font").get_string_size($Label.text,HORIZONTAL_ALIGNMENT_LEFT,-1,$Label.get_theme_font_size("font_size"))
Labellabel=GetNode<Label>("Label");Vector2stringSize=label.GetThemeFont("font").GetStringSize(label.Text,HorizontalAlignment.Left,-1,label.GetThemeFontSize("font_size"));
Note: Since kerning, advance and subpixel positioning are taken into account byget_string_size(), using separateget_string_size() calls on substrings of a string then adding the results together will return a different result compared to using a singleget_string_size() call on the full string.
Note: Real height of the string is context-dependent and can be significantly different from the value returned byget_height().
Stringget_supported_chars()const🔗
Returns a string containing all the characters available in the font.
If a given character is included in more than one font data source, it appears only once in the returned string.
Dictionaryget_supported_feature_list()const🔗
Returns list of OpenType features supported by font.
Dictionaryget_supported_variation_list()const🔗
Returns list of supportedvariation coordinates, each coordinate is returned astag:Vector3i(min_value,max_value,default_value)
.
Font variations allow for continuous change of glyph characteristics along some given design axis, such as weight, width or slant.
To print available variation axes of a variable font:
varfv=FontVariation.new()fv.base_font=load("res://RobotoFlex.ttf")varvariation_list=fv.get_supported_variation_list()fortaginvariation_list:varname=TextServerManager.get_primary_interface().tag_to_name(tag)varvalues=variation_list[tag]print("variation axis:%s (%d)\n\tmin, max, default:%s"%[name,tag,values])
Note: To set and get variation coordinates of aFontVariation, useFontVariation.variation_opentype.
floatget_underline_position(font_size:int = 16)const🔗
Returns average pixel offset of the underline below the baseline.
Note: Real underline position of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate.
floatget_underline_thickness(font_size:int = 16)const🔗
Returns average thickness of the underline.
Note: Real underline thickness of the string is context-dependent and can be significantly different from the value returned by this function. Use it only as rough estimate.
Returnstrue
if a Unicodechar
is available in the font.
boolis_language_supported(language:String)const🔗
Returnstrue
, if font supports given language (ISO 639 code).
boolis_script_supported(script:String)const🔗
Returnstrue
, if font supports given script (ISO 15924 code).
voidset_cache_capacity(single_line:int, multi_line:int)🔗
Sets LRU cache capacity fordraw_*
methods.