Font Support
Fonts on TinyCLR are stored in a custom .tcfnt binary format. Any TrueType font can be converted to .tcfnt with the FontConverter tool, embedded as a project resource, and used by the graphics engine for drawing text.
Old NETMF font files don't work on TinyCLR — re-convert with the current FontConverter even if you have older .tinyfnt files lying around.
NuGet package: GHIElectronics.TinyCLR.UI (the graphics engine that draws text). The FontConverter itself is a separate command-line tool available on the Downloads page.
Using a font
Load the converted font as a resource and pass it to the graphics engine:
using GHIElectronics.TinyCLR.UI;
var screen = Graphics.FromHdc(displayController.Hdc);
var font = Resources.GetFont(Resources.FontResources.NinaB);
var greenPen = new Pen(Color.Green);
screen.DrawString("Hello World!", font, greenPen.Brush, 10, 100);
screen.Flush();
See Graphics for the rest of the drawing API.
Converting a font
Converting a TrueType font to .tcfnt is a two-step process:
- Write a
.fntdeffile — a plain-text descriptor for the font: which face, which sizes, which character ranges, etc. - Run the FontConverter — produces a
.tcfntfile you embed as a resource.
A minimal .fntdef for the standard ASCII range:
SelectFont "FN:Arial,WE:400,HE:12,IT:0"
ImportRange 32 126
Run the converter:
GHIElectronics.TinyCLR.FontConverter.exe Arial.fntdef Arial.tcfnt
The TinyFont Tool is a third-party GUI that can also generate compatible font files if you'd rather not write .fntdef files by hand.
.fntdef reference
The order of statements matters — for example, AntiAlias must come before the ImportRange it should apply to.
Font selection
AddFontToProcess path
Include a TrueType font file in the search list, in addition to the system-installed fonts. If the path contains spaces, quote it and escape backslashes.
AddFontToProcess C:\Windows\Fonts\Arial.ttf
SelectFont "selection string"
Search the available fonts for the first one matching the comma-delimited fields in the selection string. No spaces around commas or colons — they cause parse errors.
| Field | Meaning |
|---|---|
HE | Height in logical units. 0 for default; positive = cell height; negative = character height. |
WI | Average character width in logical units. 0 for best aspect-ratio match. |
ES | Escapement angle in tenths of a degree. Negative = clockwise rotation. |
WE | Weight (0–1000). 400 = normal, 700 = bold. 0 for default. |
IT | Italic — IT:1 enables italic. |
FN | Face name (typeface name). |
FullName | Full font name, e.g. "Monotype:Arial Regular (Microsoft)". |
Example — regular-weight Arial at height 12:
SelectFont "HE:12,WE:400,FN:Arial"
Character ranges
ImportRange start end
Unicode code points to include, inclusive. Both arguments required. Use multiple ImportRange statements to convert non-contiguous ranges. Must come after SelectFont.
ImportRangeAndMap start end offset
Same as ImportRange, but maps the imported characters into a different range — output characters land at start + offset through end + offset. Must come after SelectFont.
SetAsDefaultCharacter charcode
Sets the Unicode code point used as a substitute for any character not in an imported range. Must come after SelectFont.
SetDefaultCharacter
Use the currently-selected TrueType font's own default character as the substitute. Must come after SelectFont.
NoDefaultCharacter
Don't substitute anything for unconverted characters. Must come after SelectFont.
Anti-aliasing
AntiAlias level
Levels 1, 2, 4, or 8 produce 2, 5, 17, or 65 levels of gray in the output bitmap respectively. Must come after SelectFont and before any ImportRange it should apply to.
Position adjustments
All of these take an integer (positive or negative). The Adjust* family applies to EM units unless noted; OffsetX / OffsetY apply to subsequent character ranges.
| Statement | Effect |
|---|---|
AdjustAscent | EM units added to ascent. Once per file. |
AdjustDescent | EM units added to descent. Once per file. |
AdjustExternalLeading | EM units added to external leading. Once per file. |
AdjustInternalLeading | EM units added to internal leading. Once per file. |
AdjustLeftMargin | Device units added to left margin. Applies to the next ImportRange. |
AdjustRightMargin | EM units added to right margin. Applies to the next ImportRange. |
OffsetX | EM units to shift left (positive) or right (negative). Applies to subsequent ranges. |
OffsetY | EM units to shift down (positive) or up (negative). Applies to subsequent ranges. |
Other
Verbosity level
Not currently supported — set to 0.
# comments
Lines starting with # are comments.
# This font is used by the main menu.
SelectFont "FN:Arial,WE:400,HE:14"
ImportRange 32 126
API reference
| Namespace | Description |
|---|---|
| GHIElectronics.TinyCLR.UI | TinyCLR UI framework (fonts, controls, layout) |