Table of Contents

Class SpriteFont

Namespace
Stride.Graphics
Assembly
Stride.Graphics.dll

SpriteFont to use with SpriteBatch. See SpriteFont to learn how to use it.

[DataContract]
[DataSerializerGlobal(typeof(ReferenceSerializer<SpriteFont>), null, DataSerializerGenericMode.None, false, false, Profile = "Content")]
public class SpriteFont : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder
Inheritance
SpriteFont
Implements
Inherited Members
Extension Methods

Constructors

SpriteFont()

protected SpriteFont()

Fields

Logger

public static readonly Logger Logger

Field Value

Logger

swizzle

The swizzle mode to use when drawing the sprite font.

protected SwizzleMode swizzle

Field Value

SwizzleMode

Properties

DefaultCharacter

Gets or sets the default character for the font.

public char? DefaultCharacter { get; set; }

Property Value

char?

ExtraLineSpacing

Gets or sets the extra line spacing (in pixels) to add to the default font line spacing for the current font Size. This value will be scaled during the draw in the case of dynamic fonts. Use GetExtraLineSpacing(float) to get the value of the extra spacing for a given font size.

public float ExtraLineSpacing { get; set; }

Property Value

float

Remarks

Line spacing is the distance between the base lines of two consecutive lines of text (blank space as well as characters' height are thus included).

ExtraSpacing

Gets or sets extra spacing (in pixels) between the characters for the current font Size. This value is scaled during the draw in the case of dynamic fonts. Use GetExtraSpacing(float) to get the value of the extra spacing for a given font size.

public float ExtraSpacing { get; set; }

Property Value

float

FontType

Gets the type indicating if the current font is static, dynamic or SDF.

public SpriteFontType FontType { get; protected set; }

Property Value

SpriteFontType

IgnoreUnkownCharacters

Completely skips characters that are not in the map.

public bool IgnoreUnkownCharacters { get; set; }

Property Value

bool

Size

Gets the font size (resp. the default font size) for static fonts (resp. for dynamic fonts) in pixels.

[DataMember]
public float Size { get; }

Property Value

float

Textures

Gets the textures containing the font character data.

public virtual IReadOnlyList<Texture> Textures { get; protected set; }

Property Value

IReadOnlyList<Texture>

Methods

Destroy()

Disposes of object resources.

protected override void Destroy()

GetBaseOffsetY(float)

Get the value of the base offset for the given font size.

protected virtual float GetBaseOffsetY(float fontSize)

Parameters

fontSize float

The font size in pixels

Returns

float

The value of the base offset

GetExtraLineSpacing(float)

Get the value of the extra character spacing for the given font size.

public virtual float GetExtraLineSpacing(float fontSize)

Parameters

fontSize float

The font size in pixels

Returns

float

The value of the character spacing

GetExtraSpacing(float)

Get the value of the extra line spacing for the given font size.

public virtual float GetExtraSpacing(float fontSize)

Parameters

fontSize float

The font size in pixels

Returns

float

The value of the character spacing

GetFontDefaultLineSpacing(float)

Get the value of the font default line spacing for the given font size.

public virtual float GetFontDefaultLineSpacing(float fontSize)

Parameters

fontSize float

The font size in pixels

Returns

float

The value of the default line spacing

GetGlyph(CommandList, char, in Vector2, bool, out Vector2)

Return the glyph associated to provided character at the given size.

protected virtual Glyph GetGlyph(CommandList commandList, char character, in Vector2 fontSize, bool uploadGpuResources, out Vector2 auxiliaryScaling)

Parameters

commandList CommandList

The command list in case we upload gpu resources

character char

The character we want the glyph of

fontSize Vector2

The font size in pixel

uploadGpuResources bool

Indicate if the GPU resource should be uploaded or not.

auxiliaryScaling Vector2

If the requested font size isn't available, the closest one is chosen and an auxiliary scaling is returned

Returns

Glyph

The glyph corresponding to the request or null if not existing

GetTotalLineSpacing(float)

Gets the value of the total line spacing (font default + user defined) in pixels for a given font size.

public float GetTotalLineSpacing(float fontSize)

Parameters

fontSize float

Returns

float

Remarks

Line spacing is the distance between the base lines of two consecutive lines of text (blank space as well as characters' height are thus included).

IsCharPresent(char)

Checks whether the provided character is present in the character map of the current SpriteFont.

public virtual bool IsCharPresent(char c)

Parameters

c char

The character to check.

Returns

bool

true if the c is present in the character map, false - otherwise.

MeasureString(string)

Returns the width and height of the provided text for the current font size Size

public Vector2 MeasureString(string text)

Parameters

text string

The string to measure.

Returns

Vector2

Vector2.

MeasureString(string, Vector2)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(string text, Vector2 fontSize)

Parameters

text string

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

Returns

Vector2

Vector2.

MeasureString(string, Vector2, int)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(string text, Vector2 fontSize, int length)

Parameters

text string

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

length int

The length of the string to measure

Returns

Vector2

Vector2.

MeasureString(string, ref Vector2)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(string text, ref Vector2 fontSize)

Parameters

text string

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

Returns

Vector2

Vector2.

MeasureString(string, ref Vector2, int)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(string text, ref Vector2 fontSize, int length)

Parameters

text string

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

length int

The length of the string to measure

Returns

Vector2

Vector2.

MeasureString(string, float)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(string text, float fontSize)

Parameters

text string

The string to measure.

fontSize float

The size of the font (ignored in the case of static fonts)

Returns

Vector2

Vector2.

MeasureString(StringBuilder)

Returns the width and height of the provided text for the current font size Size

public Vector2 MeasureString(StringBuilder text)

Parameters

text StringBuilder

The string to measure.

Returns

Vector2

Vector2.

MeasureString(StringBuilder, Vector2)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(StringBuilder text, Vector2 fontSize)

Parameters

text StringBuilder

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

Returns

Vector2

Vector2.

MeasureString(StringBuilder, Vector2, int)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(StringBuilder text, Vector2 fontSize, int length)

Parameters

text StringBuilder

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

length int

The length of the string to measure

Returns

Vector2

Vector2.

MeasureString(StringBuilder, ref Vector2)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(StringBuilder text, ref Vector2 fontSize)

Parameters

text StringBuilder

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

Returns

Vector2

Vector2.

MeasureString(StringBuilder, ref Vector2, int)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(StringBuilder text, ref Vector2 fontSize, int length)

Parameters

text StringBuilder

The string to measure.

fontSize Vector2

The size of the font (ignored in the case of static fonts)

length int

The length of the string to measure

Returns

Vector2

Vector2.

MeasureString(StringBuilder, float)

Returns the width and height of the provided text for a given font size

public Vector2 MeasureString(StringBuilder text, float fontSize)

Parameters

text StringBuilder

The string to measure.

fontSize float

The size of the font (ignored in the case of static fonts)

Returns

Vector2

Vector2.

PreGenerateGlyphs(string, Vector2)

Pre-generate synchronously the glyphs of the character needed to render the provided text at the provided size.

public void PreGenerateGlyphs(string text, Vector2 size)

Parameters

text string

The text containing the characters to pre-generate

size Vector2

The size of the font