diff --git a/Barotrauma/BarotraumaClient/Source/Utils/ToolBox.cs b/Barotrauma/BarotraumaClient/Source/Utils/ToolBox.cs index a171131c1..9f7df48dc 100644 --- a/Barotrauma/BarotraumaClient/Source/Utils/ToolBox.cs +++ b/Barotrauma/BarotraumaClient/Source/Utils/ToolBox.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; namespace Barotrauma { @@ -101,28 +102,47 @@ namespace Barotrauma public static string WrapText(string text, float lineLength, ScalableFont font, float textScale = 1.0f) //TODO: could integrate this into the ScalableFont class directly { - if (font.MeasureString(text).X < lineLength) return text; + Vector2 textSize = font.MeasureString(text); + if (textSize.X < lineLength) { return text; } text = text.Replace("\n", " \n "); - string[] words; - if (TextManager.NoWhiteSpace) + List words = new List(); + string currWord = ""; + for (int i = 0; i 0) + { + words.Add(currWord); + currWord = ""; + } + words.Add(text[i].ToString()); + } + else if (text[i] == ' ') + { + if (currWord.Length > 0) + { + words.Add(currWord); + currWord = ""; + } + } + else + { + currWord += text[i]; } } - else + if (currWord.Length > 0) { - words = text.Split(' '); + words.Add(currWord); + currWord = ""; } StringBuilder wrappedText = new StringBuilder(); float linePos = 0f; Vector2 spaceSize = font.MeasureString(" ") * textScale; - for (int i = 0; i < words.Length; ++i) + for (int i = 0; i < words.Count; ++i) { if (words[i].Length == 0) { @@ -180,10 +200,24 @@ namespace Barotrauma linePos = size.X + spaceSize.X; } - if (i < words.Length - 1) wrappedText.Append(" "); + if (i < words.Count - 1 && !isCJK.IsMatch(words[i]) && !isCJK.IsMatch(words[i + 1])) + { + wrappedText.Append(" "); + } } return wrappedText.ToString().Replace(" \n ", "\n"); } + + static Regex isCJK = new Regex( + @"\p{IsHangulJamo}|" + + @"\p{IsCJKRadicalsSupplement}|" + + @"\p{IsCJKSymbolsandPunctuation}|" + + @"\p{IsEnclosedCJKLettersandMonths}|" + + @"\p{IsCJKCompatibility}|" + + @"\p{IsCJKUnifiedIdeographsExtensionA}|" + + @"\p{IsCJKUnifiedIdeographs}|" + + @"\p{IsHangulSyllables}|" + + @"\p{IsCJKCompatibilityForms}"); } } diff --git a/Barotrauma/BarotraumaShared/Source/TextManager.cs b/Barotrauma/BarotraumaShared/Source/TextManager.cs index 466c12c65..69f8a6d1d 100644 --- a/Barotrauma/BarotraumaShared/Source/TextManager.cs +++ b/Barotrauma/BarotraumaShared/Source/TextManager.cs @@ -16,14 +16,6 @@ namespace Barotrauma private static string[] serverMessageCharacters = new string[] { "~", "[", "]", "=" }; public static string Language; - public static bool NoWhiteSpace - { - get - { - if (!textPacks.ContainsKey(Language)) { return false; } - return textPacks[Language].Any(t => t.NoWhiteSpace); - } - } private static HashSet availableLanguages = new HashSet(); public static IEnumerable AvailableLanguages diff --git a/Barotrauma/BarotraumaShared/Source/TextPack.cs b/Barotrauma/BarotraumaShared/Source/TextPack.cs index a4105c57b..18b0170d8 100644 --- a/Barotrauma/BarotraumaShared/Source/TextPack.cs +++ b/Barotrauma/BarotraumaShared/Source/TextPack.cs @@ -11,9 +11,7 @@ namespace Barotrauma public readonly string Language; private Dictionary> texts; - - public readonly bool NoWhiteSpace; - + private readonly string filePath; public TextPack(string filePath) @@ -25,7 +23,6 @@ namespace Barotrauma if (doc == null || doc.Root == null) return; Language = doc.Root.GetAttributeString("language", "Unknown"); - NoWhiteSpace = doc.Root.GetAttributeBool("nowhitespace", false); foreach (XElement subElement in doc.Root.Elements()) {