Class BitmapFont
- Namespace
- PluginUI
- Assembly
- PluginUI.dll
Monospace bitmap font: an image (atlas) cut into equal cells, one glyph per cell, in character order. Used by BitmapText for LCD, VFD, pixel-art or "hardware" displays that a vector font cannot reproduce.
public sealed class BitmapFont
- Inheritance
-
BitmapFont
- Inherited Members
Examples
// 16 × 6 cells of 8 × 12 pixels covering ASCII 32..127:
var font = new BitmapFont(ImageSource.FromFile("lcd-font.png"), cellWidth: 8, cellHeight: 12);
var display = new BitmapText { Font = font, Text = "CUTOFF 1.2k", PixelScale = 2 };
Remarks
The atlas is read row by row: cell 0 is FirstCharacter, cell 1 the next character, and so on (Characters can list an arbitrary order instead). Glyphs are drawn without smoothing so that pixel fonts stay crisp when scaled by an integer factor.
Missing characters are drawn as FallbackCharacter (a space by default).
Constructors
BitmapFont(ImageSource, int, int, char, string?)
Creates a font from an atlas image.
public BitmapFont(ImageSource atlas, int cellWidth, int cellHeight, char firstCharacter = ' ', string? characters = null)
Parameters
atlasImageSourceThe glyph atlas.
cellWidthintWidth of one glyph cell, in image pixels.
cellHeightintHeight of one glyph cell, in image pixels.
firstCharactercharCharacter of the first cell (default: space, ASCII 32).
charactersstringExplicit characters of the cells in order, or
nullto use consecutive characters fromfirstCharacter.
Exceptions
- ArgumentNullException
atlasisnull.- ArgumentOutOfRangeException
A cell size is not positive or larger than the atlas.
Properties
Atlas
The glyph atlas.
public ImageSource Atlas { get; }
Property Value
CellHeight
Height of a glyph cell in image pixels.
public int CellHeight { get; }
Property Value
CellWidth
Width of a glyph cell in image pixels.
public int CellWidth { get; }
Property Value
Characters
Explicit cell order, or null for consecutive characters.
public string? Characters { get; }
Property Value
Columns
Number of cells per atlas row.
public int Columns { get; }
Property Value
FallbackCharacter
Character drawn for characters missing from the atlas (default: space).
public char FallbackCharacter { get; init; }
Property Value
FirstCharacter
Character of the first cell when Characters is null.
public char FirstCharacter { get; }
Property Value
GlyphSize
Size of a glyph in DIPs (cell size divided by the atlas density).
public Size GlyphSize { get; }
Property Value
Methods
Contains(char)
true if the atlas contains c.
public bool Contains(char c)
Parameters
ccharA character.
Returns
- bool
trueif the character has a glyph.
GlyphPixels(char)
Source rectangle (atlas pixels) of a character, or null if neither it nor the fallback exists.
public Rect? GlyphPixels(char c)
Parameters
ccharA character.
Returns
- Rect?
The glyph cell in atlas pixels.