Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    SpriteFont Class

    Namespace: Stride.Graphics
    Assembly: Stride.Graphics.dll

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

    System.Object → DisposeBase → ComponentBase → SpriteFont
    Derived from SpriteFont:

    [DataContract]
    [DataSerializerGlobal(typeof(ReferenceSerializer<SpriteFont>), null, DataSerializerGenericMode.None, false, false, Profile = "Content")]
    public class SpriteFont : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder
    Name Description
    Constructors
    SpriteFont()
    Fields
    Logger
    swizzle

    The swizzle mode to use when drawing the sprite font.

    Properties
    DefaultCharacter

    Gets or sets the default character for the font.

    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(Single) to get the value of the extra spacing for a given font size.

    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(Single) to get the value of the extra spacing for a given font size.

    FontType

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

    IgnoreUnkownCharacters

    Completely skips characters that are not in the map.

    Size

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

    Textures

    Gets the textures containing the font character data.

    Methods
    Destroy()
    GetBaseOffsetY(Single)

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

    GetExtraLineSpacing(Single)

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

    GetExtraSpacing(Single)

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

    GetFontDefaultLineSpacing(Single)

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

    GetGlyph(CommandList, Char, in Vector2, Boolean, out Vector2)

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

    GetTotalLineSpacing(Single)

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

    IsCharPresent(Char)

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

    MeasureString(String)

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

    MeasureString(String, Vector2)

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

    MeasureString(String, Vector2, Int32)

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

    MeasureString(String, ref Vector2)

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

    MeasureString(String, ref Vector2, Int32)

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

    MeasureString(String, Single)

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

    MeasureString(StringBuilder)

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

    MeasureString(StringBuilder, Vector2)

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

    MeasureString(StringBuilder, Vector2, Int32)

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

    MeasureString(StringBuilder, ref Vector2)

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

    MeasureString(StringBuilder, ref Vector2, Int32)

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

    MeasureString(StringBuilder, Single)

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

    PreGenerateGlyphs(String, Vector2)

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

    | Improve this Doc View Source

    Constructors


    SpriteFont()

    protected SpriteFont()
    | Improve this Doc View Source

    Fields


    Logger

    public static readonly Logger Logger
    Field Value
    Type Description
    Logger

    swizzle

    The swizzle mode to use when drawing the sprite font.

    protected SwizzleMode swizzle
    Field Value
    Type Description
    SwizzleMode
    | Improve this Doc View Source

    Properties


    DefaultCharacter

    Gets or sets the default character for the font.

    public char? DefaultCharacter { get; set; }
    Property Value
    Type Description
    System.Nullable<System.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(Single) to get the value of the extra spacing for a given font size.

    public float ExtraLineSpacing { get; set; }
    Property Value
    Type Description
    System.Single
    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(Single) to get the value of the extra spacing for a given font size.

    public float ExtraSpacing { get; set; }
    Property Value
    Type Description
    System.Single

    FontType

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

    public SpriteFontType FontType { get; protected set; }
    Property Value
    Type Description
    SpriteFontType

    IgnoreUnkownCharacters

    Completely skips characters that are not in the map.

    public bool IgnoreUnkownCharacters { get; set; }
    Property Value
    Type Description
    System.Boolean

    Size

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

    public float Size { get; }
    Property Value
    Type Description
    System.Single

    Textures

    Gets the textures containing the font character data.

    public virtual IReadOnlyList<Texture> Textures { get; protected set; }
    Property Value
    Type Description
    System.Collections.Generic.IReadOnlyList<Texture>
    | Improve this Doc View Source

    Methods


    Destroy()

    protected override void Destroy()
    Overrides
    ComponentBase.Destroy()

    GetBaseOffsetY(Single)

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

    protected virtual float GetBaseOffsetY(float fontSize)
    Parameters
    Type Name Description
    System.Single fontSize

    The font size in pixels

    Returns
    Type Description
    System.Single

    The value of the base offset


    GetExtraLineSpacing(Single)

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

    public virtual float GetExtraLineSpacing(float fontSize)
    Parameters
    Type Name Description
    System.Single fontSize

    The font size in pixels

    Returns
    Type Description
    System.Single

    The value of the character spacing


    GetExtraSpacing(Single)

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

    public virtual float GetExtraSpacing(float fontSize)
    Parameters
    Type Name Description
    System.Single fontSize

    The font size in pixels

    Returns
    Type Description
    System.Single

    The value of the character spacing


    GetFontDefaultLineSpacing(Single)

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

    public virtual float GetFontDefaultLineSpacing(float fontSize)
    Parameters
    Type Name Description
    System.Single fontSize

    The font size in pixels

    Returns
    Type Description
    System.Single

    The value of the default line spacing


    GetGlyph(CommandList, Char, in Vector2, Boolean, 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
    Type Name Description
    CommandList commandList

    The command list in case we upload gpu resources

    System.Char character

    The character we want the glyph of

    Vector2 fontSize

    The font size in pixel

    System.Boolean uploadGpuResources

    Indicate if the GPU resource should be uploaded or not.

    Vector2 auxiliaryScaling

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

    Returns
    Type Description
    Glyph

    The glyph corresponding to the request or null if not existing


    GetTotalLineSpacing(Single)

    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
    Type Name Description
    System.Single fontSize
    Returns
    Type Description
    System.Single
    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
    Type Name Description
    System.Char c

    The character to check.

    Returns
    Type Description
    System.Boolean

    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
    Type Name Description
    System.String text

    The string to measure.

    Returns
    Type Description
    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
    Type Name Description
    System.String text

    The string to measure.

    Vector2 fontSize

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

    Returns
    Type Description
    Vector2

    Vector2.


    MeasureString(String, Vector2, Int32)

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

    public Vector2 MeasureString(string text, Vector2 fontSize, int length)
    Parameters
    Type Name Description
    System.String text

    The string to measure.

    Vector2 fontSize

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

    System.Int32 length

    The length of the string to measure

    Returns
    Type Description
    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
    Type Name Description
    System.String text

    The string to measure.

    Vector2 fontSize

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

    Returns
    Type Description
    Vector2

    Vector2.


    MeasureString(String, ref Vector2, Int32)

    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
    Type Name Description
    System.String text

    The string to measure.

    Vector2 fontSize

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

    System.Int32 length

    The length of the string to measure

    Returns
    Type Description
    Vector2

    Vector2.


    MeasureString(String, Single)

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

    public Vector2 MeasureString(string text, float fontSize)
    Parameters
    Type Name Description
    System.String text

    The string to measure.

    System.Single fontSize

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

    Returns
    Type Description
    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
    Type Name Description
    System.Text.StringBuilder text

    The string to measure.

    Returns
    Type Description
    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
    Type Name Description
    System.Text.StringBuilder text

    The string to measure.

    Vector2 fontSize

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

    Returns
    Type Description
    Vector2

    Vector2.


    MeasureString(StringBuilder, Vector2, Int32)

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

    public Vector2 MeasureString(StringBuilder text, Vector2 fontSize, int length)
    Parameters
    Type Name Description
    System.Text.StringBuilder text

    The string to measure.

    Vector2 fontSize

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

    System.Int32 length

    The length of the string to measure

    Returns
    Type Description
    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
    Type Name Description
    System.Text.StringBuilder text

    The string to measure.

    Vector2 fontSize

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

    Returns
    Type Description
    Vector2

    Vector2.


    MeasureString(StringBuilder, ref Vector2, Int32)

    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
    Type Name Description
    System.Text.StringBuilder text

    The string to measure.

    Vector2 fontSize

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

    System.Int32 length

    The length of the string to measure

    Returns
    Type Description
    Vector2

    Vector2.


    MeasureString(StringBuilder, Single)

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

    public Vector2 MeasureString(StringBuilder text, float fontSize)
    Parameters
    Type Name Description
    System.Text.StringBuilder text

    The string to measure.

    System.Single fontSize

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

    Returns
    Type Description
    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
    Type Name Description
    System.String text

    The text containing the characters to pre-generate

    Vector2 size

    The size of the font


    Inherited Members

    ComponentBase.Tags
    ComponentBase.Name
    ComponentBase.ICollectorHolder.Collector
    ComponentBase.OnNameChanged()
    ComponentBase.ToString()
    DisposeBase.Dispose()
    DisposeBase.IsDisposed
    DisposeBase.IReferencable.ReferenceCount
    DisposeBase.IReferencable.AddReference()
    DisposeBase.IReferencable.Release()
    DisposeBase.OnAddReference()
    DisposeBase.OnReleaseReference()

    Extension Methods

    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation