fix fallback font broken when using MSDF

This commit is contained in:
fibref
2026-04-18 22:37:19 +08:00
committed by Wojtek Figat
parent 248d883a8b
commit 28ea7f134d
3 changed files with 27 additions and 0 deletions
+4
View File
@@ -52,6 +52,10 @@ void Font::GetCharacter(Char c, FontCharacterEntry& result, bool enableFallback)
for (int32 fallbackIndex = 0; fallbackIndex < FallbackFonts.Count(); fallbackIndex++)
{
FontAsset* fallbackFont = FallbackFonts.Get()[fallbackIndex].Get();
if (fallbackFont && _asset->GetOptions().RasterMode == FontRasterMode::MSDF)
{
fallbackFont = fallbackFont->GetMSDF();
}
if (fallbackFont && fallbackFont->ContainsChar(c))
{
fallbackFont->CreateFont(GetSize())->GetCharacter(c, result, enableFallback);
+16
View File
@@ -155,6 +155,22 @@ FontAsset* FontAsset::GetItalic()
return _virtualItalic;
}
FontAsset* FontAsset::GetMSDF()
{
ScopeLock lock(Locker);
if (_options.RasterMode == FontRasterMode::MSDF)
return this;
if (!_virtualMSDF)
{
_virtualMSDF = Content::CreateVirtualAsset<FontAsset>();
_virtualMSDF->Init(_fontFile);
auto options = _options;
options.RasterMode = FontRasterMode::MSDF;
_virtualMSDF->SetOptions(options);
}
return _virtualMSDF;
}
bool FontAsset::Init(const BytesContainer& fontFile)
{
ScopeLock lock(Locker);
+7
View File
@@ -122,6 +122,7 @@ private:
Array<Font*, InlinedAllocation<32>> _fonts;
AssetReference<FontAsset> _virtualBold;
AssetReference<FontAsset> _virtualItalic;
AssetReference<FontAsset> _virtualMSDF;
public:
/// <summary>
@@ -180,6 +181,12 @@ public:
/// <returns>The virtual font or this.</returns>
API_FUNCTION() FontAsset* GetItalic();
/// <summary>
/// Gets the MSDF version of the font. Returns itself or creates a new virtual font asset using this font but rasterized with MSDF.
/// </summary>
/// <returns>The virtual font or this.</returns>
API_FUNCTION() FontAsset* GetMSDF();
/// <summary>
/// Initializes the font with a custom font file data.
/// </summary>