Soft Fonts - RA8875

  • Added some details related to post-processing a font file to improve the width of the <space> and fix the width of the digits '0' - '9'.

Purpose

This page details the procedure for creating a user defined font for use with the RA8875 library.

Font Tool

Mikroe has, at least right now, a free edition of their font creator tool. This is a Windows application, so this tutorial assumes Windows is in use. Go there, read about it, and if you accept the license, you'll find it is very handy. Thanks to Mikroe for this.

Fonts you can use

Depending on your desktop OS, most of the fonts may be copyright. You should not derive an embedded font from those. Generally, this is not a problem, many fonts are available as open source – so search the web. For this tutorial, I’m using a font of my own design, one I created a few years ago.

  • Install the font into Windows, if it isn’t already there.
  • Launch the MicroE GLCD Font Creator application.
  • From the file menu, import the font of interest:
    /media/uploads/WiredHome/softfont-importttf.png
  • During the import process, you can set a few characteristics, including the size.
    Note here that the size I selected is 24 point, but as you'll see further down it ended up as a larger size - I think accounting for the descender's. It may take a trial or two to get exactly what you want.
    /media/uploads/WiredHome/softfont-selectfont.png
  • In one final step of the import process, you can apply a few more changes. If you only wanted to import the digits ‘0’ – ‘9’, or perhaps only upper case ‘A’ – ‘Z’, you can set the range as you see. For this example, I’ll take all the characters I have in my font.
    /media/uploads/WiredHome/softfont-importrange.png
  • After you start the import process, be patient. This may take a rather long time as it seems to process the characters one at a time. You can monitor the progress on the status bar.
    /media/uploads/WiredHome/glcd_progressbar.png
  • You can preview, and even edit the font if you want to make some corrections.
    Look at the Font Size in the status bar. It now shows as 18x32 pixels, so up from the 24-point chosen above.
    /media/uploads/WiredHome/softfont-glcdtool.png
    You can see a lot of whitespace below the letters. There are easy methods to remove the extra space – saving a lot of memory. But, I’m also importing lower-case, which have descenders, so I’ll leave it as is.
  • To export the fonts in source-code, choose “Export for TFT and new GLCD”.
    /media/uploads/WiredHome/softfont-export.png
    • The old technique used the “Export for GLCD” format, but this required manual post-processing.
    • The new technique creates a more complex file, but requires minimal post-processing.
  • Be sure to select the mikroC tab.
    /media/uploads/WiredHome/softfont-ushorttouchar.png
  • Here you perform a manual edit. Simply change “unsigned short” to “unsigned char” in the highlighted line.

Post-Processing Modifications

  • I embedded a Perl script into the fonts folder. It can force the width of the <space> to be 1/2 the font height, which seems like a good change, and less error prone than the following way. Also, this script forces each digit to be a fixed width - which is also a good change for numeric display (e.g. a clock). The instructions are in the script source code.
  • As an alternate to the Perl script, I've noticed that the <space> character gets defined as 1 pixel wide, even on large fonts. I don’t know if that is a mistake in the original TTF file, or a product of the Mikroe tool, so I change it to a more reasonable number, 4 pixels for the example for small fonts. You cannot make this larger than 8, or all the rest of the data has to be modified - thus the reason for the Perl script. After the first 8 bytes comes the reference for character 32. The first byte was a 0x01, and you’ll see below I changed it to 0x04.
    /media/uploads/WiredHome/softfont-spacewidth.png

Include into your Project

  • For the mbed online compiler, I use “Copy Code to Clipboard” and paste it in to a waiting file.
  • I next recommend you save this into your project as a .h file (this is not the normal convention for a file that produces code, which would normally be a .c or .cpp). In this example, I’ll save it as “MyFont36x64.h”.
  • A Demo Program is handy.

#include "mbed.h"

#include "RA8875.h"
#include "MyFont18x32.h"

LocalFileSystem local("local");     // Because I want <PrintScreen>
Serial pc(USBTX, USBRX);            // And a little feedback

int main()
{
    RA8875 lcd(p5, p6, p7, p12, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name
    
    pc.baud(460800);                            // I like a snappy terminal, so crank it up!
    pc.printf("\r\nRA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");

    lcd.init();
    lcd.foreground(BrightBlue);
    lcd.puts(0,0, "RA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n");

    lcd.locate(0,4);                            // Move down a little
    lcd.SelectUserFont(Dave_Smart18x32);
    lcd.puts("**** ! Soft Fonts ! ****\r\n");
    lcd.puts("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
    lcd.puts("abcdefghijklmnopqrstuvwxyz\r\n");
    lcd.puts("0123456789\r\n");
    lcd.SelectUserFont();
    lcd.puts("Back to normal");
    
    RetCode_t r = lcd.PrintScreen(0,0,480,272,"/local/file.bmp");
    pc.printf("  PrintScreen returned %d\r\n", r);
    
    while(1) {
        ;       // end
    }
}
  • And here’s the <PrintScreen> product.
    /media/uploads/WiredHome/softfont-example.png
  • From here, you’re on your own! Enjoy.

Two Export Formats

The GLCD tool supports two export formats. This upgrade supports the new format. Briefly, here is the difference between the two.

Export TechnologyBenefits Complications
Export for GLCDSimplerRequires hand modifications
Export for TFT & GLCD LibrarySmaller file sizeMore overhead in processing

Export for GLCD - deprecated format

Here’s a sample, as exported:
/media/uploads/WiredHome/softfont-oldformat_1.png

After manual manipulation:
/media/uploads/WiredHome/softfont-oldformat_2.png

The whole file
/media/uploads/WiredHome/softfont-oldformat_3.png

Export for TFT & GLCD Library - recommended format

The newer and supported format:
/media/uploads/WiredHome/softfont-newformat_1.png

Shown is just the start of the dataset, and you can see it looks very different.
/media/uploads/WiredHome/softfont-newformat_2.png
What you can see is that not every character occupies the same storage. This is an important feature of the newer (and recommended) format.

Annex 1 – Included Fonts

A small collection of BPG Arial fonts are included. To use one of them, simply "#include <font file>" and ".SelectUserFont(fontname)".
/media/uploads/WiredHome/softfont-bpgarial.png

Attribution

This is derived from the earlier work of Peter Drescher.

Resources

The license agreements for these tools was reviewed and nothing was identified that would prevent this information from being shared. If you reach a different conclusion, please contact the author of this page.


Please log in to post comments.