void DMDFrame::drawString(int x, int y, const String &str, DMDGraphicsMode mode, const uint8_t *font) { if(!font) font = this->font; if (x >= (int)pixel_width() || y >= (int)pixel_height()) return; _drawString(this, x, y, str, mode, font); }
void DMDFrame::drawString(int x, int y, const char *bChars, bool inverse, const uint8_t *font) { if(!font) font = this->font; if (x >= (int)pixel_width() || y >= (int)pixel_height()) return; _drawString(this, x, y, bChars, inverse, font); }
void DMDFrame::drawString_P(int x, int y, const char *flashStr, DMDGraphicsMode mode, const uint8_t *font) { if(!font) font = this->font; if(x >= (int)pixel_width() || y >= (int)pixel_height()) return; _FlashStringWrapper wrapper(flashStr); _drawString(this, x, y, wrapper, mode, font); }
int DMDFrame::drawChar(const int x, const int y, const char letter, DMDGraphicsMode mode, const uint8_t *font) { if(!font) font = this->font; if(x >= (int)pixel_width() || y >= (int)pixel_height()) return -1; struct FontHeader header; memcpy_P(&header, (void*)font, sizeof(FontHeader)); char c = letter; if (c == ' ') { int charWide = charWidth(' '); this->drawFilledBox(x, y, x + charWide, y + header.height, mode); return charWide; } uint8_t width = 0; uint8_t bytes = (header.height + 7) / 8; uint16_t index = 0; if (c < header.firstChar || c >= (header.firstChar + header.charCount)) return 0; c -= header.firstChar; if (header.size == 0) { // zero length is flag indicating fixed width font (array does not contain width data entries) width = header.fixedWidth; index = sizeof(FontHeader) + c * bytes * width; } else { // variable width font, read width data, to get the index for (uint8_t i = 0; i < c; i++) { index += pgm_read_byte(font + sizeof(FontHeader) + i); } index = index * bytes + header.charCount + sizeof(FontHeader); width = pgm_read_byte(font + sizeof(FontHeader) + c); } if (x < -width || y < -header.height) return width; bool inverse = false; if (mode == GRAPHICS_INVERSE) { inverse = true; } // last but not least, draw the character for (uint8_t j = 0; j < width; j++) { // Width for (uint8_t i = bytes - 1; i < 254; i--) { // Vertical Bytes uint8_t data = pgm_read_byte(font + index + j + (i * width)); int offset = (i * 8); if ((i == bytes - 1) && bytes > 1) { offset = header.height - 8; } for (uint8_t k = 0; k < 8; k++) { // Vertical bits if ((offset+k >= i*8) && (offset+k <= header.height)) { if (data & (1 << k)) { if(inverse) { setPixel(x + j, y + offset + k, GRAPHICS_OFF); } else { setPixel(x + j, y + offset + k, GRAPHICS_NORMAL); } } else { if(inverse) { setPixel(x + j, y + offset + k, GRAPHICS_NORMAL); } else { setPixel(x + j, y + offset + k, GRAPHICS_OFF); } } } } } } return width; }