ILI9341 font builder

Status
Not open for further replies.

MerseyViking

New member
Just a quick announcement to say I have written a small tool to generate bitmap fonts that are compatible with Paul's (and Lady Ada's) ILI9341 rendering library, from TrueType fonts (and almost certainly any font supported by FreeType2).

They can be output as C code to compile straight into any project, or as a binary file that can be copied to an SD card or flash chip, and loaded dynamically at run time.

Go here: https://github.com/GeoSpark/ILI9341-font-packer for some Pythonic goodness and a more thorough README. The code is largely without comment, and would benefit from some refactoring and validation checking, but it works for me. Pull requests are welcome.

I know there are already some tools written by Paul to achieve something similar, but I wrote this for a couple of reasons. 1) the existing tool only works with BDF fonts and I wanted to use TTFs, and 2) I don't like Perl :) OK, that last one isn't a *good* reason, but it was a nice intellectual exercise in pulling apart the pretty clever font format, and rebuilding it using my language of choice.

I have also included a simplified uploader script and sketch based on those found in the SerialFlash library.

-JD
 
Awesome! I just started with Teensy and ILI9341, and was thinking of writing something similar - to make it easier to add new fonts, and work on more features for the ILI9341 library. I'll try out your code in the next few days and let you know if I hit any issues.

Have you compared the output of your tool to the fonts that have already been converted? Would be nice to use those to validate the results of your tool.

I would like to work on adding anti-aliased font support to the ILI9341 library as well. I made a simple proof of concept using two bitmaps as a comparison, and I certainly like the smoother edges :)
The output bit depth could be a parameter for the converter, to allow balancing between quality and size. For ILI9341, 6-bit would be the maximum required, but there may be other use cases of up to 8-bit output. Of course the font storage structure and packing method would need to be re-done to support anything beyond the existing 1-bit fonts. I haven't thought about it in detail yet.
 
I've added a link to this thread on the display pages. Hopefully that'll help anyone who's interested to find this alternate way to manage the fonts. :)
 
Thanks for the heads-up Frank, the number of fonts you've converted is majestic!

Thanks Paul, I appreciate that.

I've now implemented UTF-8 encoded Unicode support for fonts! See the code here: https://github.com/GeoSpark/ILI9341_t3 which is a fork from Paul's original: https://github.com/PaulStoffregen/ILI9341_t3 and a pull request has been issued.

IMG_20161123_172232.jpg

For ease of development (and because the original code does a great job already), my font-packer code now only produces Unicode-based fonts, although the magic of UTF-8 and Unicode is that the ASCII range of characters maps seamlessly. There is an extra bit of overhead when rendering Unicode-based glyphs which is an extra table of codepoints, and some slightly more convoluted glyph selection algorithm to allow for disjoint ranges of characters. strPixelLen() hasn't been touched, so you will likely get odd results if you pass it a string with bytes > 126 in it. I intend to fix that at some point - although if anyone else fancies a go... ;)

The example directory in here https://github.com/GeoSpark/ILI9341-font-packer has a binary and C versions of the hiragana Unicode block from the TakaoPGothic font, which will *only* work with the updated ILI9341_t3 library.
 
Status
Not open for further replies.
Back
Top