Skip to content

Commit

Permalink
Split words on more characters in text flow container
Browse files Browse the repository at this point in the history
- Closes ppy/osu#10085
- Closes ppy/osu#14837

I'm not really considering the performance implications of this, just
looking to get a baseline more-correct behaviour in place.

The change is basically a best-effort heuristic, although I did use a
slightly smarter split method for CJK to attempt to ensure no hanging
punctuation.
  • Loading branch information
bdach committed Mar 29, 2024
1 parent 2f71fb1 commit af715d0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion osu.Framework/Graphics/Containers/TextChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using osu.Framework.Graphics.Sprites;
Expand Down Expand Up @@ -88,7 +89,13 @@ protected string[] SplitWords(string text)

for (int i = 0; i < text.Length; i++)
{
if (i == 0 || char.IsSeparator(text[i - 1]) || char.IsControl(text[i - 1]))
if (i == 0
|| char.IsSeparator(text[i - 1])
|| char.IsControl(text[i - 1])
|| char.GetUnicodeCategory(text[i - 1]) == UnicodeCategory.DashPunctuation
|| text[i - 1] == '/'
|| text[i - 1] == '\\'
|| (isCjkCharacter(text[i - 1]) && !char.IsPunctuation(text[i])))
{
words.Add(builder.ToString());
builder.Clear();
Expand All @@ -101,6 +108,8 @@ protected string[] SplitWords(string text)
words.Add(builder.ToString());

return words.ToArray();

bool isCjkCharacter(char c) => c >= '\x3000' && c <= '\x9FFF';
}

protected virtual TSpriteText CreateSpriteText(TextFlowContainer textFlowContainer)
Expand Down

0 comments on commit af715d0

Please sign in to comment.