From 5a30d7d022986349b3526d56e81b21c120ce9f52 Mon Sep 17 00:00:00 2001 From: Norbert Walter Date: Sat, 28 Feb 2026 18:23:23 +0000 Subject: [PATCH] Fix boot loop reimplement font implementation --- lib/obp60task/OBP60Extensions.h | 39 ++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/obp60task/OBP60Extensions.h b/lib/obp60task/OBP60Extensions.h index 7d2ae8c..f704c40 100644 --- a/lib/obp60task/OBP60Extensions.h +++ b/lib/obp60task/OBP60Extensions.h @@ -132,9 +132,44 @@ public: lgfx::LGFX_Device::setFont(nullptr); return; } + + if (font->glyph == nullptr || font->bitmap == nullptr || font->last < font->first) { + lgfx::LGFX_Device::setFont(nullptr); + return; + } + + const uint16_t glyphCount = static_cast(font->last - font->first + 1); + if (glyphCount == 0) { + lgfx::LGFX_Device::setFont(nullptr); + return; + } + + if (_adfGlyphCount != glyphCount || _adfGlyphBridge == nullptr) { + if (_adfGlyphBridge != nullptr) { + free(_adfGlyphBridge); + _adfGlyphBridge = nullptr; + _adfGlyphCount = 0; + } + _adfGlyphBridge = static_cast(malloc(sizeof(lgfx::GFXglyph) * glyphCount)); + if (_adfGlyphBridge == nullptr) { + lgfx::LGFX_Device::setFont(nullptr); + return; + } + _adfGlyphCount = glyphCount; + } + + for (uint16_t index = 0; index < glyphCount; ++index) { + _adfGlyphBridge[index].bitmapOffset = font->glyph[index].bitmapOffset; + _adfGlyphBridge[index].width = font->glyph[index].width; + _adfGlyphBridge[index].height = font->glyph[index].height; + _adfGlyphBridge[index].xAdvance = font->glyph[index].xAdvance; + _adfGlyphBridge[index].xOffset = font->glyph[index].xOffset; + _adfGlyphBridge[index].yOffset = font->glyph[index].yOffset; + } + _adfFontBridge = lgfx::GFXfont( const_cast(font->bitmap), - reinterpret_cast(const_cast(font->glyph)), + _adfGlyphBridge, font->first, font->last, font->yAdvance @@ -146,6 +181,8 @@ public: private: lgfx::GFXfont _adfFontBridge { nullptr, nullptr, 0, 0, 0 }; + lgfx::GFXglyph* _adfGlyphBridge = nullptr; + uint16_t _adfGlyphCount = 0; lgfx::Panel_ST7796 _panel_instance; };