Font

package
v0.0.0-...-c858641 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Abstract base class for different font types. It has methods for drawing text and font character introspection.

Index

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 Any

type Any interface {
	gd.IsClass
	AsFont() Instance
}

type Expanded

type Expanded [1]gdclass.Font

func (Expanded) DrawChar

func (self Expanded) DrawChar(canvas_item RID.CanvasItem, pos Vector2.XY, char int, font_size int, modulate Color.RGBA) Float.X

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 Instance.DrawString or graphics.gd/classdb/TextLine instead.

func (Expanded) DrawCharOutline

func (self Expanded) DrawCharOutline(canvas_item RID.CanvasItem, pos Vector2.XY, char int, font_size int, size int, modulate Color.RGBA) Float.X

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 Instance.DrawString or graphics.gd/classdb/TextLine instead.

func (Expanded) DrawMultilineString

func (self Expanded) DrawMultilineString(canvas_item RID.CanvasItem, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, max_lines int, modulate Color.RGBA, brk_flags TextServer.LineBreakFlag, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation)

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 graphics.gd/classdb/CanvasItem.Instance.DrawMultilineString.

func (Expanded) DrawMultilineStringOutline

func (self Expanded) DrawMultilineStringOutline(canvas_item RID.CanvasItem, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, max_lines int, size int, modulate Color.RGBA, brk_flags TextServer.LineBreakFlag, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation)

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 graphics.gd/classdb/CanvasItem.Instance.DrawMultilineStringOutline.

func (Expanded) DrawString

func (self Expanded) DrawString(canvas_item RID.CanvasItem, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, modulate Color.RGBA, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation)

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 graphics.gd/classdb/CanvasItem.Instance.DrawString.

func (Expanded) DrawStringOutline

func (self Expanded) DrawStringOutline(canvas_item RID.CanvasItem, pos Vector2.XY, text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, size int, modulate Color.RGBA, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation)

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 graphics.gd/classdb/CanvasItem.Instance.DrawStringOutline.

func (Expanded) FindVariation

func (self Expanded) FindVariation(variation_coordinates map[string]float32, face_index int, strength Float.X, transform Transform2D.OriginXY, spacing_top int, spacing_bottom int, spacing_space int, spacing_glyph int, baseline_offset Float.X) RID.Font

Returns graphics.gd/classdb/TextServer RID of the font cache for specific variation.

func (Expanded) GetAscent

func (self Expanded) GetAscent(font_size int) Float.X

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).

func (Expanded) GetDescent

func (self Expanded) GetDescent(font_size int) Float.X

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).

func (Expanded) GetHeight

func (self Expanded) GetHeight(font_size int) Float.X

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).

func (Expanded) GetMultilineStringSize

func (self Expanded) GetMultilineStringSize(text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, max_lines int, brk_flags TextServer.LineBreakFlag, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation) Vector2.XY

Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account.

See also Instance.DrawMultilineString.

func (Expanded) GetStringSize

func (self Expanded) GetStringSize(text string, alignment GUI.HorizontalAlignment, width Float.X, font_size int, justification_flags TextServer.JustificationFlag, direction TextServer.Direction, orientation TextServer.Orientation) Vector2.XY

Returns the size of a bounding box of a single-line string, taking kerning, advance and subpixel positioning into account. See also Instance.GetMultilineStringSize and Instance.DrawString.

For example, to get the string size as displayed by a single-line Label, use:

Note: Since kerning, advance and subpixel positioning are taken into account by Instance.GetStringSize, using separate Instance.GetStringSize calls on substrings of a string then adding the results together will return a different result compared to using a single Instance.GetStringSize call on the full string.

Note: Real height of the string is context-dependent and can be significantly different from the value returned by Instance.GetHeight.

func (Expanded) GetUnderlinePosition

func (self Expanded) GetUnderlinePosition(font_size int) Float.X

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.

func (Expanded) GetUnderlineThickness

func (self Expanded) GetUnderlineThickness(font_size int) Float.X

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.

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsFont

func (self *Extension[T]) AsFont() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Font

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsFont

func (self Instance) AsFont() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

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 '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 Instance.DrawString or graphics.gd/classdb/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 '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 Instance.DrawString or graphics.gd/classdb/TextLine instead.

func (Instance) DrawMultilineString

func (self Instance) DrawMultilineString(canvas_item RID.CanvasItem, pos Vector2.XY, text string)

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 graphics.gd/classdb/CanvasItem.Instance.DrawMultilineString.

func (Instance) DrawMultilineStringOutline

func (self Instance) DrawMultilineStringOutline(canvas_item RID.CanvasItem, pos Vector2.XY, text string)

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 graphics.gd/classdb/CanvasItem.Instance.DrawMultilineStringOutline.

func (Instance) DrawString

func (self Instance) DrawString(canvas_item RID.CanvasItem, pos Vector2.XY, text string)

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 graphics.gd/classdb/CanvasItem.Instance.DrawString.

func (Instance) DrawStringOutline

