private IEnumerable <WordAndFontLine> ContentNodeToLines(ContentNode node, float widthToFill, Func <float, float> calculateIndent) { List <WordAndFont> buffer = new List <WordAndFont>(); float currentLength = 0; var liner = node.Linearize().GetEnumerator(); do { bool hasMore = liner.MoveNext(); float toAdd = hasMore ? liner.Current.Word.Length * _settings.EffectiveCharWidth : 0; bool isTooLong = hasMore && (currentLength + toAdd > widthToFill); if (!hasMore || isTooLong) { // Dump the buffer. float indent = calculateIndent(currentLength); yield return(new WordAndFontLine(buffer.ToArray(), indent)); buffer.Clear(); currentLength = 0; } if (!hasMore) { break; } buffer.Add(liner.Current); currentLength += toAdd + _settings.EffectiveCharWidth; } while(true); }
private IEnumerable<WordAndFontLine> ContentNodeToLines(ContentNode node, float widthToFill, Func<float, float> calculateIndent) { List<WordAndFont> buffer = new List<WordAndFont>(); float currentLength = 0; var liner = node.Linearize().GetEnumerator(); do { bool hasMore = liner.MoveNext(); float toAdd = hasMore ? liner.Current.Word.Length * _settings.EffectiveCharWidth : 0; bool isTooLong = hasMore && (currentLength + toAdd > widthToFill); if (!hasMore || isTooLong) { // Dump the buffer. float indent = calculateIndent(currentLength); yield return new WordAndFontLine(buffer.ToArray(), indent); buffer.Clear(); currentLength = 0; } if (!hasMore) break; buffer.Add(liner.Current); currentLength += toAdd + _settings.EffectiveCharWidth; } while(true); }