private void AppendTextSegmentCharWrap([NotNull] InlineSegment sourceSeg) { _curSeg = InlineSegment.CreateWithBuilder(AvailableWidth); for (int i = 0; i < sourceSeg.Text.Length; i++) { CharInfo c = CharInfo.From(sourceSeg.Text[i]); Debug.Assert(_curLineLength == GetLineLength(_curLine) + _curSeg.TextLength); if (!c.IsZeroWidth && _curLineLength >= AvailableWidth) { // Proceed as if the current char is '\n', repeat with current char on the next iteration // (unless current char is actually '\n', then it is consumed on wrap). if (!c.IsNewLine) { i--; _curLineLength--; } c = CharInfo.From('\n'); } if (c.IsNewLine) { StartNewLine(); } else if (!c.IsZeroWidth) { _curSeg.TextBuilder.Append(c); _curLineLength++; } } AppendCurrentSegment(); }
private void AppendTextSegmentWordWrap([NotNull] InlineSegment sourceSeg, bool isSpaceOnly) { _curSeg = InlineSegment.CreateWithBuilder(AvailableWidth); _segPos = 0; for (int i = 0; i < sourceSeg.Text.Length; i++) { CharInfo c = CharInfo.From(sourceSeg.Text[i]); Debug.Assert(_curLineLength == GetLineLength(_curLine) + _curSeg.TextLength); bool canAddChar = _curLineLength < AvailableWidth; if (!canAddChar && !c.IsZeroWidth) { if (c.IsConsumedOnWrap) { c = CharInfo.From('\n'); } else if (_wrapPos == -1) { c = CharInfo.From('\n'); // Repeat with current char on the next iteration i--; _curLineLength--; _segPos--; } else if (!c.IsNewLine) { _curLine.Add(_curSeg); WrapLine(); } } bool canWrap = isSpaceOnly ? c.IsWrappableSpace && (canAddChar || c.IsZeroWidth) : c.IsWrappable && (canAddChar || c.IsZeroWidth && !c.IsSoftHyphen); if (canWrap) { _wrapPos = _segPos; _wrapChar = c; _wrapSegmentIndex = _curLine.Count; } if (c.IsNewLine) { StartNewLine(); } else if (!c.IsZeroWidth) { _curSeg.TextBuilder.Append(c); _curLineLength++; _segPos++; } } AppendCurrentSegment(); }
private void AppendTextSegmentNoWrap([NotNull] InlineSegment sourceSeg) { _curSeg = InlineSegment.CreateWithBuilder(AvailableWidth); for (int i = 0; i < sourceSeg.Text.Length; i++) { CharInfo c = CharInfo.From(sourceSeg.Text[i]); if (c.IsNewLine) { StartNewLine(); } else if (!c.IsZeroWidth && _curLineLength < AvailableWidth) { _curSeg.TextBuilder.Append(c); _curLineLength++; } } AppendCurrentSegment(); }