Skip to content

Commit e2a0a3b

Browse files
committed
Fixed sprite unicode support
1 parent a499ef0 commit e2a0a3b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/utility/Sprite.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,11 @@ void TFT_eSprite::scroll(int16_t dx, int16_t dy)
990990
** Function name: fillSprite
991991
** Description: Fill the whole sprite with defined colour
992992
*************************************************************************************x*/
993+
void TFT_eSprite::fillScreen(uint32_t color)
994+
{
995+
fillSprite(color);
996+
}
997+
993998
void TFT_eSprite::fillSprite(uint32_t color)
994999
{
9951000
if (!_created ) return;
@@ -1433,10 +1438,19 @@ size_t TFT_eSprite::write(uint8_t utf8)
14331438
this->cursor_x = 0;
14341439
this->cursor_y += (int16_t)textsize * (uint8_t)pgm_read_byte(&gfxFont->yAdvance);
14351440
} else {
1441+
#ifdef USE_M5_FONT_CREATOR
1442+
int32_t index = -1;
1443+
index = getUnicodeFontIndex(uniCode);
1444+
if (index == -1) {
1445+
return 1;
1446+
}
1447+
uint16_t c2 = index;
1448+
#else
14361449
if (uniCode > pgm_read_word(&gfxFont->last )) return 1;
14371450
if (uniCode < pgm_read_word(&gfxFont->first)) return 1;
14381451

14391452
uint8_t c2 = uniCode - pgm_read_word(&gfxFont->first);
1453+
#endif
14401454
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c2]);
14411455
uint8_t w = pgm_read_byte(&glyph->width),
14421456
h = pgm_read_byte(&glyph->height);
@@ -1542,16 +1556,24 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uin
15421556
#endif // LOAD_GLCD
15431557

15441558
#ifdef LOAD_GFXFF
1559+
#ifdef USE_M5_FONT_CREATOR
1560+
int32_t index = -1;
1561+
index = getUnicodeFontIndex(c);
1562+
if (index != -1)
1563+
{
1564+
c = index;
1565+
#else
15451566
// Filter out bad characters not present in font
15461567
if ((c >= pgm_read_word(&gfxFont->first)) && (c <= pgm_read_word(&gfxFont->last )))
15471568
{
15481569
//>>>>>>>>>>>>>>>>>>>>>>>>>>>
15491570

15501571
c -= pgm_read_word(&gfxFont->first);
1572+
#endif
15511573
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c]);
15521574
uint8_t *bitmap = (uint8_t *)pgm_read_dword(&gfxFont->bitmap);
15531575

1554-
uint32_t bo = pgm_read_word(&glyph->bitmapOffset);
1576+
uint32_t bo = pgm_read_dword(&glyph->bitmapOffset);
15551577
uint8_t w = pgm_read_byte(&glyph->width),
15561578
h = pgm_read_byte(&glyph->height);
15571579
//xa = pgm_read_byte(&glyph->xAdvance);
@@ -1643,9 +1665,17 @@ int16_t TFT_eSprite::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t fo
16431665
}
16441666
else
16451667
{
1668+
#ifdef USE_M5_FONT_CREATOR
1669+
int32_t index = -1;
1670+
index = getUnicodeFontIndex(uniCode);
1671+
if (index != -1)
1672+
{
1673+
uint16_t c2 = index;
1674+
#else
16461675
if((uniCode >= pgm_read_word(&gfxFont->first)) && (uniCode <= pgm_read_word(&gfxFont->last) ))
16471676
{
16481677
uint16_t c2 = uniCode - pgm_read_word(&gfxFont->first);
1678+
#endif
16491679
GFXglyph *glyph = &(((GFXglyph *)pgm_read_dword(&gfxFont->glyph))[c2]);
16501680
return pgm_read_byte(&glyph->xAdvance) * textsize;
16511681
}

src/utility/Sprite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TFT_eSprite : public TFT_eSPI {
3434

3535
void drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size),
3636

37+
fillScreen(uint32_t color),
3738
fillSprite(uint32_t color),
3839

3940
// Define a window to push 16 bit colour pixels into in a raster order

0 commit comments

Comments
 (0)