MCUFont Aims to Put High-Quality Typography on Microcontrollers with a Clever Two-Part Approach
By importing TTF and BDF vector fonts and compressing them down into a new format, MCUFont gives higher quality text than the competition.
Embedded developer Petteri Aimonen wants to put an end to ugly typography on microcontroller-driven projects with MCUFont, a library designed to squeeze high-quality fonts down to fit in the memory of resource-constrained devices — then to bring them back out again for pin-sharp rendering.
"Historically, there are many simple font rendering routines available. They are usually ad-hoc implementations inside various graphics libraries, and consequently they 'take the easy way out,'" Aimonen explains by way of introduction to the project, brought to our attention by Adafruit. "Usually this means monochrome only, no kerning, sometimes only monospace, and very basic algorithms for word wrap. The goal of [the MCUFont] library is to become a standard solution for this problem, so that also microcontroller based systems can enjoy high quality text."
The problem is stated easily enough: vector-based fonts, like the TrueType or OpenType fonts used on desktop computers, take up a relatively large amount of storage space and require a corresponding amount of CPU time to extract and render. For a desktop, this "large" amount is tiny; for a microcontroller, it's simply too much to leave room for the rest of your program. MCUFont works by importing the vector fonts and compressing them down — then the microcontroller decompresses the results and renders the selected text.
There are, however, a couple of caveats before you add MCUFont to your next project. The biggest of these is that there's no support for font scaling on-device, only during the import and compression process — reducing flexibility compared with rival font rendering approaches. The encoding process is also slow, and while hinting is active during import there's currently no support for sub-pixel interpolation during the display process.
MCUFont is available on GitHub, under the permissive MIT license; the encoder side is written in C++ and the decoder in C with minimal dependencies, ensuring portability.
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.