func (self Instance) DrawStringOutline(canvas_item RID.CanvasItem, pos Vector2.XY, text string)

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 graphics.gd/classdb/CanvasItem.Instance.DrawStringOutline.

func (Instance) Fallbacks

func (self Instance) Fallbacks() []Instance

func (Instance) FindVariation

func (self Instance) FindVariation(variation_coordinates map[string]float32) RID.Font

Returns graphics.gd/classdb/TextServer RID of the font cache for specific variation.

func (Instance) GetAscent

func (self Instance) GetAscent() Float.X

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).

func (Instance) GetCharSize

func (self Instance) GetCharSize(char int, font_size int) Vector2.XY

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 Instance.GetStringSize or graphics.gd/classdb/TextLine instead. The height returned is the font height (see also Instance.GetHeight) and has no relation to the glyph height.

func (Instance) GetDescent

func (self Instance) GetDescent() Float.X

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).

func (Instance) GetFaceCount

func (self Instance) GetFaceCount() int

Returns number of faces in the TrueType / OpenType collection.

func (Instance) GetFontName

func (self Instance) GetFontName() string

Returns font family name.

func (Instance) GetFontStretch

func (self Instance) GetFontStretch() int

Returns font stretch amount, compared to a normal width. A percentage value between 50% and 200%.

func (Instance) GetFontStyle

func (self Instance) GetFontStyle() TextServer.FontStyle

Returns font style flags, see [TextServer.FontStyle].

func (Instance) GetFontStyleName

func (self Instance) GetFontStyleName() string

Returns font style name.

func (Instance) GetFontWeight

func (self Instance) GetFontWeight() int

Returns weight (boldness) of the font. A value in the 100...999 range, normal font weight is 400, bold font weight is 700.

func (Instance) GetHeight

func (self Instance) GetHeight() Float.X

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).

func (Instance) GetMultilineStringSize

func (self Instance) GetMultilineStringSize(text string) Vector2.XY

Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account.

See also Instance.DrawMultilineString.

func (Instance) GetOpentypeFeatures

func (self Instance) GetOpentypeFeatures() map[string][2]string

Returns a set of OpenType feature tags. More info: OpenType feature tags.

func (Instance) GetOtNameStrings

func (self Instance) GetOtNameStrings() map[string]map[string]string

Returns data structure with OpenType font name strings (localized font names, version, description, license information, sample text, etc.).

func (Instance) GetRids

func (self Instance) GetRids() [][]RID.Font

Returns slice of valid graphics.gd/classdb/Font [Resource.ID]s, which can be passed to the graphics.gd/classdb/TextServer methods.

func (Instance) GetSpacing

func (self Instance) GetSpacing(spacing TextServer.SpacingType) int

Returns the spacing for the given type (see [TextServer.SpacingType]).

func (Instance) GetStringSize

func (self Instance) GetStringSize(text string) Vector2.XY

Returns the size of a bounding box of a single-line string, taking kerning, advance and subpixel positioning into account. See also Instance.GetMultilineStringSize and Instance.DrawString.

For example, to get the string size as displayed by a single-line Label, use:

Note: Since kerning, advance and subpixel positioning are taken into account by Instance.GetStringSize, using separate Instance.GetStringSize calls on substrings of a string then adding the results together will return a different result compared to using a single Instance.GetStringSize call on the full string.

Note: Real height of the string is context-dependent and can be significantly different from the value returned by Instance.GetHeight.

func (Instance) GetSupportedChars

func (self Instance) GetSupportedChars() string

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

func (self Instance) GetSupportedFeatureList() map[string]OpenTypeFeature

Returns list of OpenType features supported by font.

func (Instance) GetSupportedVariationList

func (self Instance) GetSupportedVariationList() map[string]map[string]struct {
	X int32
	Y int32
	Z int32
}

Returns list of supported variation coordinates, each coordinate is returned as tag: 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:

Note: To set and get variation coordinates of a graphics.gd/classdb/FontVariation, use graphics.gd/classdb/FontVariation.Instance.VariationOpentype.

func (Instance) GetUnderlinePosition

func (self Instance) GetUnderlinePosition() Float.X

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.

func (Instance) GetUnderlineThickness

func (self Instance) GetUnderlineThickness() Float.X

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.

func (Instance) HasChar

func (self Instance) HasChar(char int) bool

Returns true if a Unicode 'char' is available in the font.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) IsLanguageSupported

func (self Instance) IsLanguageSupported(language string) bool

Returns true, if font supports given language (ISO 639 code).

func (Instance) IsScriptSupported

func (self Instance) IsScriptSupported(script string) bool

Returns true, if font supports given script (ISO 15924 code).

func (Instance) SetCacheCapacity

func (self Instance) SetCacheCapacity(single_line int, multi_line int)

Sets LRU cache capacity for draw_* methods.

func (Instance) SetFallbacks

func (self Instance) SetFallbacks(value []Instance)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type OpenTypeFeature

type OpenTypeFeature struct {
	Label  string       `gd:"label"`
	Type   reflect.Type `gd:"type"`
	Hidden bool         `gd:"hidden"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL