internal static TextLineImpl Create(TextParagraphProperties paragraphProperties, int firstIndex, int paragraphLength, TextSource textSource) { var index = firstIndex; var visibleLength = 0; var widthLeft = paragraphProperties.TextWrapping == TextWrapping.Wrap && paragraphLength > 0 ? paragraphLength : double.MaxValue; TextLineRun prevRun = null; var run = TextLineRun.Create(textSource, index, firstIndex, widthLeft, paragraphProperties); if (!run.IsEnd && run.Width <= widthLeft) { index += run.Length; widthLeft -= run.Width; prevRun = run; run = TextLineRun.Create(textSource, index, firstIndex, widthLeft, paragraphProperties); } var trailing = new TrailingInfo(); var runs = new List <TextLineRun>(2); if (prevRun != null) { visibleLength += AddRunReturnVisibleLength(runs, prevRun); } while (true) { visibleLength += AddRunReturnVisibleLength(runs, run); index += run.Length; widthLeft -= run.Width; if (run.IsEnd || widthLeft <= 0) { trailing.SpaceWidth = 0; UpdateTrailingInfo(runs, trailing); return(new TextLineImpl(paragraphProperties, firstIndex, runs, trailing)); } run = TextLineRun.Create(textSource, index, firstIndex, widthLeft, paragraphProperties); if (run.Width > widthLeft) { return(new TextLineImpl(paragraphProperties, firstIndex, runs, trailing)); } } }