Files
TFT_eSPI/Extensions/Smooth_font.h
T

61 lines
2.1 KiB
C++
Raw Normal View History

2018-02-24 19:02:20 +00:00
// Coded by Bodmer 10/2/18, see license in root directory.
// This is part of the TFT_eSPI class and is associated with anti-aliased font functions
public:
2022-05-16 19:58:05 +01:00
// These are for the new anti-aliased fonts
2020-02-14 23:54:37 +00:00
void loadFont(const uint8_t array[]);
#ifdef FONT_FS_AVAILABLE
void loadFont(String fontName, fs::FS &ffs);
2020-02-14 23:54:37 +00:00
#endif
void loadFont(String fontName, bool flash = true);
2018-02-24 19:02:20 +00:00
void unloadFont( void );
bool getUnicodeIndex(uint16_t unicode, uint16_t *index);
virtual void drawGlyph(uint16_t code);
2018-02-24 19:02:20 +00:00
void showFont(uint32_t td);
// This is for the whole font
2018-02-24 19:02:20 +00:00
typedef struct
{
2020-02-15 11:28:31 +00:00
const uint8_t* gArray; //array start pointer
2020-02-14 23:54:37 +00:00
uint16_t gCount; // Total number of characters
uint16_t yAdvance; // Line advance
uint16_t spaceWidth; // Width of a space character
int16_t ascent; // Height of top of 'd' above baseline, other characters may be taller
int16_t descent; // Offset to bottom of 'p', other characters may have a larger descent
uint16_t maxAscent; // Maximum ascent found in font
uint16_t maxDescent; // Maximum descent found in font
2018-02-24 19:02:20 +00:00
} fontMetrics;
2020-02-15 11:28:31 +00:00
fontMetrics gFont = { nullptr, 0, 0, 0, 0, 0, 0, 0 };
2018-02-24 19:02:20 +00:00
// These are for the metrics for each individual glyph (so we don't need to seek this in file and waste time)
uint16_t* gUnicode = NULL; //UTF-16 code, the codes are searched so do not need to be sequential
uint8_t* gHeight = NULL; //cheight
uint8_t* gWidth = NULL; //cwidth
uint8_t* gxAdvance = NULL; //setWidth
2019-02-20 23:33:21 +00:00
int16_t* gdY = NULL; //topExtent
2018-02-24 19:02:20 +00:00
int8_t* gdX = NULL; //leftExtent
uint32_t* gBitmap = NULL; //file pointer to greyscale bitmap
bool fontLoaded = false; // Flags when a anti-aliased font is loaded
2020-02-14 23:54:37 +00:00
#ifdef FONT_FS_AVAILABLE
fs::File fontFile;
fs::FS &fontFS = SPIFFS;
bool spiffs = true;
bool fs_font = false; // For ESP32/8266 use smooth font file or FLASH (PROGMEM) array
2020-02-14 23:54:37 +00:00
#else
bool fontFile = true;
#endif
2018-02-24 19:02:20 +00:00
private:
2018-02-24 19:02:20 +00:00
2020-02-14 23:54:37 +00:00
void loadMetrics(void);
2018-02-24 19:02:20 +00:00
uint32_t readInt32(void);
2020-02-14 23:54:37 +00:00
uint8_t* fontPtr = nullptr;