mirror of
https://github.com/Bodmer/TFT_eSPI.git
synced 2025-08-07 06:34:44 +02:00
Filter bad character codes
Do not substitute bad characters for first valid one.
This commit is contained in:
46
TFT_eSPI.cpp
46
TFT_eSPI.cpp
@@ -572,7 +572,7 @@ uint16_t TFT_eSPI::readPixel(int32_t x0, int32_t y0)
|
||||
int32_t len = dw;
|
||||
uint8_t* ptr = (uint8_t*)data;
|
||||
|
||||
// Make pointer 32 bit align using imune call then use the faster writeBytes()
|
||||
// Make pointer 32 bit align using immune call then use the faster writeBytes()
|
||||
if (offset) { SPI.writePattern(ptr, offset, 1); len -= offset; ptr += offset; }
|
||||
|
||||
if (len) SPI.writeBytes(ptr, len);
|
||||
@@ -1401,8 +1401,8 @@ int16_t TFT_eSPI::textWidth(const char *string, int font)
|
||||
while (*string)
|
||||
{
|
||||
uniCode = *(string++);
|
||||
if (uniCode < (uint8_t)pgm_read_byte(&gfxFont->first)) uniCode = pgm_read_byte(&gfxFont->first);
|
||||
if (uniCode > (uint8_t)pgm_read_byte(&gfxFont->last )) uniCode = pgm_read_byte(&gfxFont->first);
|
||||
if ((uniCode >= (uint8_t)pgm_read_byte(&gfxFont->first)) && (uniCode <= (uint8_t)pgm_read_byte(&gfxFont->last )))
|
||||
{
|
||||
uniCode -= pgm_read_byte(&gfxFont->first);
|
||||
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[uniCode]);
|
||||
// If this is not the last character then use xAdvance
|
||||
@@ -1411,6 +1411,7 @@ int16_t TFT_eSPI::textWidth(const char *string, int font)
|
||||
else str_width += ((int8_t)pgm_read_byte(&glyph->xOffset) + pgm_read_byte(&glyph->width));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
@@ -1567,14 +1568,13 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, unsigned char c, uint32_t color, u
|
||||
#endif // LOAD_GLCD
|
||||
|
||||
#ifdef LOAD_GFXFF
|
||||
// Filter out bad characters not present in font
|
||||
if ((c >= (uint8_t)pgm_read_byte(&gfxFont->first)) && (c <= (uint8_t)pgm_read_byte(&gfxFont->last )))
|
||||
{
|
||||
spi_begin();
|
||||
inTransaction = true;
|
||||
//>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Character is assumed previously filtered by write() to eliminate
|
||||
// newlines, returns, non-printable characters, etc. Calling drawChar()
|
||||
// directly with 'bad' characters of font may cause mayhem!
|
||||
if (c < (uint8_t)pgm_read_byte(&gfxFont->first)) c = pgm_read_byte(&gfxFont->first);
|
||||
if (c > (uint8_t)pgm_read_byte(&gfxFont->last )) c = pgm_read_byte(&gfxFont->first);
|
||||
|
||||
c -= pgm_read_byte(&gfxFont->first);
|
||||
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c]);
|
||||
uint8_t *bitmap = (uint8_t *)pgm_read_dword(&gfxFont->bitmap);
|
||||
@@ -1696,6 +1696,7 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, unsigned char c, uint32_t color, u
|
||||
#endif
|
||||
inTransaction = false;
|
||||
spi_end();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3040,9 +3041,7 @@ int16_t TFT_eSPI::drawChar(unsigned int uniCode, int x, int y, int font)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uniCode > pgm_read_byte(&gfxFont->last)) uniCode = pgm_read_byte(&gfxFont->first);
|
||||
|
||||
if(uniCode >= pgm_read_byte(&gfxFont->first))
|
||||
if((uniCode >= pgm_read_byte(&gfxFont->first)) && (uniCode <= pgm_read_byte(&gfxFont->last) ))
|
||||
{
|
||||
uint8_t c2 = uniCode - pgm_read_byte(&gfxFont->first);
|
||||
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c2]);
|
||||
@@ -3056,7 +3055,7 @@ int16_t TFT_eSPI::drawChar(unsigned int uniCode, int x, int y, int font)
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((font>1) && (font<9) && ((uniCode < 32) || (uniCode > 122))) return 0;
|
||||
if ((font>1) && (font<9) && ((uniCode < 32) || (uniCode > 127))) return 0;
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
@@ -3404,8 +3403,8 @@ int16_t TFT_eSPI::drawString(const char *string, int poX, int poY, int font)
|
||||
cheight = (glyph_ab + glyph_bb) * textsize;
|
||||
// Get the offset for the first character only to allow for negative offsets
|
||||
uint8_t c2 = *string;
|
||||
if (c2 < (uint8_t)pgm_read_byte(&gfxFont->first)) c2 = pgm_read_byte(&gfxFont->first);
|
||||
if (c2 > (uint8_t)pgm_read_byte(&gfxFont->last )) c2 = pgm_read_byte(&gfxFont->first);
|
||||
if((c2 >= pgm_read_byte(&gfxFont->first)) && (c2 <= pgm_read_byte(&gfxFont->last) ))
|
||||
{
|
||||
c2 -= pgm_read_byte(&gfxFont->first);
|
||||
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c2]);
|
||||
xo = pgm_read_byte(&glyph->xOffset) * textsize;
|
||||
@@ -3416,6 +3415,7 @@ int16_t TFT_eSPI::drawString(const char *string, int poX, int poY, int font)
|
||||
//cheight +=2;
|
||||
//fillRect(poX+xo-1, poY - 1 - glyph_ab * textsize, cwidth+2, cheight, textbgcolor);
|
||||
fillRect(poX+xo, poY - glyph_ab * textsize, cwidth, cheight, textbgcolor);
|
||||
}
|
||||
padding -=100;
|
||||
}
|
||||
#endif
|
||||
@@ -4587,13 +4587,11 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, unsigned char c, uint32_t color
|
||||
#endif // LOAD_GLCD
|
||||
|
||||
#ifdef LOAD_GFXFF
|
||||
|
||||
// Filter out bad characters not present in font
|
||||
if ((c >= (uint8_t)pgm_read_byte(&gfxFont->first)) && (c <= (uint8_t)pgm_read_byte(&gfxFont->last )))
|
||||
{
|
||||
//>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Character is assumed previously filtered by write() to eliminate
|
||||
// newlines, returns, non-printable characters, etc. Calling drawChar()
|
||||
// directly with 'bad' characters of font may cause mayhem!
|
||||
if (c < (uint8_t)pgm_read_byte(&gfxFont->first)) c = pgm_read_byte(&gfxFont->first);
|
||||
if (c > (uint8_t)pgm_read_byte(&gfxFont->last )) c = pgm_read_byte(&gfxFont->first);
|
||||
|
||||
c -= pgm_read_byte(&gfxFont->first);
|
||||
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c]);
|
||||
uint8_t *bitmap = (uint8_t *)pgm_read_dword(&gfxFont->bitmap);
|
||||
@@ -4636,7 +4634,7 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, unsigned char c, uint32_t color
|
||||
hpc=0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -4975,9 +4973,7 @@ int16_t TFT_eSprite::drawChar(unsigned int uniCode, int x, int y, int font)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uniCode > pgm_read_byte(&gfxFont->last)) uniCode = pgm_read_byte(&gfxFont->first);
|
||||
|
||||
if(uniCode >= pgm_read_byte(&gfxFont->first))
|
||||
if((uniCode >= pgm_read_byte(&gfxFont->first)) && (uniCode <= pgm_read_byte(&gfxFont->last) ))
|
||||
{
|
||||
uint8_t c2 = uniCode - pgm_read_byte(&gfxFont->first);
|
||||
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c2]);
|
||||
@@ -4991,7 +4987,7 @@ int16_t TFT_eSprite::drawChar(unsigned int uniCode, int x, int y, int font)
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((font>1) && (font<9) && ((uniCode < 32) || (uniCode > 122))) return 0;
|
||||
if ((font>1) && (font<9) && ((uniCode < 32) || (uniCode > 127))) return 0;
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
Reference in New Issue
Block a user