Skip to content
CShift0.45

Font

Struct · namespace System.Graphics · Since 0.45

struct Font

A bitmap font: every character is a cell of the same size. Built in are the “fixed” fonts of X11 (7 x 13 and 10 x 20, with ASCII, Latin-1 and a few typographic marks and arrows) and a small one for games (5 x 7, uppercase); Font.Parse reads one of your own. A character that a font does not have is drawn as its uppercase letter if it has that, else as ?. Zoom draws every pixel of a glyph as a square of that many pixels.

var font = Font.Tiny5x7().Zoomed(2);
canvas.Text(font, 8, 8, "SCORE " + score.ToString(), Color.White());
Name Description
Width The width of a character cell in pixels (without the zoom).
Height The height of a character cell in pixels (without the zoom).
Ascent How far the baseline is below the top of a cell.
Zoom Every font pixel becomes Zoom x Zoom pixels.
int Width

The width of a character cell in pixels (without the zoom).

int Height

The height of a character cell in pixels (without the zoom).

int Ascent

How far the baseline is below the top of a cell.

int Zoom

Every font pixel becomes Zoom x Zoom pixels.

Name Description
Fixed7x13 7 x 13 pixels: for a scale of 1 (96 dpi).
Fixed10x20 10 x 20 pixels: for a scale of about 1.5.
Tiny5x7 5 x 7 pixels in cells of 6 x 8: digits, uppercase letters (with Ä, Ö, Ü and ß), punctuation and arrows, for the small screens of games; lowercase letters are drawn as uppercase ones.
Parse A font from text: for each character a line with the character itself, then height lines of up to width characters, # for a pixel that is set and any other character for one that is not.
ForScale The built-in font that suits a scale (1 = 96 dpi): 7x13, 10x20, and both zoomed for higher scales.
Metrics A font of which only the sizes are known: for a Ui that is drawn with commands (Ui.BeginCommands) by a renderer with its own font (AmigaOS: the system font).
static Font Fixed7x13()

7 x 13 pixels: for a scale of 1 (96 dpi).

static Font Fixed10x20()

10 x 20 pixels: for a scale of about 1.5.

static Font Tiny5x7()

5 x 7 pixels in cells of 6 x 8: digits, uppercase letters (with Ä, Ö, Ü and ß), punctuation and arrows, for the small screens of games; lowercase letters are drawn as uppercase ones.

static Font Parse(ReadOnlySlice<StringSlice> lines, int width, int height)

A font from text: for each character a line with the character itself, then height lines of up to width characters, # for a pixel that is set and any other character for one that is not. The cells are width x height (up to 16 pixels wide); leave an empty column and row in the glyphs for the space between characters and lines.

var font = Font.Parse((try File.ReadAllText("font.txt")).Split('\n'), 6, 8);
static Font ForScale(double scale)

The built-in font that suits a scale (1 = 96 dpi): 7x13, 10x20, and both zoomed for higher scales.

static Font Metrics(int width, int height, int ascent)

A font of which only the sizes are known: for a Ui that is drawn with commands (Ui.BeginCommands) by a renderer with its own font (AmigaOS: the system font). It draws nothing itself.

Name Description
Zoomed The same font with every pixel drawn zoom x zoom times.
CharWidth The width of one character on the screen.
LineHeight The height of a line on the screen.
Measure The width of a text on the screen (every character has the same width).
Draw Draws text into a canvas with its top left corner at (x, y) and returns its width (see Canvas.Text).
Font Zoomed(int zoom)

The same font with every pixel drawn zoom x zoom times.

int CharWidth()

The width of one character on the screen.

int LineHeight()

The height of a line on the screen.

int Measure(StringSlice text)

The width of a text on the screen (every character has the same width).

int Draw(ref Canvas canvas, int x, int y, StringSlice text, Color color)

Draws text into a canvas with its top left corner at (x, y) and returns its width (see Canvas.Text).