diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index 63c59ff70..b2e6e8b75 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -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); diff --git a/Source/Engine/Render2D/FontAsset.cpp b/Source/Engine/Render2D/FontAsset.cpp index 813eb0c66..b8edf0448 100644 --- a/Source/Engine/Render2D/FontAsset.cpp +++ b/Source/Engine/Render2D/FontAsset.cpp @@ -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(); + _virtualMSDF->Init(_fontFile); + auto options = _options; + options.RasterMode = FontRasterMode::MSDF; + _virtualMSDF->SetOptions(options); + } + return _virtualMSDF; +} + bool FontAsset::Init(const BytesContainer& fontFile) { ScopeLock lock(Locker); diff --git a/Source/Engine/Render2D/FontAsset.h b/Source/Engine/Render2D/FontAsset.h index 56cc3d655..44ffbbdd1 100644 --- a/Source/Engine/Render2D/FontAsset.h +++ b/Source/Engine/Render2D/FontAsset.h @@ -122,6 +122,7 @@ private: Array> _fonts; AssetReference _virtualBold; AssetReference _virtualItalic; + AssetReference _virtualMSDF; public: /// @@ -180,6 +181,12 @@ public: /// The virtual font or this. API_FUNCTION() FontAsset* GetItalic(); + /// + /// Gets the MSDF version of the font. Returns itself or creates a new virtual font asset using this font but rasterized with MSDF. + /// + /// The virtual font or this. + API_FUNCTION() FontAsset* GetMSDF(); + /// /// Initializes the font with a custom font file data. ///