Font
Struct · namespace System.Graphics · Since 0.45
struct FontA 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());Fields
Section titled “Fields”| 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 WidthThe width of a character cell in pixels (without the zoom).
Height
Section titled “Height”int HeightThe height of a character cell in pixels (without the zoom).
Ascent
Section titled “Ascent”int AscentHow far the baseline is below the top of a cell.
int ZoomEvery font pixel becomes Zoom x Zoom pixels.
Static methods
Section titled “Static methods”| 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). |
Fixed7x13
Section titled “Fixed7x13”static Font Fixed7x13()7 x 13 pixels: for a scale of 1 (96 dpi).
Fixed10x20
Section titled “Fixed10x20”static Font Fixed10x20()10 x 20 pixels: for a scale of about 1.5.
Tiny5x7
Section titled “Tiny5x7”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);ForScale
Section titled “ForScale”static Font ForScale(double scale)The built-in font that suits a scale (1 = 96 dpi): 7x13, 10x20, and both zoomed for higher scales.
Metrics
Section titled “Metrics”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.
Methods
Section titled “Methods”| 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). |
Zoomed
Section titled “Zoomed”Font Zoomed(int zoom)The same font with every pixel drawn zoom x zoom times.
CharWidth
Section titled “CharWidth”int CharWidth()The width of one character on the screen.
LineHeight
Section titled “LineHeight”int LineHeight()The height of a line on the screen.
Measure
Section titled “Measure”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).