SadFont Class
Definition
Section titled “Definition”Represents a graphical font used by SadConsole.
[DataContract]public sealed class SadFont : IFont, IDisposableInheritance object
Implements IFont, IDisposable
Constructors
Section titled “Constructors”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.
public SadFont(int glyphWidth, int glyphHeight, int glyphPadding, int rows, int columns, int solidGlyphIndex, ITexture image, string name, Dictionary<int, Rectangle>? glyphRectangles = null)Parameters
Section titled “Parameters”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.
Properties
Section titled “Properties”SolidGlyphIndex
Section titled “SolidGlyphIndex”Which glyph index is considered completely solid white. Used for shading.
[DataMember]public int SolidGlyphIndex { get; set; }SolidGlyphRectangle
Section titled “SolidGlyphRectangle”The rectangle associated with the SolidGlyphIndex.
public Rectangle SolidGlyphRectangle { get; }Columns
Section titled “Columns”[DataMember]public int Columns { get; set; }[DataMember]public int Rows { get; set; }TotalGlyphs
Section titled “TotalGlyphs”Gets the total glyphs in this font, which represents the last index. Calculated from Columns times Rows.
public int TotalGlyphs { get; }The name of the font used when it is registered with the Fonts collection.
[DataMember]public string Name { get; set; }FilePath
Section titled “FilePath”The name of the image file as defined in the .font file.
[DataMember]public string FilePath { get; set; }GlyphHeight
Section titled “GlyphHeight”The height of each glyph in pixels.
[DataMember]public int GlyphHeight { get; set; }GlyphWidth
Section titled “GlyphWidth”The width of each glyph in pixels.
[DataMember]public int GlyphWidth { get; set; }GlyphPadding
Section titled “GlyphPadding”The amount of pixels between glyphs.
[DataMember]public int GlyphPadding { get; set; }UnsupportedGlyphIndex
Section titled “UnsupportedGlyphIndex”The glyph index to use when an unsupported glyph is used during rendering.
[DataMember]public int UnsupportedGlyphIndex { get; set; }UnsupportedGlyphRectangle
Section titled “UnsupportedGlyphRectangle”The rectangle associated with the UnsupportedGlyphIndex.
public Rectangle UnsupportedGlyphRectangle { get; }GlyphRectangles
Section titled “GlyphRectangles”A dictionary that stores the source rectangles of the font by glyph id.
public Dictionary<int, Rectangle> GlyphRectangles { get; set; }IsSadExtended
Section titled “IsSadExtended”True when the font supports SadConsole extended decorators; otherwise false.
[DataMember]public bool IsSadExtended { get; set; }The texture used by the font.
public ITexture Image { get; set; }GlyphDefinitions
Section titled “GlyphDefinitions”A collection of named glyph definitions.
[DataMember]public Dictionary<string, GlyphDefinition> GlyphDefinitions { get; set; }Methods
Section titled “Methods”GetGlyphSourceRectangle(int)
Section titled “GetGlyphSourceRectangle(int)”Gets the rendering rectangle for a glyph.
public Rectangle GetGlyphSourceRectangle(int glyph)Parameters
Section titled “Parameters”glyph int
The index of the glyph to get.
Returns
Section titled “Returns”SadRogue.Primitives.Rectangle
The rectangle for the glyph if it exists, otherwise returns UnsupportedGlyphRectangle.
GenerateGlyphSourceRectangle(int)
Section titled “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).
public Rectangle GenerateGlyphSourceRectangle(int glyph)Parameters
Section titled “Parameters”glyph int
The glyph.
Returns
Section titled “Returns”SadRogue.Primitives.Rectangle
A rectangle based on where the font thinks the rectangle should be.
GetDecorator(string, Color)
Section titled “GetDecorator(string, Color)”Gets a CellDecorator by the GlyphDefinition defined by the font file.
public CellDecorator GetDecorator(string name, Color color)Parameters
Section titled “Parameters”name string
The name of the decorator to get.
color SadRogue.Primitives.Color
The color to apply to the decorator.
Returns
Section titled “Returns”CellDecorator
The decorator instance.
Remarks
Section titled “Remarks”If the decorator does not exist, Empty is returned.
GetGlyphDefinition(string)
Section titled “GetGlyphDefinition(string)”A safe way to get a GlyphDefinition by name that is defined by the font file.
public GlyphDefinition GetGlyphDefinition(string name)Parameters
Section titled “Parameters”name string
The name of the glyph definition.
Returns
Section titled “Returns”GlyphDefinition
The glyph definition.
Remarks
Section titled “Remarks”If the glyph definition doesn’t exist, return sEmpty.
HasGlyphDefinition(string)
Section titled “HasGlyphDefinition(string)”Returns true when the glyph has been defined by name.
public bool HasGlyphDefinition(string name)Parameters
Section titled “Parameters”name string
The name of the glyph
Returns
Section titled “Returns”bool
true when the glyph name exists, otherwise false.
GetFontSize(Sizes)
Section titled “GetFontSize(Sizes)”Gets the pixel size of a font based on a IFont.Sizes.
public Point GetFontSize(IFont.Sizes size)Parameters
Section titled “Parameters”size IFont.Sizes
The desired size.
Returns
Section titled “Returns”SadRogue.Primitives.Point
The width and height of a font cell.
ConfigureRects()
Section titled “ConfigureRects()”Builds the GlyphRectangles array based on the current font settings, if the GlyphRectangles dictionary is empty.
public void ConfigureRects()ForceConfigureRects()
Section titled “ForceConfigureRects()”Builds the GlyphRectangles array based on the current font settings.
public void ForceConfigureRects()Clone(string)
Section titled “Clone(string)”Clones this font.
public SadFont Clone(string newName)Parameters
Section titled “Parameters”newName string
The name to apply when creating the cloned font.
Returns
Section titled “Returns”SadFont
Returns the cloned font.
Dispose()
Section titled “Dispose()”Disposes the Image property.
public void Dispose()