From fa842b202ab2df16cbf27b762f9637d7ebcccaef Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Wed, 20 May 2026 10:32:26 +0200 Subject: [PATCH] fix: scale Lemon font glyphs with setTextSize on lock screen clock Co-Authored-By: Claude Sonnet 4.6 --- src/helpers/ui/SH1106Display.cpp | 27 +++++++++++++++++++-------- src/helpers/ui/SH1106Display.h | 7 ++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/helpers/ui/SH1106Display.cpp b/src/helpers/ui/SH1106Display.cpp index 25913c20..79455b04 100644 --- a/src/helpers/ui/SH1106Display.cpp +++ b/src/helpers/ui/SH1106Display.cpp @@ -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) { diff --git a/src/helpers/ui/SH1106Display.h b/src/helpers/ui/SH1106Display.h index 5e92b0a8..53900804 100644 --- a/src/helpers/ui/SH1106Display.h +++ b/src/helpers/ui/SH1106Display.h @@ -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;