Skip to content

Commit 8aa39cc

Browse files
committed
Fix #3090
1 parent df24f1b commit 8aa39cc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

TFT_eSPI.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,8 +3153,10 @@ uint16_t TFT_eSPI::fontsLoaded(void)
31533153
** Function name: fontHeight
31543154
** Description: return the height of a font (yAdvance for free fonts)
31553155
***************************************************************************************/
3156-
int16_t TFT_eSPI::fontHeight(int16_t font)
3156+
int16_t TFT_eSPI::fontHeight(uint8_t font)
31573157
{
3158+
if (font > 8) return 0;
3159+
31583160
#ifdef SMOOTH_FONT
31593161
if(fontLoaded) return gFont.yAdvance;
31603162
#endif
@@ -3211,7 +3213,7 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32
32113213

32123214
setWindow(xd, yd, xd+5, yd+7);
32133215

3214-
for (int8_t i = 0; i < 5; i++ ) column[i] = pgm_read_byte(font + (c * 5) + i);
3216+
for (int8_t i = 0; i < 5; i++ ) column[i] = pgm_read_byte(&font[0] + (c * 5) + i);
32153217
column[5] = 0;
32163218

32173219
for (int8_t j = 0; j < 8; j++) {
@@ -3234,7 +3236,7 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32
32343236
if (i == 5)
32353237
line = 0x0;
32363238
else
3237-
line = pgm_read_byte(font + (c * 5) + i);
3239+
line = pgm_read_byte(&font[0] + (c * 5) + i);
32383240

32393241
if (size == 1 && !fillbg) { // default size
32403242
for (int8_t j = 0; j < 8; j++) {
@@ -5501,6 +5503,8 @@ int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY)
55015503
// With font number. Note: font number is over-ridden if a smooth font is loaded
55025504
int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY, uint8_t font)
55035505
{
5506+
if (font > 8) return 0;
5507+
55045508
int16_t sumX = 0;
55055509
uint8_t padding = 1, baseline = 0;
55065510
uint16_t cwidth = textWidth(string, font); // Find the pixel width of the string in the font
@@ -5906,6 +5910,7 @@ void TFT_eSPI::setFreeFont(const GFXfont *f)
59065910
void TFT_eSPI::setTextFont(uint8_t f)
59075911
{
59085912
textfont = (f > 0) ? f : 1; // Don't allow font 0
5913+
textfont = (f > 8) ? 1 : f; // Don't allow font > 8
59095914
gfxFont = NULL;
59105915
}
59115916

@@ -5931,6 +5936,7 @@ void TFT_eSPI::setFreeFont(uint8_t font)
59315936
void TFT_eSPI::setTextFont(uint8_t f)
59325937
{
59335938
textfont = (f > 0) ? f : 1; // Don't allow font 0
5939+
textfont = (f > 8) ? 1 : f; // Don't allow font > 8
59345940
}
59355941
#endif
59365942

TFT_eSPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
681681
textWidth(const char *string), // Returns pixel width of string in current font
682682
textWidth(const String& string, uint8_t font), // As above for String types
683683
textWidth(const String& string),
684-
fontHeight(int16_t font), // Returns pixel height of specified font
684+
fontHeight(uint8_t font), // Returns pixel height of specified font
685685
fontHeight(void); // Returns pixel height of current font
686686

687687
// Used by library and Smooth font class to extract Unicode point codes from a UTF8 encoded string

0 commit comments

Comments
 (0)