fix: scale Lemon font glyphs with setTextSize on lock screen clock

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-20 10:32:26 +02:00
parent 319428c7c6
commit fa842b202a
2 changed files with 23 additions and 11 deletions

View File

@@ -43,11 +43,13 @@ void SH1106Display::startFrame(Color bkg)
_color = SH110X_WHITE;
display.setTextColor(_color);
display.setTextSize(1);
_text_sz = 1;
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
void SH1106Display::setTextSize(int sz)
{
_text_sz = sz;
display.setTextSize(sz);
}
@@ -88,6 +90,7 @@ uint32_t SH1106Display::decodeUtf8(const uint8_t*& p) {
}
int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
int sz = _text_sz;
for (uint8_t i = 0; i < lemonIconCount; i++) {
if (pgm_read_dword(&lemonIconCPs[i]) == cp) {
const GFXglyph* g = &lemonIconGlyphs[i];
@@ -99,16 +102,19 @@ int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
for (uint8_t row = 0; row < h; row++)
for (uint8_t col = 0; col < w; col++) {
if (!bit) { bits = pgm_read_byte(&lemonIconBitmaps[bo++]); bit = 0x80; }
if (bits & bit) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
if (bits & bit) {
if (sz == 1) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
else display.fillRect(x + xo*sz + col*sz, y + 6*sz + yo*sz + row*sz, sz, sz, _color);
}
bit >>= 1;
}
return x + xa;
return x + xa * sz;
}
}
if (cp < Lemon.first || cp > Lemon.last) {
if (cp >= 0x20) display.fillRect(x + 1, y - 1, 4, 6, _color);
return x + 6;
if (cp >= 0x20) display.fillRect(x + sz, y - sz, 4*sz, 6*sz, _color);
return x + 6 * sz;
}
const GFXglyph* g = &lemonGlyphs[cp - Lemon.first];
uint8_t w = pgm_read_byte(&g->width), h = pgm_read_byte(&g->height);
@@ -119,15 +125,20 @@ int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
for (uint8_t row = 0; row < h; row++)
for (uint8_t col = 0; col < w; col++) {
if (!bit) { bits = pgm_read_byte(&lemonBitmaps[bo++]); bit = 0x80; }
if (bits & bit) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
if (bits & bit) {
if (sz == 1) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
else display.fillRect(x + xo*sz + col*sz, y + 6*sz + yo*sz + row*sz, sz, sz, _color);
}
bit >>= 1;
}
return x + xa;
return x + xa * sz;
}
uint8_t SH1106Display::lemonXAdvance(uint32_t cp) {
if (cp < Lemon.first || cp > Lemon.last) return 6;
return pgm_read_byte(&lemonGlyphs[cp - Lemon.first].xAdvance);
uint8_t xa;
if (cp < Lemon.first || cp > Lemon.last) xa = 6;
else xa = pgm_read_byte(&lemonGlyphs[cp - Lemon.first].xAdvance);
return xa * _text_sz;
}
void SH1106Display::translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) {

View File

@@ -22,6 +22,7 @@ class SH1106Display : public DisplayDriver
uint8_t _contrast;
uint8_t _precharge;
bool _use_lemon;
int _text_sz;
bool i2c_probe(TwoWire &wire, uint8_t addr);
static uint32_t decodeUtf8(const uint8_t*& p);
@@ -30,7 +31,7 @@ class SH1106Display : public DisplayDriver
public:
SH1106Display() : DisplayDriver(128, 64), display(128, 64, &Wire, PIN_OLED_RESET) {
_isOn = false; _contrast = 255; _precharge = 0x1F; _use_lemon = false;
_isOn = false; _contrast = 255; _precharge = 0x1F; _use_lemon = false; _text_sz = 1;
}
bool begin();
@@ -47,8 +48,8 @@ public:
void drawRect(int x, int y, int w, int h) override;
void drawXbm(int x, int y, const uint8_t *bits, int w, int h) override;
uint16_t getTextWidth(const char *str) override;
int getCharWidth() const override { return _use_lemon ? 5 : 6; }
int getLineHeight() const override { return _use_lemon ? 9 : 8; }
int getCharWidth() const override { return (_use_lemon ? 5 : 6) * _text_sz; }
int getLineHeight() const override { return (_use_lemon ? 9 : 8) * _text_sz; }
void setLemonFont(bool enabled) override { _use_lemon = enabled; }
void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) override;
void setBrightness(uint8_t level) override;