csharp4405de34 | 1 | #nullable enable |
| 2 | |
| 3 | namespace CascadeIDE.Views.SkiaKit; |
| 4 | |
| 5 | /// <summary>Перенос текста для Skia-примитивов (без Avalonia TextLayout).</summary> |
| 6 | internal static class SkiaTextLayout |
| 7 | { |
| 8 | public static List<string> Wrap(string text, int maxChars) |
| 9 | { |
| 10 | if (string.IsNullOrWhiteSpace(text)) |
| 11 | return [""]; |
| 12 | |
| 13 | var words = text.Replace("\r", "").Replace("\n", " ").Split(' ', StringSplitOptions.RemoveEmptyEntries); |
| 14 | var lines = new List<string>(); |
| 15 | var current = ""; |
| 16 | foreach (var word in words) |
| 17 | { |
| 18 | if (current.Length == 0) |
| 19 | { |
| 20 | current = word; |
| 21 | continue; |
| 22 | } |
| 23 | |
| 24 | if (current.Length + 1 + word.Length <= maxChars) |
| 25 | { |
| 26 | current += " " + word; |
| 27 | continue; |
| 28 | } |
| 29 | |
| 30 | lines.Add(current); |
| 31 | current = word; |
| 32 | } |
| 33 | |
| 34 | if (current.Length > 0) |
| 35 | lines.Add(current); |
| 36 | return lines; |
| 37 | } |
| 38 | } |
| 39 | |
View only · write via MCP/CIDE