| 693 | } |
| 694 | |
| 695 | void drawString(TFT_eSprite &spr, String content, int16_t posx, int16_t posy, String font, byte align, uint16_t color, uint16_t size, uint16_t bgcolor) { |
| 696 | // drawString(spr,"test",100,10,"bahnschrift30",TC_DATUM,TFT_RED); |
| 697 | |
| 698 | // backwards compitibility |
| 699 | replaceVariables(content); |
| 700 | if (font.startsWith("fonts/calibrib")) { |
| 701 | String numericValueStr = font.substring(14); |
| 702 | int calibriSize = numericValueStr.toInt(); |
| 703 | if (calibriSize != 30 && calibriSize != 16) { |
| 704 | font = "Signika-SB.ttf"; |
| 705 | size = calibriSize; |
| 706 | } |
| 707 | } |
| 708 | if (font == "glasstown_nbp_tf") { |
| 709 | font = "tahoma9.vlw"; |
| 710 | posy -= 8; |
| 711 | } |
| 712 | if (font == "7x14_tf") { |
| 713 | font = "REFSAN12.vlw"; |
| 714 | posy -= 10; |
| 715 | } |
| 716 | if (font == "t0_14b_tf") { |
| 717 | font = "calibrib16.vlw"; |
| 718 | posy -= 11; |
| 719 | } |
| 720 | |
| 721 | switch (processFontPath(font)) { |
| 722 | case 2: { |
| 723 | // truetype |
| 724 | time_t t = millis(); |
| 725 | truetypeClass truetype = truetypeClass(); |
| 726 | void *framebuffer = spr.getPointer(); |
| 727 | truetype.setFramebuffer(spr.width(), spr.height(), spr.getColorDepth(), static_cast<uint8_t *>(framebuffer)); |
| 728 | File fontFile = contentFS->open(font, "r"); |
| 729 | if (!truetype.setTtfFile(fontFile)) { |
| 730 | Serial.println("read ttf failed"); |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | truetype.setCharacterSize(size); |
| 735 | truetype.setCharacterSpacing(0); |
| 736 | if (align == TC_DATUM) { |
| 737 | posx -= truetype.getStringWidth(content) / 2; |
| 738 | } |
| 739 | if (align == TR_DATUM) { |
| 740 | posx -= truetype.getStringWidth(content); |
| 741 | } |
| 742 | truetype.setTextBoundary(posx, spr.width(), spr.height()); |
| 743 | if (spr.getColorDepth() == 8) { |
| 744 | truetype.setTextColor(spr.color16to8(color), spr.color16to8(color)); |
| 745 | } else { |
| 746 | truetype.setTextColor(color, color); |
| 747 | } |
| 748 | truetype.textDraw(posx, posy, content); |
| 749 | truetype.end(); |
| 750 | } break; |
| 751 | case 3: { |
| 752 | // vlw bitmap font |
no test coverage detected