This sub-repository is part of the TERKA project providing text input & advanced text rendering for .NET Micro Framework.
There are two ways how to generate tiny fonts in .NET Micro Framework. Using the TFConvert console application, and using the new TinyFont Builder library.
TFConvert is the standard way users are used to make fonts on .NET Micro Framework. This application was completely rewritten in managed code for the TERKA project. The TFConvert has two parameters, input file and output file.
TFConvert <input file> <output file>
<input file> = Font definition file (.fntdef)
<output file> = Font output file (.tinyfnt)
Users need to create a font definition file specifying what should be generated into the font, a plain text file with commands. Listing 1 shows a sample definition importing capital Latin letters and Small Capitals feature. For the complete commands reference, see the user documentation for TFConvert.
SelectFont "FN:Arial,HE:12"
#import A-Z
ImportRange 65 90
#import a-z
ImportRange 97 122
#import Small Capitals feature
ImportFeature latn dflt smcp
Listing 1 Sample font definition, letters A-z, small capitals
The TFConvert binary is located in the Release
directory; source code is available in Source\CLR\Tools\TinyFonts
.
The TFConvert calls the TinyFont Builder library to do the core work. Users are welcome to call it directly, should they need any advanced features or custom modifications to the generated font.
string fonts = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
GlyphTypeface arial = new GlyphTypeface(new Uri(Path.Combine(fonts, "arial.ttf")));
TinyFontBuilder builder = new TinyFontBuilder(arial, 15);
builder.OpenTypeCompiler = new OpenTypeCompiler();
builder.ImportFeature("dflt", "latn", "smcp");
TinyFont font = builder.Build("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
font.Save("arial.tinyfnt");
Listing 2 Sample font builder usage, letters A-z, small capitals
The code equivalent to Listing 1 using the library directly is shown in Listing 2. Note that users need to resolve the input font file themselves and provide a feature compiler. The TERKA compiler is available in a separate assembly. All binaries are located in the Release
directory; source code in Source\CLR\Tools\TinyFonts
.
The generated file can be used in .NET Micro Framework as a resource file.
- Create a new Micro Framework Window Application.
- Open
Resources.resx
. - Use Add Existing File command under Add Resource.
- Locate the
arial.tinyfnt
generated above and add it. - Open the
Program.cs
and update
text.Font = Resources.GetFont(Resources.FontResources.small);
to
text.Font = Resources.GetFont(Resources.FontResources.arial);
- To see the imported feature, add the following line:
text.TextFeatures = new[] { TextFeature.SmallCapitals };
- Run the project.