#pragma once #include "Fonts.hpp" #include "app_framework.hpp" #include #include #include namespace font16x8 { constexpr int kGlyphWidth = 8; constexpr int kGlyphHeight = 16; constexpr unsigned char kFallbackChar = '?'; inline unsigned char normalizeChar(char ch) { unsigned char uc = static_cast(ch); if (uc >= 'a' && uc <= 'z') uc = static_cast(std::toupper(static_cast(uc))); if (!std::isprint(static_cast(uc))) return kFallbackChar; return uc; } inline const std::array& glyphBitmap(char ch) { unsigned char uc = normalizeChar(ch); return fonts_Terminess_Powerline[uc]; } inline void drawGlyph(IFramebuffer& fb, int x, int y, char ch, int scale = 1, bool on = true) { const auto& rows = glyphBitmap(ch); for (int row = 0; row < kGlyphHeight; ++row) { const uint8_t rowBits = rows[row]; for (int col = 0; col < kGlyphWidth; ++col) { const uint8_t mask = static_cast(1u << (kGlyphWidth - 1 - col)); if (rowBits & mask) { for (int sx = 0; sx < scale; ++sx) for (int sy = 0; sy < scale; ++sy) fb.drawPixel(x + col * scale + sx, y + row * scale + sy, on); } } } } inline int measureText(std::string_view text, int scale = 1, int letterSpacing = 1) { if (text.empty()) return 0; const int advance = (kGlyphWidth + letterSpacing) * scale; return static_cast(text.size()) * advance - letterSpacing * scale; } inline void drawText(IFramebuffer& fb, int x, int y, std::string_view text, int scale = 1, bool on = true, int letterSpacing = 1) { int cursor = x; for (char ch: text) { drawGlyph(fb, cursor, y, ch, scale, on); cursor += (kGlyphWidth + letterSpacing) * scale; } } } // namespace font16x8