Class SpriteFont
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
- 
      objectSpriteFont
- Implements
- Inherited Members
- Extension Methods
Constructors
SpriteFont()
protected SpriteFont()Fields
Logger
public static readonly Logger LoggerField Value
swizzle
The swizzle mode to use when drawing the sprite font.
protected SwizzleMode swizzleField Value
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
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
FontType
Gets the type indicating if the current font is static, dynamic or SDF.
public SpriteFontType FontType { get; protected set; }Property Value
IgnoreUnkownCharacters
Completely skips characters that are not in the map.
public bool IgnoreUnkownCharacters { get; set; }Property Value
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
Textures
Gets the textures containing the font character data.
public virtual IReadOnlyList<Texture> Textures { get; protected set; }Property Value
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
- fontSizefloat
- 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
- fontSizefloat
- 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
- fontSizefloat
- 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
- fontSizefloat
- 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
- commandListCommandList
- The command list in case we upload gpu resources 
- characterchar
- The character we want the glyph of 
- fontSizeVector2
- The font size in pixel 
- uploadGpuResourcesbool
- Indicate if the GPU resource should be uploaded or not. 
- auxiliaryScalingVector2
- 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
- fontSizefloat
Returns
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
- cchar
- The character to check. 
Returns
- bool
- true if the - cis 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
- textstring
- 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
- textstring
- The string to measure. 
- fontSizeVector2
- 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
- textstring
- The string to measure. 
- fontSizeVector2
- The size of the font (ignored in the case of static fonts) 
- lengthint
- 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
- textstring
- The string to measure. 
- fontSizeVector2
- 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
- textstring
- The string to measure. 
- fontSizeVector2
- The size of the font (ignored in the case of static fonts) 
- lengthint
- 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
- textstring
- The string to measure. 
- fontSizefloat
- 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
- textStringBuilder
- 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
- textStringBuilder
- The string to measure. 
- fontSizeVector2
- 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
- textStringBuilder
- The string to measure. 
- fontSizeVector2
- The size of the font (ignored in the case of static fonts) 
- lengthint
- 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
- textStringBuilder
- The string to measure. 
- fontSizeVector2
- 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
- textStringBuilder
- The string to measure. 
- fontSizeVector2
- The size of the font (ignored in the case of static fonts) 
- lengthint
- 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
- textStringBuilder
- The string to measure. 
- fontSizefloat
- 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)