mikaelpatel/Cosa — pull request #286 by jediunix (2014-12-19 23:11:15+00:00)
Title: Major Enhancement of Fonts

This is a **BIG** PR.

In a nutshell,

1. Introduces a new concept **Glyph** which is a container for "bitmaps" from Fonts and Icons with a simple iterator. **Glyph** maintains a RAM-based image of the currently attached character in a format optimum for most display devices (GLCDFont-like). The image is dynamically allocated but is small and normally there is only 1 glyph. The memory impact can be minimized by staying with the default System5x7 font which requires only 5 bytes for the image.

2. Each Font and Icon style **renders** to the **Glyph-maintained** image. This means **any** Font or Icon can be displayed by **any** device (within device size constraints of course).

3. All the X11/Adobe fixed width fonts have been implemented. They were created by bdf2uc (https://github.com/jediunix/bdf2uc) from the original BDF files. They are defined in optimized GLCDFont format.

3. Test case CosaCanvasFontST7735 was created to exercise fonts on the ST7735. The active font is selected by a define. Test case CosaCanvasST7735 was updated to use **IconGlyphs**; the old method can be selected with a define. I've also tested with my CosaOLED driver. I do not have the other LCD devices to test. Full builds have been done on 1.5.8 and 1.0.6.

4. A lot of effort went into making this backward-compatible. In other words, any use of prior bitmaps, fonts, and icons should still work. Some APIs are marked **deprecated**, especially `get_bitmap()`.

5. Performance has degraded about 12% for Fonts with ST7735.

In the future, a compressed Font could be implemented easily. At this time there seems to be no good way to compress all Fonts for an environment as constrained as a microcontroller since it has to be per-character compression. However, a brief experiment with 0's compression saved ~30% on the largest fonts. At least now the foundation is available for more experimentation.

Hopefully I haven't forgotten anything significant. Please review and feel free to discuss concerns before merging.

Thanks!

P.S. Another variation considered was to standardize on the GLCDFont representation for everything. Consumers would have to convert any font that wasn't in than format. This would eliminate the need for a standardized image representation saving a few bytes of RAM and some CPU from rendering. I don't feel that displaying things is that speed-sensitive.