PaulStoffregen / ILI9341_t3

Optimized ILI9341 TFT Library
http://pjrc.com/store/display_ili9341.html
242 stars 95 forks source link

Implemented Unicode support while maintaining backwards compatibility #39

Open GeoSpark opened 7 years ago

GeoSpark commented 7 years ago

This PR implements Unicode support for fonts that have a Unicode codepoint table associated with them. See: https://github.com/GeoSpark/ILI9341-font-packer for Python code that generates these fonts, and examples/TakaoPGothic.c for an example.

It assumes UTF-8 encoding, but it is robust enough to ignore invalid strings of bytes, and will decode it as best it can when things get rough. I have yet to make it hang or start global thermonuclear war.

The code is backwards compatible with existing ASCII-based fonts.

It hijacks index1_first and index1_last members in the ILI9341_t3_font_t structure to store the size of the codepoint table as a uint16_t, which limits the table to 64k entries. If more entries are required, index2_* could be co-opted to give us the full range, although of course fonts this large are likely to be too big to fit into memory anyway. The code is structured such that if there isn't a codepoint table, index1_first and index1_last are treated as normal.

The only thing I have not implemented yet is strPixelLen() which assumes an ASCII string. Modifying this would be achievable, although it may break backwards compatibility. Alternatively a second function strPixelLenUTF8() could be written to handle the more general case.