Documentation
¶
Overview ¶
Package Font provides methods for working with Font object instances.
Index ¶
- type Advanced
- type Any
- type HorizontalAlignment
- type Instance
- func (self Instance) AsFont() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) DrawChar(canvas_item RID.CanvasItem, pos Vector2.XY, char int, font_size int) Float.X
- func (self Instance) DrawCharOutline(canvas_item RID.CanvasItem, pos Vector2.XY, char int, font_size int) Float.X
- func (self Instance) DrawMultilineString(canvas_item RID.CanvasItem, pos Vector2.XY, text string)
- func (self Instance) DrawMultilineStringOutline(canvas_item RID.CanvasItem, pos Vector2.XY, text string)
- func (self Instance) DrawString(canvas_item RID.CanvasItem, pos Vector2.XY, text string)
- func (self Instance) DrawStringOutline(canvas_item RID.CanvasItem, pos Vector2.XY, text string)
- func (self Instance) Fallbacks() [][1]gdclass.Font
- func (self Instance) FindVariation(variation_coordinates map[string]float32) RID.Font
- func (self Instance) GetAscent() Float.X
- func (self Instance) GetCharSize(char int, font_size int) Vector2.XY
- func (self Instance) GetDescent() Float.X
- func (self Instance) GetFaceCount() int
- func (self Instance) GetFontName() string
- func (self Instance) GetFontStretch() int
- func (self Instance) GetFontStyle() gdclass.TextServerFontStyle
- func (self Instance) GetFontStyleName() string
- func (self Instance) GetFontWeight() int
- func (self Instance) GetHeight() Float.X
- func (self Instance) GetMultilineStringSize(text string) Vector2.XY
- func (self Instance) GetOpentypeFeatures() map[string]string
- func (self Instance) GetOtNameStrings() map[string]string
- func (self Instance) GetRids() [][]RID.Font
- func (self Instance) GetSpacing(spacing gdclass.TextServerSpacingType) int
- func (self Instance) GetStringSize(text string) Vector2.XY
- func (self Instance) GetSupportedChars() string
- func (self Instance) GetSupportedFeatureList() map[string]string
- func (self Instance) GetSupportedVariationList() map[string]string
- func (self Instance) GetUnderlinePosition() Float.X
- func (self Instance) GetUnderlineThickness() Float.X
- func (self Instance) HasChar(char int) bool
- func (self Instance) IsLanguageSupported(language string) bool
- func (self Instance) IsScriptSupported(script string) bool
- func (self Instance) SetCacheCapacity(single_line int, multi_line int)
- func (self Instance) SetFallbacks(value [][1]gdclass.Font)
- func (self *Instance) UnsafePointer() unsafe.Pointer
- func (self Instance) Virtual(name string) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type HorizontalAlignment ¶
type HorizontalAlignment int
const ( /*Horizontal left alignment, usually for text-derived classes.*/ HorizontalAlignmentLeft HorizontalAlignment = 0 /*Horizontal center alignment, usually for text-derived classes.*/ HorizontalAlignmentCenter HorizontalAlignment = 1 /*Horizontal right alignment, usually for text-derived classes.*/ HorizontalAlignmentRight HorizontalAlignment = 2 /*Expand row to fit width, usually for text-derived classes.*/ HorizontalAlignmentFill HorizontalAlignment = 3 )
type Instance ¶
Abstract base class for different font types. It has methods for drawing text and font character introspection.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
func (Instance) DrawChar ¶
func (self Instance) DrawChar(canvas_item RID.CanvasItem, pos Vector2.XY, char int, font_size int) Float.X
Draw a single Unicode character [param char] into a canvas item using the font, at a given position, with [param modulate] color. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. [b]Note:[/b] Do not use this function to draw strings character by character, use [method draw_string] or [TextLine] instead.
func (Instance) DrawCharOutline ¶
func (self Instance) DrawCharOutline(canvas_item RID.CanvasItem, pos Vector2.XY, char int, font_size int) Float.X
Draw a single Unicode character [param char] outline into a canvas item using the font, at a given position, with [param modulate] color and [param size] outline size. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. [b]Note:[/b] Do not use this function to draw strings character by character, use [method draw_string] or [TextLine] instead.
func (Instance) DrawMultilineString ¶
Breaks [param text] into lines using rules specified by [param brk_flags] and draws it into a canvas item using the font, at a given position, with [param modulate] color, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. See also [method CanvasItem.draw_multiline_string].
func (Instance) DrawMultilineStringOutline ¶
func (self Instance) DrawMultilineStringOutline(canvas_item RID.CanvasItem, pos Vector2.XY, text string)
Breaks [param text] to the lines using rules specified by [param brk_flags] and draws text outline into a canvas item using the font, at a given position, with [param modulate] color and [param size] outline size, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline of the first line, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. See also [method CanvasItem.draw_multiline_string_outline].
func (Instance) DrawString ¶
Draw [param text] into a canvas item using the font, at a given position, with [param modulate] color, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. See also [method CanvasItem.draw_string].
func (Instance) DrawStringOutline ¶
Draw [param text] outline into a canvas item using the font, at a given position, with [param modulate] color and [param size] outline size, optionally clipping the width and aligning horizontally. [param pos] specifies the baseline, not the top. To draw from the top, [i]ascent[/i] must be added to the Y axis. See also [method CanvasItem.draw_string_outline].
func (Instance) FindVariation ¶
Returns [TextServer] RID of the font cache for specific variation.
func (Instance) GetAscent ¶
Returns the average font ascent (number of pixels above the baseline). [b]Note:[/b] 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).
func (Instance) GetCharSize ¶
Returns the size of a character. Does not take kerning into account. [b]Note:[/b] Do not use this function to calculate width of the string character by character, use [method get_string_size] or [TextLine] instead. The height returned is the font height (see also [method get_height]) and has no relation to the glyph height.
func (Instance) GetDescent ¶
Returns the average font descent (number of pixels below the baseline). [b]Note:[/b] 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).
func (Instance) GetFaceCount ¶
Returns number of faces in the TrueType / OpenType collection.
func (Instance) GetFontStretch ¶
Returns font stretch amount, compared to a normal width. A percentage value between [code]50%[/code] and [code]200%[/code].
func (Instance) GetFontStyle ¶
func (self Instance) GetFontStyle() gdclass.TextServerFontStyle
Returns font style flags, see [enum TextServer.FontStyle].
func (Instance) GetFontStyleName ¶
Returns font style name.
func (Instance) GetFontWeight ¶
Returns weight (boldness) of the font. A value in the [code]100...999[/code] range, normal font weight is [code]400[/code], bold font weight is [code]700[/code].
func (Instance) GetHeight ¶
Returns the total average font height (ascent plus descent) in pixels. [b]Note:[/b] 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).
func (Instance) GetMultilineStringSize ¶
Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account. See also [method draw_multiline_string].
func (Instance) GetOpentypeFeatures ¶
Returns a set of OpenType feature tags. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url].
func (Instance) GetOtNameStrings ¶
Returns [Dictionary] with OpenType font name strings (localized font names, version, description, license information, sample text, etc.).
func (Instance) GetRids ¶
Returns [Array] of valid [Font] [RID]s, which can be passed to the [TextServer] methods.
func (Instance) GetSpacing ¶
func (self Instance) GetSpacing(spacing gdclass.TextServerSpacingType) int
Returns the spacing for the given [code]type[/code] (see [enum TextServer.SpacingType]).
func (Instance) GetStringSize ¶
Returns the size of a bounding box of a single-line string, taking kerning, advance and subpixel positioning into account. See also [method get_multiline_string_size] and [method draw_string]. For example, to get the string size as displayed by a single-line Label, use: [codeblocks] [gdscript] var string_size = $Label.get_theme_font("font").get_string_size($Label.text, HORIZONTAL_ALIGNMENT_LEFT, -1, $Label.get_theme_font_size("font_size")) [/gdscript] [csharp] Label label = GetNode<Label>("Label"); Vector2 stringSize = label.GetThemeFont("font").GetStringSize(label.Text, HorizontalAlignment.Left, -1, label.GetThemeFontSize("font_size")); [/csharp] [/codeblocks] [b]Note:[/b] Since kerning, advance and subpixel positioning are taken into account by [method get_string_size], using separate [method get_string_size] calls on substrings of a string then adding the results together will return a different result compared to using a single [method get_string_size] call on the full string. [b]Note:[/b] Real height of the string is context-dependent and can be significantly different from the value returned by [method get_height].
func (Instance) GetSupportedChars ¶
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.
func (Instance) GetSupportedFeatureList ¶
Returns list of OpenType features supported by font.
func (Instance) GetSupportedVariationList ¶
Returns list of supported [url=https://docs.microsoft.com/en-us/typography/opentype/spec/dvaraxisreg]variation coordinates[/url], each coordinate is returned as [code]tag: Vector3i(min_value,max_value,default_value)[/code]. 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: [codeblock] var fv = FontVariation.new() fv.base_font = load("res://RobotoFlex.ttf") var variation_list = fv.get_supported_variation_list() for tag in variation_list:
var name = TextServerManager.get_primary_interface().tag_to_name(tag) var values = variation_list[tag] print("variation axis: %s (%d)\n\tmin, max, default: %s" % [name, tag, values])
[/codeblock] [b]Note:[/b] To set and get variation coordinates of a [FontVariation], use [member FontVariation.variation_opentype].
func (Instance) GetUnderlinePosition ¶
Returns average pixel offset of the underline below the baseline. [b]Note:[/b] 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.
func (Instance) GetUnderlineThickness ¶
Returns average thickness of the underline. [b]Note:[/b] 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.
func (Instance) HasChar ¶
Returns [code]true[/code] if a Unicode [param char] is available in the font.
func (Instance) IsLanguageSupported ¶
Returns [code]true[/code], if font supports given language ([url=https://en.wikipedia.org/wiki/ISO_639-1]ISO 639[/url] code).
func (Instance) IsScriptSupported ¶
Returns [code]true[/code], if font supports given script ([url=https://en.wikipedia.org/wiki/ISO_15924]ISO 15924[/url] code).
func (Instance) SetCacheCapacity ¶
Sets LRU cache capacity for [code]draw_*[/code] methods.