FontFile
Holds font source data and prerendered glyph cache, imported from a dynamic or a bitmap font.
FontFile.swift:30class FontFile
FontFile
contains a set of glyphs to represent Unicode characters imported from a font file, as well as a cache of rasterized glyphs, and a set of fallback Font
s to use.
Use FontVariation
to access specific OpenType variation of the font, create simulated bold / slanted version, and draw lines of text.
For more complex text processing, use FontVariation
in conjunction with TextLine
or TextParagraph
.
Supported font formats:
Dynamic font importer: TrueType (.ttf), TrueType collection (.ttc), OpenType (.otf), OpenType collection (.otc), WOFF (.woff), WOFF2 (.woff2), Type 1 (.pfb, .pfm).
Bitmap font importer: AngelCode BMFont (.fnt, .font), text and binary (version 3) format variants.
Monospace image font importer: All supported image formats.
Superclasses
class Font
Abstract base class for fonts and font variations.
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 allowSystemFallback: Bool
If set to
true
, system fonts can be automatically used as fallbacks.var antialiasing: TextServer.FontAntialiasing
Font anti-aliasing mode.
var data: PackedByteArray
Contents of the dynamic font source file.
var fixedSize: Int32
Font size, used only for the bitmap fonts.
var fixedSizeScaleMode: TextServer.FixedSizeScaleMode
Scaling mode, used only for the bitmap fonts with
fixedSize
greater than zero.var fontName: String
Font family name.
var fontStretch: Int32
Font stretch amount, compared to a normal width. A percentage value between
50%
and200%
.var fontStyle: TextServer.FontStyle
Font style flags, see
TextServer.FontStyle
.var fontWeight: Int32
Weight (boldness) of the font. A value in the
100...999
range, normal font weight is400
, bold font weight is700
.var forceAutohinter: Bool
If set to
true
, auto-hinting is supported and preferred over font built-in hinting. Used by dynamic fonts only (MSDF fonts don’t support hinting).var generateMipmaps: Bool
If set to
true
, generate mipmaps for the font textures.var hinting: TextServer.Hinting
Font hinting mode. Used by dynamic fonts only.
var msdfPixelRange: Int32
The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines,
msdfPixelRange
must be set to at least twice the size of the largest font outline. The defaultmsdfPixelRange
value of16
allows outline sizes up to8
to look correct.var msdfSize: Int32
Source font size used to generate MSDF textures. Higher values allow for more precision, but are slower to render and require more memory. Only increase this value if you notice a visible lack of precision in glyph rendering.
var multichannelSignedDistanceField: Bool
If set to
true
, glyphs of all sizes are rendered using single multichannel signed distance field (MSDF) generated from the dynamic font vector data. Since this approach does not rely on rasterizing the font every time its size changes, this allows for resizing the font in real-time without any performance penalty. Text will also not look grainy forControl
s that are scaled down (or forLabel3D
s viewed from a long distance). As a downside, font hinting is not available with MSDF. The lack of font hinting may result in less crisp and less readable fonts at small sizes.var opentypeFeatureOverrides: GDictionary
Font OpenType feature set override.
var oversampling: Double
Font oversampling factor. If set to
0.0
, the global oversampling factor is used instead. Used by dynamic fonts only (MSDF fonts ignore oversampling).var styleName: String
Font style name.
var subpixelPositioning: TextServer.SubpixelPositioning
Font glyph subpixel positioning mode. Subpixel positioning provides shaper text and better kerning for smaller font sizes, at the cost of higher memory usage and lower font rasterization speed. Use
auto
to automatically enable it based on the font size.func clearCache(
) Removes all font cache entries.
func clearGlyphs(cacheIndex: Int32, size: Vector2i
) Removes all rendered glyphs information from the cache entry.
func clearKerningMap(cacheIndex: Int32, size: Int32
) Removes all kerning overrides.
func clearSizeCache(cacheIndex: Int32
) Removes all font sizes from the cache entry
func clearTextures(cacheIndex: Int32, size: Vector2i
) Removes all textures from font cache entry.
func getCacheAscent(cacheIndex: Int32, size: Int32
) -> Double Returns the font ascent (number of pixels above the baseline).
func getCacheCount(
) -> Int32 Returns number of the font cache entries.
func getCacheDescent(cacheIndex: Int32, size: Int32
) -> Double Returns the font descent (number of pixels below the baseline).
func getCacheScale(cacheIndex: Int32, size: Int32
) -> Double Returns scaling factor of the color bitmap font.
func getCacheUnderlinePosition(cacheIndex: Int32, size: Int32
) -> Double Returns pixel offset of the underline below the baseline.
func getCacheUnderlineThickness(cacheIndex: Int32, size: Int32
) -> Double Returns thickness of the underline in pixels.
func getCharFromGlyphIndex(size: Int32, glyphIndex: Int32
) -> Int64 Returns character code associated with
glyphIndex
, or0
ifglyphIndex
is invalid. SeegetGlyphIndex(size:char:variationSelector:)
.func getEmbolden(cacheIndex: Int32
) -> Double Returns embolden strength, if is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.
func getExtraSpacing(cacheIndex: Int32, spacing: TextServer.SpacingType
) -> Int Returns spacing for
spacing
(seeTextServer.SpacingType
) in pixels (not relative to the font size).func getFaceIndex(cacheIndex: Int32
) -> Int Returns an active face index in the TrueType / OpenType collection.
func getGlyphAdvance(cacheIndex: Int32, size: Int32, glyph: Int32
) -> Vector2 Returns glyph advance (offset of the next glyph).
func getGlyphIndex(size: Int32, char: Int64, variationSelector: Int64
) -> Int32 Returns the glyph index of a
char
, optionally modified by thevariationSelector
.func getGlyphList(cacheIndex: Int32, size: Vector2i
) -> PackedInt32Array Returns list of rendered glyphs in the cache entry.
func getGlyphOffset(cacheIndex: Int32, size: Vector2i, glyph: Int32
) -> Vector2 Returns glyph offset from the baseline.
func getGlyphSize(cacheIndex: Int32, size: Vector2i, glyph: Int32
) -> Vector2 Returns glyph size.
func getGlyphTextureIdx(cacheIndex: Int32, size: Vector2i, glyph: Int32
) -> Int32 Returns index of the cache texture containing the glyph.
func getGlyphUvRect(cacheIndex: Int32, size: Vector2i, glyph: Int32
) -> Rect2 Returns rectangle in the cache texture containing the glyph.
func getKerning(cacheIndex: Int32, size: Int32, glyphPair: Vector2i
) -> Vector2 Returns kerning for the pair of glyphs.
func getKerningList(cacheIndex: Int32, size: Int32
) -> VariantCollection<Vector2i> Returns list of the kerning overrides.
func getLanguageSupportOverride(language: String
) -> Bool Returns
true
if support override is enabled for thelanguage
.func getLanguageSupportOverrides(
) -> PackedStringArray Returns list of language support overrides.
func getScriptSupportOverride(script: String
) -> Bool Returns
true
if support override is enabled for thescript
.func getScriptSupportOverrides(
) -> PackedStringArray Returns list of script support overrides.
func getSizeCacheList(cacheIndex: Int32
) -> VariantCollection<Vector2i> Returns list of the font sizes in the cache. Each size is
Vector2i
with font size and outline size.func getTextureCount(cacheIndex: Int32, size: Vector2i
) -> Int32 Returns number of textures used by font cache entry.
func getTextureImage(cacheIndex: Int32, size: Vector2i, textureIndex: Int32
) -> Image? Returns a copy of the font cache texture image.
func getTextureOffsets(cacheIndex: Int32, size: Vector2i, textureIndex: Int32
) -> PackedInt32Array Returns a copy of the array containing glyph packing data.
func getTransform(cacheIndex: Int32
) -> Transform2D Returns 2D transform, applied to the font outlines, can be used for slanting, flipping and rotating glyphs.
func getVariationCoordinates(cacheIndex: Int32
) -> GDictionary Returns variation coordinates for the specified font cache entry. See
getSupportedVariationList
for more info.func loadBitmapFont(path: String
) -> GodotError Loads an AngelCode BMFont (.fnt, .font) bitmap font from file
path
.func loadDynamicFont(path: String
) -> GodotError Loads a TrueType (.ttf), OpenType (.otf), WOFF (.woff), WOFF2 (.woff2) or Type 1 (.pfb, .pfm) dynamic font from file
path
.func removeCache(cacheIndex: Int32
) Removes specified font cache entry.
func removeGlyph(cacheIndex: Int32, size: Vector2i, glyph: Int32
) Removes specified rendered glyph information from the cache entry.
func removeKerning(cacheIndex: Int32, size: Int32, glyphPair: Vector2i
) Removes kerning override for the pair of glyphs.
func removeLanguageSupportOverride(language: String
) Remove language support override.
func removeScriptSupportOverride(script: String
) Removes script support override.
func removeSizeCache(cacheIndex: Int32, size: Vector2i
) Removes specified font size from the cache entry.
func removeTexture(cacheIndex: Int32, size: Vector2i, textureIndex: Int32
) Removes specified texture from the cache entry.
func renderGlyph(cacheIndex: Int32, size: Vector2i, index: Int32
) Renders specified glyph to the font cache texture.
func renderRange(cacheIndex: Int32, size: Vector2i, start: Int64, end: Int64
) Renders the range of characters to the font cache texture.
func setCacheAscent(cacheIndex: Int32, size: Int32, ascent: Double
) Sets the font ascent (number of pixels above the baseline).
func setCacheDescent(cacheIndex: Int32, size: Int32, descent: Double
) Sets the font descent (number of pixels below the baseline).
func setCacheScale(cacheIndex: Int32, size: Int32, scale: Double
) Sets scaling factor of the color bitmap font.
func setCacheUnderlinePosition(cacheIndex: Int32, size: Int32, underlinePosition: Double
) Sets pixel offset of the underline below the baseline.
func setCacheUnderlineThickness(cacheIndex: Int32, size: Int32, underlineThickness: Double
) Sets thickness of the underline in pixels.
func setEmbolden(cacheIndex: Int32, strength: Double
) Sets embolden strength, if is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.
func setExtraSpacing(cacheIndex: Int32, spacing: TextServer.SpacingType, value: Int
) Sets the spacing for
spacing
(seeTextServer.SpacingType
) tovalue
in pixels (not relative to the font size).func setFaceIndex(cacheIndex: Int32, faceIndex: Int
) Sets an active face index in the TrueType / OpenType collection.
func setGlyphAdvance(cacheIndex: Int32, size: Int32, glyph: Int32, advance: Vector2
) Sets glyph advance (offset of the next glyph).
func setGlyphOffset(cacheIndex: Int32, size: Vector2i, glyph: Int32, offset: Vector2
) Sets glyph offset from the baseline.
func setGlyphSize(cacheIndex: Int32, size: Vector2i, glyph: Int32, glSize: Vector2
) Sets glyph size.
func setGlyphTextureIdx(cacheIndex: Int32, size: Vector2i, glyph: Int32, textureIdx: Int32
) Sets index of the cache texture containing the glyph.
func setGlyphUvRect(cacheIndex: Int32, size: Vector2i, glyph: Int32, uvRect: Rect2
) Sets rectangle in the cache texture containing the glyph.
func setKerning(cacheIndex: Int32, size: Int32, glyphPair: Vector2i, kerning: Vector2
) Sets kerning for the pair of glyphs.
func setLanguageSupportOverride(language: String, supported: Bool
) Adds override for
isLanguageSupported(language:)
.func setScriptSupportOverride(script: String, supported: Bool
) Adds override for
isScriptSupported(script:)
.func setTextureImage(cacheIndex: Int32, size: Vector2i, textureIndex: Int32, image: Image?
) Sets font cache texture image.
func setTextureOffsets(cacheIndex: Int32, size: Vector2i, textureIndex: Int32, offset: PackedInt32Array
) Sets array containing glyph packing data.
func setTransform(cacheIndex: Int32, transform: Transform2D
) Sets 2D transform, applied to the font outlines, can be used for slanting, flipping and rotating glyphs.
func setVariationCoordinates(cacheIndex: Int32, variationCoordinates: GDictionary
) Sets variation coordinates for the specified font cache entry. See
getSupportedVariationList
for more info.