From 249fdd9226da5bbba63586c35812ec0e82bed13d Mon Sep 17 00:00:00 2001 From: Kirill Serogodsky Date: Sat, 11 Jan 2025 01:49:09 +0300 Subject: [PATCH 1/3] Fix incorrect calc space width in WrapTextSegment --- Blish HUD/_Utils/DrawUtil.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blish HUD/_Utils/DrawUtil.cs b/Blish HUD/_Utils/DrawUtil.cs index 1233b5823..fe5cf292f 100644 --- a/Blish HUD/_Utils/DrawUtil.cs +++ b/Blish HUD/_Utils/DrawUtil.cs @@ -47,7 +47,7 @@ private static string WrapTextSegment(BitmapFont spriteFont, string text, float string[] words = text.Split(' '); var sb = new StringBuilder(); float lineWidth = 0f; - float spaceWidth = spriteFont.MeasureString(" ").Width; + float spaceWidth = spriteFont.MeasureString("_").Width; foreach (string word in words) { Vector2 size = spriteFont.MeasureString(word); From c34b8234a78233dbb94dd1d8e242aab4abac1e51 Mon Sep 17 00:00:00 2001 From: Kirill Serogodsky Date: Sun, 12 Jan 2025 14:42:59 +0300 Subject: [PATCH 2/3] Fix space width and word calc --- Blish HUD/_Utils/DrawUtil.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Blish HUD/_Utils/DrawUtil.cs b/Blish HUD/_Utils/DrawUtil.cs index fe5cf292f..c603b27f8 100644 --- a/Blish HUD/_Utils/DrawUtil.cs +++ b/Blish HUD/_Utils/DrawUtil.cs @@ -1,7 +1,7 @@ -using Microsoft.Xna.Framework; +using System; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MonoGame.Extended.BitmapFonts; -using System; using System.Linq; using System.Text; using Blish_HUD.Controls; @@ -47,17 +47,19 @@ private static string WrapTextSegment(BitmapFont spriteFont, string text, float string[] words = text.Split(' '); var sb = new StringBuilder(); float lineWidth = 0f; - float spaceWidth = spriteFont.MeasureString("_").Width; + float spaceWidth = spriteFont.MeasureString(" ").Width - spriteFont.MeasureString(" ").Width; + float aWidth = spriteFont.MeasureString("a").Width; foreach (string word in words) { - Vector2 size = spriteFont.MeasureString(word); + float wordWidth = spriteFont.MeasureString("a" + word).Width - aWidth; + wordWidth = Math.Max(wordWidth, spriteFont.MeasureString(word + "a").Width - aWidth); - if (lineWidth + size.X < maxLineWidth) { + if (lineWidth + wordWidth < maxLineWidth) { sb.Append(word + " "); - lineWidth += size.X + spaceWidth; + lineWidth += wordWidth + spaceWidth; } else { sb.Append("\n" + word + " "); - lineWidth = size.X + spaceWidth; + lineWidth = wordWidth + spaceWidth; } } From f5210279c932254adbcfe1c05f23e844d20f93ad Mon Sep 17 00:00:00 2001 From: Kirill Serogodsky Date: Sun, 12 Jan 2025 15:07:04 +0300 Subject: [PATCH 3/3] fix usings --- Blish HUD/_Utils/DrawUtil.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Blish HUD/_Utils/DrawUtil.cs b/Blish HUD/_Utils/DrawUtil.cs index c603b27f8..91e0aff84 100644 --- a/Blish HUD/_Utils/DrawUtil.cs +++ b/Blish HUD/_Utils/DrawUtil.cs @@ -1,7 +1,7 @@ -using System; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MonoGame.Extended.BitmapFonts; +using System; using System.Linq; using System.Text; using Blish_HUD.Controls;