Show / Hide Table of Contents

Class SadFont

Represents a graphical font used by SadConsole.

Inheritance
object
SadFont
Implements
IFont
IDisposable
Inherited Members
object.GetType()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: SadConsole
Assembly: SadConsole.dll
Syntax
[DataContract]
public sealed class SadFont : IFont, IDisposable

Constructors

SadFont(int, int, int, int, int, int, ITexture, string, Dictionary<int, Rectangle>?)

Creates a new font with the specified settings.

Declaration
public SadFont(int glyphWidth, int glyphHeight, int glyphPadding, int rows, int columns, int solidGlyphIndex, ITexture image, string name, Dictionary<int, Rectangle>? glyphRectangles = null)
Parameters
Type Name Description
int glyphWidth

The pixel width of each glyph.

int glyphHeight

The pixel height of each glyph.

int glyphPadding

The pixel padding between each glyph.

int rows

Number of glyph rows in the image.

int columns

Number of glyph columns in the image.

int solidGlyphIndex

The index of the glyph that is a solid white box.

ITexture image

The ITexture of the font.

string name

A font identifier used for serialization of resources using this font.

Dictionary<int, Rectangle> glyphRectangles

Glyph mapping dictionary.

Properties

Columns

Declaration
[DataMember]
public int Columns { get; set; }
Property Value
Type Description
int

FilePath

The name of the image file as defined in the .font file.

Declaration
[DataMember]
public string FilePath { get; set; }
Property Value
Type Description
string

GlyphDefinitions

A collection of named glyph definitions.

Declaration
[DataMember]
public Dictionary<string, GlyphDefinition> GlyphDefinitions { get; set; }
Property Value
Type Description
Dictionary<string, GlyphDefinition>

GlyphHeight

The height of each glyph in pixels.

Declaration
[DataMember]
public int GlyphHeight { get; set; }
Property Value
Type Description
int

GlyphPadding

The amount of pixels between glyphs.

Declaration
[DataMember]
public int GlyphPadding { get; set; }
Property Value
Type Description
int

GlyphRectangles

A dictionary that stores the source rectangles of the font by glyph id.

Declaration
public Dictionary<int, Rectangle> GlyphRectangles { get; set; }
Property Value
Type Description
Dictionary<int, Rectangle>

GlyphWidth

The width of each glyph in pixels.

Declaration
[DataMember]
public int GlyphWidth { get; set; }
Property Value
Type Description
int

Image

The texture used by the font.

Declaration
public ITexture Image { get; set; }
Property Value
Type Description
ITexture

IsSadExtended

True when the font supports SadConsole extended decorators; otherwise false.

Declaration
[DataMember]
public bool IsSadExtended { get; set; }
Property Value
Type Description
bool

Name

The name of the font used when it is registered with the Fonts collection.

Declaration
[DataMember]
public string Name { get; set; }
Property Value
Type Description
string

Rows

Declaration
[DataMember]
public int Rows { get; set; }
Property Value
Type Description
int

SolidGlyphIndex

Which glyph index is considered completely solid white. Used for shading.

Declaration
[DataMember]
public int SolidGlyphIndex { get; set; }
Property Value
Type Description
int

SolidGlyphRectangle

The rectangle associated with the SolidGlyphIndex.

Declaration
public Rectangle SolidGlyphRectangle { get; }
Property Value
Type Description
Rectangle

TotalGlyphs

Gets the total glyphs in this font, which represents the last index. Calculated from Columns times Rows.

Declaration
public int TotalGlyphs { get; }
Property Value
Type Description
int

UnsupportedGlyphIndex

The glyph index to use when an unsupported glyph is used during rendering.

Declaration
[DataMember]
public int UnsupportedGlyphIndex { get; set; }
Property Value
Type Description
int

UnsupportedGlyphRectangle

The rectangle associated with the UnsupportedGlyphIndex.

Declaration
public Rectangle UnsupportedGlyphRectangle { get; }
Property Value
Type Description
Rectangle

Methods

Clone(string)

Clones this font.

Declaration
public SadFont Clone(string newName)
Parameters
Type Name Description
string newName

The name to apply when creating the cloned font.

Returns
Type Description
SadFont

Returns the cloned font.

ConfigureRects()

Builds the GlyphRectangles array based on the current font settings, if the GlyphRectangles dictionary is empty.

Declaration
public void ConfigureRects()

Dispose()

Disposes the Image property.

Declaration
public void Dispose()

ForceConfigureRects()

Builds the GlyphRectangles array based on the current font settings.

Declaration
public void ForceConfigureRects()

GenerateGlyphSourceRectangle(int)

Generates a rectangle for the specified glyph based on the glyph index, Rows, Columns, and GlyphPadding values. For the actual font rectangle, use GetGlyphSourceRectangle(int).

Declaration
public Rectangle GenerateGlyphSourceRectangle(int glyph)
Parameters
Type Name Description
int glyph

The glyph.

Returns
Type Description
Rectangle

A rectangle based on where the font thinks the rectangle should be.

GetDecorator(string, Color)

Gets a CellDecorator by the GlyphDefinition defined by the font file.

Declaration
public CellDecorator GetDecorator(string name, Color color)
Parameters
Type Name Description
string name

The name of the decorator to get.

Color color

The color to apply to the decorator.

Returns
Type Description
CellDecorator

The decorator instance.

Remarks

If the decorator does not exist, Empty is returned.

GetFontSize(Sizes)

Gets the pixel size of a font based on a IFont.Sizes.

Declaration
public Point GetFontSize(IFont.Sizes size)
Parameters
Type Name Description
IFont.Sizes size

The desired size.

Returns
Type Description
Point

The width and height of a font cell.

GetGlyphDefinition(string)

A safe way to get a GlyphDefinition by name that is defined by the font file.

Declaration
public GlyphDefinition GetGlyphDefinition(string name)
Parameters
Type Name Description
string name

The name of the glyph definition.

Returns
Type Description
GlyphDefinition

The glyph definition.

Remarks

If the glyph definition doesn't exist, return sEmpty.

GetGlyphSourceRectangle(int)

Gets the rendering rectangle for a glyph.

Declaration
public Rectangle GetGlyphSourceRectangle(int glyph)
Parameters
Type Name Description
int glyph

The index of the glyph to get.

Returns
Type Description
Rectangle

The rectangle for the glyph if it exists, otherwise returns UnsupportedGlyphRectangle.

HasGlyphDefinition(string)

Returns true when the glyph has been defined by name.

Declaration
public bool HasGlyphDefinition(string name)
Parameters
Type Name Description
string name

The name of the glyph

Returns
Type Description
bool

true when the glyph name exists, otherwise false.

Implements

IFont
IDisposable

Extension Methods

FontExtensions.GetGlyphRatio(IFont, Point)
FontExtensions.GetRenderRect(IFont, int, int, Point)
FontExtensions.GetWorldPosition(IFont, Point, Point)
ExtensionsSystem.GetDebuggerDisplayValue(object)
In this article

Back to top

Back to top Generated by DocFX