FigletFont
Namespace: Hex1b.Widgets
Assembly: Hex1b.dll
Represents a parsed FIGfont — a typeface used by to render large ASCII-art text. Subclass to intercept glyph lookups, decorate or substitute glyphs, or build a fully synthetic font without parsing a .flf file.
public class FigletFontInheritance
Object → FigletFont
Constructors
FigletFont(FigletFont)
Initializes a new that delegates all behavior to inner. Use this constructor when subclassing to decorate an existing font (for example to override for character substitution or fallback chains).
Parameters:
inner(FigletFont): The font to delegate to. Must not be null.
protected FigletFont(FigletFont inner)FigletFont(int, int, char, int, bool, bool, int, bool, bool)
Initializes a new from primitive layout parameters. Use this constructor when implementing a fully synthetic font (no .flf data).
Parameters:
height(Int32): The number of rows in every glyph. Must be at least 1.baseline(Int32): The 1-based row index of the FIGfont baseline counted from the top of a glyph. Must be in the range[1, height].hardblank(Char): The sub-character that represents the hardblank in this font's glyph data. Renders as a space in output but participates in horizontal layout differently than ordinary spaces.horizontalSmushingRules(Int32): Bitmask of horizontal smushing rules that this font opts in to (bits 1, 2, 4, 8, 16, 32). A value of0with horizontalSmushing set enables universal smushing.horizontalSmushing(Boolean): True when smushing is the font's preferred horizontal layout.horizontalFitting(Boolean): True when fitting (kerning) is the font's preferred horizontal layout.verticalSmushingRules(Int32): Bitmask of vertical smushing rules in the post-shift form (bits 1, 2, 4, 8, 16). A value of0with verticalSmushing set enables universal vertical smushing.verticalSmushing(Boolean): True when smushing is the font's preferred vertical layout.verticalFitting(Boolean): True when fitting is the font's preferred vertical layout.
protected FigletFont(int height, int baseline, char hardblank, int horizontalSmushingRules, bool horizontalSmushing, bool horizontalFitting, int verticalSmushingRules, bool verticalSmushing, bool verticalFitting)Properties
Baseline
Gets the 1-based row index of the FIGfont baseline (counted from the top of a glyph). Capital letters rest on top of this row.
Returns: Int32
public virtual int Baseline { get; }Hardblank
Gets the sub-character used to represent hardblanks in this font's glyph data. Hardblanks render as spaces but participate in horizontal layout differently.
Returns: Char
public virtual char Hardblank { get; }Height
Gets the height of every glyph in this font, in rows of sub-characters.
Returns: Int32
public virtual int Height { get; }Methods
GetMissingGlyph()
Returns the glyph used when returns false. The default implementation returns the font's space glyph if available, matching reference figlet behavior.
Returns: FigletGlyph
The fallback glyph for missing characters.
public virtual FigletGlyph GetMissingGlyph()LoadAsync(Stream, CancellationToken)
Asynchronously loads a FIGfont from a stream. The stream is read using ISO-8859-1 (Latin-1) so that hardblanks and sub-characters in the upper Latin-1 range are preserved.
Parameters:
stream(Stream): The stream to read. The caller retains ownership.cancellationToken(CancellationToken): A token to cancel the async copy.
Returns: Task<FigletFont>
The parsed font.
public static Task<FigletFont> LoadAsync(Stream stream, CancellationToken cancellationToken = default)LoadBundled(string)
Synchronously loads one of Hex1b's bundled FIGfonts by short name. Used by to populate its lazy singletons.
Parameters:
name(String): The bundled font's short name (see ).
Returns: FigletFont
The parsed font.
public static FigletFont LoadBundled(string name)LoadBundledAsync(string, CancellationToken)
Asynchronously loads one of Hex1b's bundled FIGfonts by short name.
Parameters:
name(String): The font name. Recognized values (case-insensitive):standard,slant,small,big,mini,shadow,block,banner.cancellationToken(CancellationToken): A token to cancel the read.
Returns: Task<FigletFont>
The parsed font.
public static Task<FigletFont> LoadBundledAsync(string name, CancellationToken cancellationToken = default)LoadFileAsync(string, CancellationToken)
Asynchronously loads a FIGfont from a file path.
Parameters:
path(String): Path to a.flffile.cancellationToken(CancellationToken): A token to cancel the read.
Returns: Task<FigletFont>
The parsed font.
public static Task<FigletFont> LoadFileAsync(string path, CancellationToken cancellationToken = default)Parse(string)
Parses a FIGfont from an in-memory .flf string.
Parameters:
flfContent(String): The full text of a.flffile.
Returns: FigletFont
The parsed font.
public static FigletFont Parse(string flfContent)ToString()
Returns a string identifying the font (height, hardblank, layout flags). Useful for diagnostics.
Returns: String
public override string ToString()TryGetGlyph(int, out FigletGlyph)
Looks up the glyph for codePoint.
Parameters:
codePoint(Int32): The Unicode code point of the desired character.glyph(FigletGlyph): The glyph if found; otherwise null.
Returns: Boolean
true if a glyph exists in this font for the given code point; otherwise false.
public virtual bool TryGetGlyph(int codePoint, out FigletGlyph glyph)Remarks
Use one of the static factory methods to load a font: — load from any stream — load from disk / — load one of Hex1b's embedded fonts — parse a .flf string already in memory For the bundled fonts, prefer the lazy singletons exposed on (e.g. FigletFonts.Standard) over re-loading the resource.
Subclasses can override to substitute glyphs (for example to provide a fallback chain), and may use the decorator constructor to wrap an existing font.
Instances are immutable and safe to share across threads. Parsing a font is moderately expensive; bundled fonts are cached on .