#pragma once #include #include #include #include class FontDecompressor; class FontCacheManager { public: explicit FontCacheManager(const std::map& fontMap); void setFontDecompressor(FontDecompressor* d); void clearCache(); void prewarmCache(int fontId, const char* utf8Text, uint8_t styleMask = 0x0F); void logStats(const char* label = "render"); void resetStats(); // Scan-mode API: called by GfxRenderer::drawText() during scan pass bool isScanning() const; void recordText(const char* text, int fontId, EpdFontFamily::Style style); // The FontDecompressor pointer, needed by GfxRenderer::getGlyphBitmap() FontDecompressor* getDecompressor() const { return fontDecompressor_; } // RAII scope for two-pass prewarm pattern class PrewarmScope { public: explicit PrewarmScope(FontCacheManager& manager); ~PrewarmScope(); void endScanAndPrewarm(); PrewarmScope(PrewarmScope&& other) noexcept; PrewarmScope& operator=(PrewarmScope&&) = delete; PrewarmScope(const PrewarmScope&) = delete; PrewarmScope& operator=(const PrewarmScope&) = delete; private: FontCacheManager* manager_; bool active_ = true; }; PrewarmScope createPrewarmScope(); private: const std::map& fontMap_; FontDecompressor* fontDecompressor_ = nullptr; enum class ScanMode : uint8_t { None, Scanning }; ScanMode scanMode_ = ScanMode::None; std::string scanText_; uint32_t scanStyleCounts_[4] = {}; int scanFontId_ = -1; };