Fix #10660: Sprite Font scale affected by viewport zoom level limits. (#10668)

This commit is contained in:
PeterN
2023-04-16 23:14:03 +01:00
committed by GitHub
parent e20a6f8ebb
commit db573c8742
6 changed files with 50 additions and 18 deletions

View File

@@ -21,6 +21,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_LVL_BASE (traditional "normal" interface size).
* @return Pixel amount at _font_zoom (current interface size).
*/
static int ScaleFontTrad(int value)
{
return UnScaleByZoom(value * ZOOM_LVL_BASE, _font_zoom);
}
/**
* Create a new sprite font cache.
* @param fs The font size to create the cache for.
@@ -29,7 +39,7 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid
{
this->InitializeUnicodeGlyphMap();
this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
this->ascender = (this->height - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
this->ascender = (this->height - ScaleFontTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
}
/**
@@ -106,7 +116,7 @@ void SpriteFontCache::ClearFontCache()
{
Layouter::ResetFontCache(this->fs);
this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
this->ascender = (this->height - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
this->ascender = (this->height - ScaleFontTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
}
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
@@ -120,7 +130,7 @@ uint SpriteFontCache::GetGlyphWidth(GlyphID key)
{
SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleSpriteTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
}
bool SpriteFontCache::GetDrawGlyphShadow()