@@ -3153,8 +3153,10 @@ uint16_t TFT_eSPI::fontsLoaded(void)
3153
3153
** Function name: fontHeight
3154
3154
** Description: return the height of a font (yAdvance for free fonts)
3155
3155
***************************************************************************************/
3156
- int16_t TFT_eSPI::fontHeight (int16_t font)
3156
+ int16_t TFT_eSPI::fontHeight (uint8_t font)
3157
3157
{
3158
+ if (font > 8 ) return 0 ;
3159
+
3158
3160
#ifdef SMOOTH_FONT
3159
3161
if (fontLoaded) return gFont .yAdvance ;
3160
3162
#endif
@@ -3211,7 +3213,7 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32
3211
3213
3212
3214
setWindow (xd, yd, xd+5 , yd+7 );
3213
3215
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);
3215
3217
column[5 ] = 0 ;
3216
3218
3217
3219
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
3234
3236
if (i == 5 )
3235
3237
line = 0x0 ;
3236
3238
else
3237
- line = pgm_read_byte (font + (c * 5 ) + i);
3239
+ line = pgm_read_byte (& font[ 0 ] + (c * 5 ) + i);
3238
3240
3239
3241
if (size == 1 && !fillbg) { // default size
3240
3242
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)
5501
5503
// With font number. Note: font number is over-ridden if a smooth font is loaded
5502
5504
int16_t TFT_eSPI::drawString (const char *string, int32_t poX, int32_t poY, uint8_t font)
5503
5505
{
5506
+ if (font > 8 ) return 0 ;
5507
+
5504
5508
int16_t sumX = 0 ;
5505
5509
uint8_t padding = 1 , baseline = 0 ;
5506
5510
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)
5906
5910
void TFT_eSPI::setTextFont (uint8_t f)
5907
5911
{
5908
5912
textfont = (f > 0 ) ? f : 1 ; // Don't allow font 0
5913
+ textfont = (f > 8 ) ? 1 : f; // Don't allow font > 8
5909
5914
gfxFont = NULL ;
5910
5915
}
5911
5916
@@ -5931,6 +5936,7 @@ void TFT_eSPI::setFreeFont(uint8_t font)
5931
5936
void TFT_eSPI::setTextFont (uint8_t f)
5932
5937
{
5933
5938
textfont = (f > 0 ) ? f : 1 ; // Don't allow font 0
5939
+ textfont = (f > 8 ) ? 1 : f; // Don't allow font > 8
5934
5940
}
5935
5941
#endif
5936
5942
0 commit comments