diff --git a/MLEM/Extensions/SpriteFontExtensions.cs b/MLEM/Extensions/SpriteFontExtensions.cs index 0231f63..b7f9f5d 100644 --- a/MLEM/Extensions/SpriteFontExtensions.cs +++ b/MLEM/Extensions/SpriteFontExtensions.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework.Graphics; +using MLEM.Font; namespace MLEM.Extensions { public static class SpriteFontExtensions { @@ -64,5 +65,12 @@ namespace MLEM.Extensions { return total.ToString(0, total.Length - 2); } + public static string GetWidthString(IGenericFont font, float width, char content = ' ') { + var strg = content.ToString(); + while (font.MeasureString(strg).X < width) + strg += content; + return strg; + } + } } \ No newline at end of file diff --git a/MLEM/Formatting/FormattingCode.cs b/MLEM/Formatting/FormattingCode.cs index 46a4d05..1485d86 100644 --- a/MLEM/Formatting/FormattingCode.cs +++ b/MLEM/Formatting/FormattingCode.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using MLEM.Animations; +using MLEM.Extensions; using MLEM.Font; using MLEM.Textures; @@ -37,7 +38,7 @@ namespace MLEM.Formatting { } public virtual string GetReplacementString(IGenericFont font) { - return this.CodeType == Type.Icon ? TextFormatting.GetOneEmString(font) : string.Empty; + return this.CodeType == Type.Icon ? SpriteFontExtensions.GetWidthString(font, font.LineHeight) : string.Empty; } public enum Type { diff --git a/MLEM/Formatting/TextFormatting.cs b/MLEM/Formatting/TextFormatting.cs index 6947741..a9455fe 100644 --- a/MLEM/Formatting/TextFormatting.cs +++ b/MLEM/Formatting/TextFormatting.cs @@ -12,7 +12,6 @@ namespace MLEM.Formatting { public static class TextFormatting { public static readonly Dictionary FormattingCodes = new Dictionary(); - private static readonly Dictionary OneEmStrings = new Dictionary(); private static Regex formatRegex; static TextFormatting() { @@ -45,16 +44,6 @@ namespace MLEM.Formatting { formatRegex = new Regex($"{op}[^{op}{cl}]*{cl}"); } - public static string GetOneEmString(IGenericFont font) { - if (!OneEmStrings.TryGetValue(font, out var strg)) { - strg = " "; - while (font.MeasureString(strg + ' ').X < font.LineHeight) - strg += ' '; - OneEmStrings[font] = strg; - } - return strg; - } - public static string RemoveFormatting(this string s, IGenericFont font) { return formatRegex.Replace(s, match => { var code = FromMatch(match);