diff --git a/Source/Engine/Render2D/FontAsset.cpp b/Source/Engine/Render2D/FontAsset.cpp
index 4cced556f..44723f47a 100644
--- a/Source/Engine/Render2D/FontAsset.cpp
+++ b/Source/Engine/Render2D/FontAsset.cpp
@@ -67,6 +67,8 @@ void FontAsset::unload(bool isReloading)
// Cleanup data
_fontFile.Release();
+ _virtualBold = nullptr;
+ _virtualItalic = nullptr;
}
AssetChunksFlag FontAsset::getChunksToPreload() const
diff --git a/Source/Engine/Render2D/FontReference.cs b/Source/Engine/Render2D/FontReference.cs
index 5ad67f486..d11f0a36d 100644
--- a/Source/Engine/Render2D/FontReference.cs
+++ b/Source/Engine/Render2D/FontReference.cs
@@ -40,6 +40,17 @@ namespace FlaxEngine
_cachedFont = null;
}
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The other font reference.
+ public FontReference(FontReference other)
+ {
+ _font = other._font;
+ _size = other._size;
+ _cachedFont = other._cachedFont;
+ }
+
///
/// Initializes a new instance of the struct.
///
diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs
index 113e4a943..7f7291956 100644
--- a/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs
+++ b/Source/Engine/UI/GUI/Common/RichTextBox.Parsing.cs
@@ -72,6 +72,7 @@ namespace FlaxEngine.GUI
{ "color", ProcessColor },
{ "alpha", ProcessAlpha },
{ "style", ProcessStyle },
+ { "font", ProcessFont },
{ "b", ProcessBold },
{ "i", ProcessItalic },
};
diff --git a/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs b/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs
index ead87ddc6..71f519e7b 100644
--- a/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs
+++ b/Source/Engine/UI/GUI/Common/RichTextBox.Tags.cs
@@ -81,6 +81,35 @@ namespace FlaxEngine.GUI
}
}
+ private static void ProcessFont(ref ParsingContext context, ref HtmlTag tag)
+ {
+ if (tag.IsSlash)
+ {
+ context.StyleStack.Pop();
+ }
+ else
+ {
+ var style = context.StyleStack.Peek();
+ style.Font = new FontReference(style.Font);
+ if (tag.Attributes.TryGetValue(string.Empty, out var fontName))
+ {
+ var ids = Content.GetAllAssetsByType(typeof(FontAsset));
+ foreach (var id in ids)
+ {
+ if (Content.GetAssetInfo(id, out var info) && string.Equals(fontName, System.IO.Path.GetFileNameWithoutExtension(info.Path), System.StringComparison.OrdinalIgnoreCase))
+ {
+ var font = Content.LoadAsync(id);
+ if (font != null)
+ style.Font.Font = font;
+ }
+ }
+ }
+ if (tag.Attributes.TryGetValue("size", out var sizeText) && int.TryParse(sizeText, out var size))
+ style.Font.Size = size;
+ context.StyleStack.Push(style);
+ }
+ }
+
private static void ProcessBold(ref ParsingContext context, ref HtmlTag tag)
{
if (tag.IsSlash)