Font
Abstract base class for fonts and font variations.
Font.swift:11class Font
Abstract base class for different font types. It has methods for drawing text and font character introspection.
Superclasses
class Resource
Base class for serializable objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var fallbacks: ObjectCollection<Font>
Array of fallback
Font
s to use as a substitute if a glyph is not found in this currentFont
.func drawChar(canvasItem: RID, pos: Vector2, char: Int64, fontSize: Int32, modulate: Color
) -> Double Draw a single Unicode character
char
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.func drawCharOutline(canvasItem: RID, pos: Vector2, char: Int64, fontSize: Int32, size: Int32, modulate: Color
) -> Double Draw a single Unicode character
char
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.func drawMultilineString(canvasItem: RID, pos: Vector2, text: String, alignment: HorizontalAlignment, width: Double, fontSize: Int32, maxLines: Int32, modulate: Color, brkFlags: TextServer.LineBreakFlag, justificationFlags: TextServer.JustificationFlag, direction: TextServer.Direction, orientation: TextServer.Orientation
) Breaks
text
into lines using rules specified bybrkFlags
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.func drawMultilineStringOutline(canvasItem: RID, pos: Vector2, text: String, alignment: HorizontalAlignment, width: Double, fontSize: Int32, maxLines: Int32, size: Int32, modulate: Color, brkFlags: TextServer.LineBreakFlag, justificationFlags: TextServer.JustificationFlag, direction: TextServer.Direction, orientation: TextServer.Orientation
) Breaks
text
to the lines using rules specified bybrkFlags
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.func drawString(canvasItem: RID, pos: Vector2, text: String, alignment: HorizontalAlignment, width: Double, fontSize: Int32, modulate: Color, justificationFlags: TextServer.JustificationFlag, direction: TextServer.Direction, orientation: TextServer.Orientation
) Draw
text
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.func drawStringOutline(canvasItem: RID, pos: Vector2, text: String, alignment: HorizontalAlignment, width: Double, fontSize: Int32, size: Int32, modulate: Color, justificationFlags: TextServer.JustificationFlag, direction: TextServer.Direction, orientation: TextServer.Orientation
) Draw
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, not the top. To draw from the top, ascent must be added to the Y axis.func findVariation(variationCoordinates: GDictionary, faceIndex: Int32, strength: Double, transform: Transform2D, spacingTop: Int32, spacingBottom: Int32, spacingSpace: Int32, spacingGlyph: Int32
) -> RID Returns
TextServer
RID of the font cache for specific variation.func getAscent(fontSize: Int32
) -> Double Returns the average font ascent (number of pixels above the baseline).
func getCharSize(char: Int64, fontSize: Int32
) -> Vector2 Returns the size of a character, optionally taking kerning into account if the next character is provided.
func getDescent(fontSize: Int32
) -> Double Returns the average font descent (number of pixels below the baseline).
func getFaceCount(
) -> Int Returns number of faces in the TrueType / OpenType collection.
func getFontName(
) -> String Returns font family name.
func getFontStretch(
) -> Int32 Returns font stretch amount, compared to a normal width. A percentage value between
50%
and200%
.func getFontStyle(
) -> TextServer.FontStyle Returns font style flags, see
TextServer.FontStyle
.func getFontStyleName(
) -> String Returns font style name.
func getFontWeight(
) -> Int32 Returns weight (boldness) of the font. A value in the
100...999
range, normal font weight is400
, bold font weight is700
.func getHeight(fontSize: Int32
) -> Double Returns the total average font height (ascent plus descent) in pixels.
func getMultilineStringSize(text: String, alignment: HorizontalAlignment, width: Double, fontSize: Int32, maxLines: Int32, brkFlags: TextServer.LineBreakFlag, justificationFlags: TextServer.JustificationFlag, direction: TextServer.Direction, orientation: TextServer.Orientation
) -> Vector2 Returns the size of a bounding box of a string broken into the lines, taking kerning and advance into account.
func getOpentypeFeatures(
) -> GDictionary Returns a set of OpenType feature tags. More info: OpenType feature tags.
func getOtNameStrings(
) -> GDictionary Returns
GDictionary
with OpenType font name strings (localized font names, version, description, license information, sample text, etc.).func getRids(
) -> VariantCollection<RID> Returns
GArray
of validFont
RID
s, which can be passed to theTextServer
methods.func getSpacing(TextServer.SpacingType
) -> Int32 Returns the spacing for the given
type
(seeTextServer.SpacingType
).func getStringSize(text: String, alignment: HorizontalAlignment, width: Double, fontSize: Int32, justificationFlags: TextServer.JustificationFlag, direction: TextServer.Direction, orientation: TextServer.Orientation
) -> Vector2 Returns the size of a bounding box of a single-line string, taking kerning, advance and subpixel positioning into account. See also
getMultilineStringSize(text:alignment:width:fontSize:maxLines:brkFlags:justificationFlags:direction:orientation:)
anddrawString(canvasItem:pos:text:alignment:width:fontSize:modulate:justificationFlags:direction:orientation:)
.func getSupportedChars(
) -> String Returns a string containing all the characters available in the font.
func getSupportedFeatureList(
) -> GDictionary Returns list of OpenType features supported by font.
func getSupportedVariationList(
) -> GDictionary Returns list of supported variation coordinates, each coordinate is returned as
tag: Vector3i(min_value,max_value,default_value)
.func getUnderlinePosition(fontSize: Int32
) -> Double Returns average pixel offset of the underline below the baseline.
func getUnderlineThickness(fontSize: Int32
) -> Double Returns average thickness of the underline.
func hasChar(Int64
) -> Bool Returns
true
if a Unicodechar
is available in the font.func isLanguageSupported(language: String
) -> Bool Returns
true
, if font supports given language (ISO 639 code).func isScriptSupported(script: String
) -> Bool Returns
true
, if font supports given script (ISO 15924 code).func setCacheCapacity(singleLine: Int32, multiLine: Int32
) Sets LRU cache capacity for
draw_*
methods.
Subclasses
class FontFile
Holds font source data and prerendered glyph cache, imported from a dynamic or a bitmap font.
class FontVariation
A variation of a font with additional settings.
class SystemFont
A font loaded from a system font. Falls back to a default theme font if not implemented on the host OS.