From 404e95c8f2f714efbe25d8cae735ea36d6c836db Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 24 Aug 2019 00:08:36 +0200 Subject: [PATCH] also apply the newline fix to bitmap fonts --- .../Extensions/BitmapFontExtensions.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/MLEM.Extended/Extensions/BitmapFontExtensions.cs b/MLEM.Extended/Extensions/BitmapFontExtensions.cs index 9bd9cbb..58ccdd1 100644 --- a/MLEM.Extended/Extensions/BitmapFontExtensions.cs +++ b/MLEM.Extended/Extensions/BitmapFontExtensions.cs @@ -8,15 +8,18 @@ namespace MLEM.Extended.Extensions { public static IEnumerable SplitString(this BitmapFont font, string text, float width, float scale) { var builder = new StringBuilder(); - foreach (var word in text.Split(' ')) { - builder.Append(word).Append(' '); - if (font.MeasureString(builder).Width * scale >= width) { - var len = builder.Length - word.Length - 1; - yield return builder.ToString(0, len - 1); - builder.Remove(0, len); + foreach (var line in text.Split('\n')) { + foreach (var word in line.Split(' ')) { + builder.Append(word).Append(' '); + if (font.MeasureString(builder).Width * scale >= width) { + var len = builder.Length - word.Length - 1; + yield return builder.ToString(0, len - 1); + builder.Remove(0, len); + } } + yield return builder.ToString(0, builder.Length - 1); + builder.Clear(); } - yield return builder.ToString(0, builder.Length - 1); } }