public void ArrangeLines(bool textWrap, SizeF proposedSize) { if (!textWrap || (double)proposedSize.Width <= 0.0 && (double)proposedSize.Height <= 0.0) { return; } for (int index1 = 0; index1 < this.lines.Count; ++index1) { while ((double)FormattedTextBlock.GetTextLineSize(this.lines[index1]).Width > (double)proposedSize.Width && this.lines[index1].List.Count > 1) { int index2 = this.lines[index1].List.Count - 1; FormattedText formattedText = this.lines[index1].List[index2]; this.lines[index1].List.RemoveAt(index2); if (index1 == this.lines.Count - 1) { this.lines.Add(new TextLine()); } TextLine line = this.lines[index1 + 1]; if (line.List.Count > 0 && !line.List[0].StartNewLine) { line.List.Insert(0, formattedText); } else { this.lines.Insert(index1 + 1, new TextLine() { List = { formattedText } }); } } } }
public SizeF GetTextSize( SizeF proposedSize, bool useCompatibleTextRendering, StringFormat sf, TextFormatFlags textFormatFlags, bool textWrap) { if (textWrap) { this.RecalculateBlockLines(textWrap); this.ArrangeLines(textWrap, proposedSize); } SizeF empty1 = (SizeF)Size.Empty; SizeF empty2 = (SizeF)Size.Empty; foreach (TextLine line in this.lines) { SizeF textLineSize = FormattedTextBlock.GetTextLineSize(line); float height = (double)textLineSize.Height <= 2.0 ? 0.0f : textLineSize.Height; line.LineSize = new SizeF(textLineSize.Width, height); empty1.Height += height; empty1.Width = Math.Max(textLineSize.Width, empty1.Width); } return(empty1); }