Table of Contents

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

atlas ImageSource

The glyph atlas.

cellWidth int

Width of one glyph cell, in image pixels.

cellHeight int

Height of one glyph cell, in image pixels.

firstCharacter char

Character of the first cell (default: space, ASCII 32).

characters string

Explicit characters of the cells in order, or null to use consecutive characters from firstCharacter.

Exceptions

ArgumentNullException

atlas is null.

ArgumentOutOfRangeException

A cell size is not positive or larger than the atlas.

Properties

Atlas

The glyph atlas.

public ImageSource Atlas { get; }

Property Value

ImageSource

CellHeight

Height of a glyph cell in image pixels.

public int CellHeight { get; }

Property Value

int

CellWidth

Width of a glyph cell in image pixels.

public int CellWidth { get; }

Property Value

int

Characters

Explicit cell order, or null for consecutive characters.

public string? Characters { get; }

Property Value

string

Columns

Number of cells per atlas row.

public int Columns { get; }

Property Value

int

FallbackCharacter

Character drawn for characters missing from the atlas (default: space).

public char FallbackCharacter { get; init; }

Property Value

char

FirstCharacter

Character of the first cell when Characters is null.

public char FirstCharacter { get; }

Property Value

char

GlyphSize

Size of a glyph in DIPs (cell size divided by the atlas density).

public Size GlyphSize { get; }

Property Value

Size

Methods

Contains(char)

true if the atlas contains c.

public bool Contains(char c)

Parameters

c char

A character.

Returns

bool

true if 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

c char

A character.

Returns

Rect?

The glyph cell in atlas pixels.