Embedded developer Petteri Aimonen needs to place an finish to ugly typography on microcontroller-driven tasks with MCUFont, a library designed to squeeze high-quality fonts down to slot in the reminiscence of resource-constrained units — then to convey them again out once more for pin-sharp rendering.
“Traditionally, there are lots of easy font rendering routines accessible. They’re often ad-hoc implementations inside numerous graphics libraries, and consequently they ‘take the straightforward approach out,'” Aimonen explains by means of introduction to the mission, delivered to our consideration by Adafruit. “Normally this implies monochrome solely, no kerning, generally solely monospace, and really primary algorithms for phrase wrap. The purpose of [the MCUFont] library is to turn into a typical answer for this drawback, in order that additionally microcontroller based mostly programs can take pleasure in top quality textual content.”
For simply 1-5kB of flash, you can also have desktop-like high-quality fonts in your subsequent microcontroller mission. (📷: MCUFont)
The issue is acknowledged simply sufficient: vector-based fonts, just like the TrueType or OpenType fonts used on desktop computer systems, take up a comparatively great amount of space for storing and require a corresponding quantity of CPU time to extract and render. For a desktop, this “massive” quantity is tiny; for a microcontroller, it is merely an excessive amount of to depart room for the remainder of your program. MCUFont works by importing the vector fonts and compressing them down — then the microcontroller decompresses the outcomes and renders the chosen textual content.
There are, nonetheless, a few caveats earlier than you add MCUFont to your subsequent mission. The largest of those is that there is no assist for font scaling on-device, solely throughout the import and compression course of — lowering flexibility in contrast with rival font rendering approaches. The encoding course of can also be sluggish, and whereas hinting is energetic throughout import there’s at present no assist for sub-pixel interpolation throughout the show course of.
MCUFont is accessible on GitHub, underneath the permissive MIT license; the encoder facet is written in C++ and the decoder in C with minimal dependencies, making certain portability.