Revert: "Change: Support side-by-side fallback FontCaches instead of hierarchical. (#13303)"

This reverts commit 1829f7926d.
This commit is contained in:
Peter Nelson
2025-12-13 00:29:06 +00:00
committed by Peter Nelson
parent 973514adc3
commit b03347f00c
32 changed files with 480 additions and 783 deletions
+20 -21
View File
@@ -23,6 +23,16 @@
static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
/**
* Scale traditional pixel dimensions to font zoom level, for drawing sprite fonts.
* @param value Pixel amount at #ZOOM_BASE (traditional "normal" interface size).
* @return Pixel amount at _font_zoom (current interface size).
*/
static int ScaleFontTrad(int value)
{
return UnScaleByZoom(value * ZOOM_BASE, _font_zoom);
}
static std::array<std::unordered_map<char32_t, SpriteID>, FS_END> _char_maps{}; ///< Glyph map for each font size.
/**
@@ -106,48 +116,37 @@ void InitializeUnicodeGlyphMap()
*/
SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
{
this->UpdateMetrics();
this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
this->ascender = (this->height - ScaleFontTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
}
void SpriteFontCache::ClearFontCache()
{
Layouter::ResetFontCache(this->fs);
this->UpdateMetrics();
}
void SpriteFontCache::UpdateMetrics()
{
this->height = ScaleFontTrad(DEFAULT_FONT_HEIGHT[this->fs]);
this->ascender = ScaleGUITrad(DEFAULT_FONT_ASCENDER[this->fs]);
this->descender = ScaleGUITrad(DEFAULT_FONT_ASCENDER[this->fs] - DEFAULT_FONT_HEIGHT[this->fs]);
this->scaled_ascender = ScaleFontTrad(DEFAULT_FONT_ASCENDER[this->fs]);
}
int SpriteFontCache::GetGlyphYOffset()
{
return FontCache::GetFontBaseline(this->fs) - this->scaled_ascender;
this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
this->ascender = (this->height - ScaleFontTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
}
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
{
SpriteID sprite = static_cast<SpriteID>(key);
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
if (sprite == 0) sprite = GetUnicodeGlyph(this->fs, '?');
return GetSprite(sprite, SpriteType::Font);
}
uint SpriteFontCache::GetGlyphWidth(GlyphID key)
{
SpriteID sprite = static_cast<SpriteID>(key);
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
if (sprite == 0) sprite = GetUnicodeGlyph(this->fs, '?');
return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
}
GlyphID SpriteFontCache::MapCharToGlyph(char32_t key)
GlyphID SpriteFontCache::MapCharToGlyph(char32_t key, [[maybe_unused]] bool allow_fallback)
{
assert(IsPrintable(key));
SpriteID sprite = GetUnicodeGlyph(this->fs, key);
if (sprite == 0) return 0;
return static_cast<GlyphID>(sprite);
return SPRITE_GLYPH | sprite;
}
bool SpriteFontCache::GetDrawGlyphShadow()
@@ -159,14 +158,14 @@ class SpriteFontCacheFactory : public FontCacheFactory {
public:
SpriteFontCacheFactory() : FontCacheFactory("sprite", "Sprite font provider") {}
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype, bool, const std::string &, std::span<const std::byte>) const override
std::unique_ptr<FontCache> LoadFont(FontSize fs, FontType fonttype) const override
{
if (fonttype != FontType::Sprite) return nullptr;
return std::make_unique<SpriteFontCache>(fs);
}
bool FindFallbackFont(const std::string &, FontSizes, class MissingGlyphSearcher *) const override
bool FindFallbackFont(struct FontCacheSettings *, const std::string &, class MissingGlyphSearcher *) const override
{
return false;
}