Uses the same fonts as the SPI_TFT_ILI9341 Library (I have many, and a html/php font editor for that)
Diff: SPI_TFT_ILI9225.cpp
- Revision:
- 14:a7640e7e9f80
- Parent:
- 13:9e6589dc8864
- Child:
- 15:4b8c052d386a
--- a/SPI_TFT_ILI9225.cpp Wed Nov 23 13:30:20 2016 +0000 +++ b/SPI_TFT_ILI9225.cpp Wed Nov 23 16:09:25 2016 +0000 @@ -603,7 +603,7 @@ void TFT_22_ILI9225::character(int x, int y, int c) { unsigned int hor, vert, offset, bpl, i, j, b; - unsigned char* zeichen; + unsigned char* char_ptr; unsigned char z,w; if ((c < 31) || (c > 127)) return; // test char range @@ -623,14 +623,14 @@ } _setWindow(char_x, char_y, (char_x+hor)-1, (char_y+vert)-1); - zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap - w = zeichen[0]; // width of actual char + char_ptr = &font[((c -32) * offset) + 4]; // start of char bitmap + w = char_ptr[0]; // width of actual char _startData(); // Portrait for (j = 0; j < vert; j++) { // vert line for (i = 0; i < hor; i++) { // horz line - z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; + z = char_ptr[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); if (( z & b ) == 0x00) { _spi.write(_background >> 8); @@ -646,9 +646,34 @@ _setWindowMax(); if ((w + 2) < hor) { // x offset to next char char_x += w + 2; - } else char_x += hor; + } else { + char_x += hor; + } } - + +uint16_t TFT_22_ILI9225::getStringWidth(char * s) +{ + unsigned char* char_ptr; + uint16_t width = 0; + uint16_t offset = font[FONT_LENGTH]; // bytes / char + uint16_t hor = font[FONT_HORZ]; // get hor size of font + + uint16_t len = strlen(s); + for (uint8_t i = 0; i < len; i++) { + if ((s[i] < 31) || (s[i] > 127)) { + continue; // test char range + } + char_ptr = &font[((s[i] -32) * offset) + 4]; // start of char bitmap + unsigned char w = char_ptr[0]; + if ((w + 2) < hor) { // x offset to next char + width += w + 2; + } else { + width += hor; + } + } + return width; +} + void TFT_22_ILI9225::foreground(uint16_t color) { _foreground = color;