/// <summary> /// Appends any text after the first line to the first line and removes any line breaks. /// </summary> private void FlattenText() { int charCount = 0; for (int n = 0; n < Count; n++) { charCount += lines[n].Count; } Line chars = lines.GetNewLine(charCount); for (int line = 0; line < Count; line++) { for (int ch = 0; ch < lines[line].Count; ch++) { if (lines[line][ch].Ch >= ' ') { chars.AddCharFromLine(ch, lines[line]); } } } chars.UpdateSize(); lines.Clear(); lines.Add(chars); }
/// <summary> /// Generates a new list of wrapped <see cref="Line"/>s from the contents of the character buffer. Uses precalculated list /// width to estimate the size of the collection. /// </summary> private List <Line> GetLines(float listWidth) { Line currentLine = null; List <Line> newLines = new List <Line>(Math.Max(3, (int)(1.1f * (listWidth / MaxLineWidth)))); int estLineLength = Math.Max(3, (int)(charBuffer.Count / (listWidth / MaxLineWidth)) / 2), end; float wordWidth, spaceRemaining = -1f; for (int start = 0; TryGetWordEnd(start, out end, out wordWidth); start = end + 1) { bool wrapWord = (spaceRemaining < wordWidth && wordWidth <= MaxLineWidth) || charBuffer.Chars[start] == '\n'; for (int n = start; n <= end; n++) { if (spaceRemaining < charBuffer.LocData[n].chSize.X || wrapWord) { spaceRemaining = MaxLineWidth; currentLine = lines.GetNewLine(estLineLength); newLines.Add(currentLine); wrapWord = false; } currentLine.AddCharFromLine(n, charBuffer); spaceRemaining -= charBuffer.LocData[n].chSize.X; } } return(newLines); }
/// <summary> /// Generates a list of lines from the contents of the character buffer. /// </summary> private List <Line> GetLines() { Line currentLine = null; List <Line> newLines = new List <Line>(); for (int n = 0; n < charBuffer.Count; n++) { if (currentLine == null || (charBuffer.Chars[n] == '\n' && currentLine.Count > 0)) { currentLine = lines.GetNewLine(); newLines.Add(currentLine); } currentLine.AddCharFromLine(n, charBuffer); } return(newLines); }