Add font tag

This commit is contained in:
Wojciech Figat
2022-08-03 14:39:00 +02:00
parent 8f895e54cd
commit 6f18a8a3ff
4 changed files with 43 additions and 0 deletions

View File

@@ -72,6 +72,7 @@ namespace FlaxEngine.GUI
{ "color", ProcessColor },
{ "alpha", ProcessAlpha },
{ "style", ProcessStyle },
{ "font", ProcessFont },
{ "b", ProcessBold },
{ "i", ProcessItalic },
};

View File

@@ -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<FontAsset>(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)