Add SdCardFontFamilyInfo::pickClosestSize(targetPtSize) and have the
manager and SdCardFontSystem drive size selection from a target point
size derived from the user's font-size enum (SMALL=12, MEDIUM=14,
LARGE=16, EXTRA_LARGE=18) rather than indexing the family's sorted size
list by enum ordinal.
The ordinal-slot approach mis-selects whenever a family doesn't ship the
canonical {12,14,16,18} set: a family with only [10,14,18] would map
SMALL/MEDIUM/LARGE/EXTRA_LARGE to 10/14/18/18 — fine for SMALL but
arbitrary for the rest. Closest-pt always picks the on-disk file nearest
to the user-intended point size, with a deterministic smaller-pt
tie-break.
No change for canonical-sized families.
## Summary
* **What is the goal of this PR?** (e.g., Implements the new feature for
file uploading.)
* **What changes are included?**
## Additional Context
* Add any other information that might be helpful for the reviewer
(e.g., performance implications, potential risks,
specific areas to focus on).
---
### AI Usage
While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.
Did you use AI tools to help write this code? _**< YES | PARTIALLY | NO
>**_
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class GfxRenderer;
|
|
class SdCardFont;
|
|
struct SdCardFontFamilyInfo;
|
|
|
|
class SdCardFontManager {
|
|
public:
|
|
SdCardFontManager() = default;
|
|
~SdCardFontManager();
|
|
SdCardFontManager(const SdCardFontManager&) = delete;
|
|
SdCardFontManager& operator=(const SdCardFontManager&) = delete;
|
|
|
|
// Load the single size whose pointSize is closest to targetPtSize. Only one
|
|
// .cpfont file is loaded; other sizes remain on disk. This keeps resident
|
|
// interval + kern/ligature tables to one size's worth of memory.
|
|
//
|
|
// Closest-pt selection is robust against families that don't ship the
|
|
// canonical {12,14,16,18}: a family with only [10,14,18] still resolves
|
|
// any reasonable target, where ordinal slot-mapping by SMALL..EXTRA_LARGE
|
|
// would mis-select.
|
|
// Returns true on success.
|
|
bool loadFamily(const SdCardFontFamilyInfo& family, GfxRenderer& renderer, uint8_t targetPtSize);
|
|
|
|
// Unload everything, unregister from renderer.
|
|
void unloadAll(GfxRenderer& renderer);
|
|
|
|
// Look up the font ID for the loaded family. Returns 0 if nothing loaded
|
|
// or familyName doesn't match.
|
|
int getFontId(const std::string& familyName) const;
|
|
|
|
// Get name of currently loaded family (empty if none).
|
|
const std::string& currentFamilyName() const { return loadedFamilyName_; };
|
|
|
|
// Point size that was actually loaded (closest match to targetPtSize).
|
|
// 0 if nothing loaded.
|
|
uint8_t currentPointSize() const { return loadedPointSize_; };
|
|
|
|
private:
|
|
struct LoadedFont {
|
|
SdCardFont* font; // heap-allocated, owned
|
|
int fontId;
|
|
uint8_t size;
|
|
};
|
|
static int computeFontId(uint32_t contentHash, const char* familyName, uint8_t pointSize);
|
|
|
|
std::string loadedFamilyName_;
|
|
uint8_t loadedPointSize_ = 0;
|
|
std::vector<LoadedFont> loaded_;
|
|
};
|