-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathSdCardFontSystem.h
More file actions
62 lines (49 loc) · 2.43 KB
/
Copy pathSdCardFontSystem.h
File metadata and controls
62 lines (49 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include <SdCardFontManager.h>
#include <SdCardFontRegistry.h>
#include <atomic>
class GfxRenderer;
/// Facade that owns the SD card font registry, manager, and resolver logic.
/// Hides implementation details behind a single begin() + ensureLoaded() API.
class SdCardFontSystem {
public:
SdCardFontSystem() = default;
SdCardFontSystem(const SdCardFontSystem&) = delete;
SdCardFontSystem& operator=(const SdCardFontSystem&) = delete;
/// Discover SD card fonts and load user's saved selection. Call once during setup.
void begin(GfxRenderer& renderer);
/// Ensure the correct SD font family is loaded for the current settings.
/// Call before entering the reader or after settings change.
/// Also re-discovers if the registry has been marked dirty (e.g. by web upload).
void ensureLoaded(GfxRenderer& renderer);
/// Resolve an SD card font ID from family name + reader point size.
/// Returns 0 if not found. Used by CrossPointSettings::getReaderFontId().
int resolveFontId(const char* familyName, uint8_t pointSize) const;
/// Access the registry (e.g. for settings UI to enumerate available fonts).
const SdCardFontRegistry& registry() const { return registry_; }
/// Non-const access to the registry (for FontInstaller).
SdCardFontRegistry& registry() { return registry_; }
/// Mark the registry as needing re-discovery.
/// Thread-safe: can be called from the web server task.
void markRegistryDirty() { registryDirty_.store(true, std::memory_order_release); }
/// If the registry is dirty, re-scan the SD card now and clear the flag.
/// Used by the web UI so uploaded/deleted fonts appear in the list
/// without waiting for the reader activity to run ensureLoaded().
void refreshIfDirty() {
if (registryDirty_.exchange(false, std::memory_order_acquire)) {
registry_.discover();
}
}
private:
// Load the active SD family at the built-in UI point sizes and register each
// as a size-matched CJK fallback for the corresponding UI font, so CJK book
// titles/list rows render at the same size as the surrounding Latin UI text.
// No-op when no SD family is loaded. Safe to call repeatedly (sizes already
// loaded are reused).
void setupUiFallbacks(GfxRenderer& renderer);
SdCardFontRegistry registry_;
SdCardFontManager manager_;
std::atomic<bool> registryDirty_{false};
};
// Global SD card font system instance (defined in main.cpp).
extern SdCardFontSystem sdFontSystem;