Skip to content

SadFont Class

Represents a graphical font used by SadConsole.

C#
[DataContract]
public sealed class SadFont : IFont, IDisposable

Inheritance object

Implements IFont, IDisposable

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

Section titled “SadFont(int, int, int, int, int, int, ITexture, string, Dictionary<int, Rectangle>?)”

Creates a new font with the specified settings.

C#
public SadFont(int glyphWidth, int glyphHeight, int glyphPadding, int rows, int columns, int solidGlyphIndex, ITexture image, string name, Dictionary<int, Rectangle>? glyphRectangles = null)

glyphWidth int
The pixel width of each glyph.

glyphHeight int
The pixel height of each glyph.

glyphPadding int
The pixel padding between each glyph.

rows int
Number of glyph rows in the image.

columns int
Number of glyph columns in the image.

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

image ITexture
The ITexture of the font.

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

glyphRectangles Dictionary<int, Rectangle>
Glyph mapping dictionary.

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

C#
[DataMember]
public int SolidGlyphIndex { get; set; }

The rectangle associated with the SolidGlyphIndex.

C#
public Rectangle SolidGlyphRectangle { get; }
C#
[DataMember]
public int Columns { get; set; }
C#
[DataMember]
public int Rows { get; set; }

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

C#
public int TotalGlyphs { get; }

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

C#
[DataMember]
public string Name { get; set; }

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

C#
[DataMember]
public string FilePath { get; set; }

The height of each glyph in pixels.

C#
[DataMember]
public int GlyphHeight { get; set; }

The width of each glyph in pixels.

C#
[DataMember]
public int GlyphWidth { get; set; }

The amount of pixels between glyphs.

C#
[DataMember]
public int GlyphPadding { get; set; }

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

C#
[DataMember]
public int UnsupportedGlyphIndex { get; set; }

The rectangle associated with the UnsupportedGlyphIndex.

C#
public Rectangle UnsupportedGlyphRectangle { get; }

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

C#
public Dictionary<int, Rectangle> GlyphRectangles { get; set; }

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

C#
[DataMember]
public bool IsSadExtended { get; set; }

The texture used by the font.

C#
public ITexture Image { get; set; }

A collection of named glyph definitions.

C#
[DataMember]
public Dictionary<string, GlyphDefinition> GlyphDefinitions { get; set; }

Gets the rendering rectangle for a glyph.

C#
public Rectangle GetGlyphSourceRectangle(int glyph)

glyph int
The index of the glyph to get.

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

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).

C#
public Rectangle GenerateGlyphSourceRectangle(int glyph)

glyph int
The glyph.

SadRogue.Primitives.Rectangle
A rectangle based on where the font thinks the rectangle should be.

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

C#
public CellDecorator GetDecorator(string name, Color color)

name string
The name of the decorator to get.

color SadRogue.Primitives.Color
The color to apply to the decorator.

CellDecorator
The decorator instance.

If the decorator does not exist, Empty is returned.

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

C#
public GlyphDefinition GetGlyphDefinition(string name)

name string
The name of the glyph definition.

GlyphDefinition
The glyph definition.

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

Returns true when the glyph has been defined by name.

C#
public bool HasGlyphDefinition(string name)

name string
The name of the glyph

bool
true when the glyph name exists, otherwise false.

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

C#
public Point GetFontSize(IFont.Sizes size)

size IFont.Sizes
The desired size.

SadRogue.Primitives.Point
The width and height of a font cell.

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

C#
public void ConfigureRects()

Builds the GlyphRectangles array based on the current font settings.

C#
public void ForceConfigureRects()

Clones this font.

C#
public SadFont Clone(string newName)

newName string
The name to apply when creating the cloned font.

SadFont
Returns the cloned font.

Disposes the Image property.

C#
public void Dispose()