introduced compiler switch SMOOTH_FONT_OVERRIDE_BG
When defined, smooth font clears out the background while drawing a glyph. This approach takes the balance between memory consumption (sprites) and flicker (blank out complete rectangle before drawing new string).
This commit is contained in:
parent
6f2c5f7301
commit
9555868eda
|
|
@ -365,7 +365,13 @@ void TFT_eSPI::drawGlyph(uint16_t code)
|
||||||
if (code < 0x21)
|
if (code < 0x21)
|
||||||
{
|
{
|
||||||
if (code == 0x20) {
|
if (code == 0x20) {
|
||||||
//if (fg!=bg) fillRect(cursor_x, cursor_y, gFont.spaceWidth, gFont.yAdvance, bg);
|
|
||||||
|
#ifdef SMOOTH_FONT_OVERRIDE_BG
|
||||||
|
|
||||||
|
if (fg!=bg) fillRect(cursor_x, cursor_y, gFont.spaceWidth, gFont.yAdvance, bg);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
cursor_x += gFont.spaceWidth;
|
cursor_x += gFont.spaceWidth;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -414,6 +420,19 @@ void TFT_eSPI::drawGlyph(uint16_t code)
|
||||||
|
|
||||||
//if (fg!=bg) fillRect(cursor_x, cursor_y, gxAdvance[gNum], gFont.yAdvance, bg);
|
//if (fg!=bg) fillRect(cursor_x, cursor_y, gxAdvance[gNum], gFont.yAdvance, bg);
|
||||||
|
|
||||||
|
#ifdef SMOOTH_FONT_OVERRIDE_BG
|
||||||
|
|
||||||
|
if (gdY[gNum] < (2 * (gFont.ascent + gFont.descent)))
|
||||||
|
{
|
||||||
|
// strange condition, explanation see below
|
||||||
|
for (int y = 0; y < (gFont.maxAscent - gdY[gNum]); ++y)
|
||||||
|
{
|
||||||
|
drawFastHLine(cursor_x, cursor_y + y, gxAdvance[gNum], bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int y = 0; y < gHeight[gNum]; y++)
|
for (int y = 0; y < gHeight[gNum]; y++)
|
||||||
{
|
{
|
||||||
#ifdef FONT_FS_AVAILABLE
|
#ifdef FONT_FS_AVAILABLE
|
||||||
|
|
@ -432,6 +451,16 @@ void TFT_eSPI::drawGlyph(uint16_t code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SMOOTH_FONT_OVERRIDE_BG
|
||||||
|
|
||||||
|
if (gdY[gNum] < (2 * (gFont.ascent + gFont.descent)))
|
||||||
|
{
|
||||||
|
drawFastHLine(cursor_x, y + cy, gxAdvance[gNum], bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int x = 0; x < gWidth[gNum]; x++)
|
for (int x = 0; x < gWidth[gNum]; x++)
|
||||||
{
|
{
|
||||||
#ifdef FONT_FS_AVAILABLE
|
#ifdef FONT_FS_AVAILABLE
|
||||||
|
|
@ -466,6 +495,35 @@ void TFT_eSPI::drawGlyph(uint16_t code)
|
||||||
if (dl) { drawFastHLine( xs, y + cy, dl, fg); dl = 0; }
|
if (dl) { drawFastHLine( xs, y + cy, dl, fg); dl = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SMOOTH_FONT_OVERRIDE_BG
|
||||||
|
|
||||||
|
if (gdY[gNum] == (2 * (gFont.ascent + gFont.descent)))
|
||||||
|
{
|
||||||
|
// odd, unexpected situation,
|
||||||
|
// happens with an unicode special space character (not 0x20)
|
||||||
|
// with no pixels in it
|
||||||
|
// e.g. Six-Per-Em Space U+2006
|
||||||
|
//
|
||||||
|
// With NotoSans Regular, size 50, I got the following values:
|
||||||
|
// ascent: 38, maxAscent: 38, maxDescent: 12, descent: 12
|
||||||
|
// gxAdvance: 8, gdX: 4294967246
|
||||||
|
// gHeight: 1, gdY: 100
|
||||||
|
|
||||||
|
for (int y = 0; y < (gFont.ascent + gFont.descent); ++y)
|
||||||
|
{
|
||||||
|
drawFastHLine(cursor_x, y + cursor_y, gxAdvance[gNum], bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int y = 0; y < (gFont.descent - (gHeight[gNum] - gdY[gNum])); ++y)
|
||||||
|
{
|
||||||
|
drawFastHLine(cursor_x, y + cursor_y + gFont.ascent + (gHeight[gNum] - gdY[gNum]), gxAdvance[gNum], bg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if (pbuffer) free(pbuffer);
|
if (pbuffer) free(pbuffer);
|
||||||
cursor_x += gxAdvance[gNum];
|
cursor_x += gxAdvance[gNum];
|
||||||
endWrite();
|
endWrite();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue