public void AddLineBreakAfter(Run afterTextRun) { if (afterTextRun == null) { this.EndWithLineBreak = true; TextLineBox newline = _textFlowLayer.InsertNewLine(_currentLineNumber + 1); // if (_textFlowLayer.LineCount - 1 != newline.LineNumber) { newline.EndWithLineBreak = true; } } else if (afterTextRun.NextRun == null) { this.EndWithLineBreak = true; TextLineBox newline = _textFlowLayer.InsertNewLine(_currentLineNumber + 1); // if (_textFlowLayer.LineCount - 1 != newline.LineNumber) { newline.EndWithLineBreak = true; } } else { using (RunListPool.Borrow(out List <Run> tempTextRuns)) { if (afterTextRun != null) { foreach (Run t in GetRunIterForward(afterTextRun.NextRun)) { tempTextRuns.Add(t); } } bool thisEndWithLineBreak = this.EndWithLineBreak; this.EndWithLineBreak = true; this.LocalSuspendLineReArrange(); TextLineBox newTextline = _textFlowLayer.InsertNewLine(_currentLineNumber + 1); newTextline.EndWithLineBreak = thisEndWithLineBreak; // int j = tempTextRuns.Count; newTextline.LocalSuspendLineReArrange(); int cx = 0; for (int i = 0; i < j; ++i) { Run t = tempTextRuns[i]; this.Remove(t); newTextline.AddLast(t); Run.DirectSetLocation(t, cx, 0); cx += t.Width; } newTextline.LocalResumeLineReArrange(); this.LocalResumeLineReArrange(); } } }
void AddLineBreakBefore(Run beforeTextRun) { if (beforeTextRun == null) { this.EndWithLineBreak = true; _textFlowLayer.InsertNewLine(_currentLineNumber + 1); } else { //TODO: use pool using (RunListPool.Borrow(out List <Run> tempTextRuns)) { if (beforeTextRun != null) { foreach (Run t in GetRunIterForward(beforeTextRun)) { tempTextRuns.Add(t); } } this.EndWithLineBreak = true; TextLineBox newTextline = _textFlowLayer.InsertNewLine(_currentLineNumber + 1); // this.LocalSuspendLineReArrange(); newTextline.LocalSuspendLineReArrange(); int j = tempTextRuns.Count; for (int i = 0; i < j; ++i) { Run t = tempTextRuns[i]; this.Remove(t); newTextline.AddLast(t); } this.LocalResumeLineReArrange(); newTextline.LocalResumeLineReArrange(); } } }
internal SelectionRangeInfo Split(VisualSelectionRange selectionRange) { selectionRange.SwapIfUnOrder(); EditableVisualPointInfo startPoint = selectionRange.StartPoint; EditableVisualPointInfo endPoint = selectionRange.EndPoint; if (startPoint.Run == endPoint.Run) { Run toBeCutTextRun = startPoint.Run; CopyRun leftPart = toBeCutTextRun.LeftCopy(startPoint.RunLocalSelectedIndex); CopyRun middlePart = toBeCutTextRun.Copy(startPoint.RunLocalSelectedIndex, endPoint.LineCharIndex - startPoint.LineCharIndex); CopyRun rightPart = toBeCutTextRun.Copy(endPoint.RunLocalSelectedIndex); EditableVisualPointInfo newStartRangePointInfo = null; EditableVisualPointInfo newEndRangePointInfo = null; TextLineBox line = this; if (startPoint.LineId != _currentLineNumber) { line = _textFlowLayer.GetTextLine(startPoint.LineId); } line.LocalSuspendLineReArrange(); if (leftPart != null) { Run leftRun = line.AddBefore(toBeCutTextRun, leftPart); newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, leftRun, startPoint.TextRunCharOffset, startPoint.TextRunPixelOffset); } else { //no left part, //so we connect to prev text run Run prevTxtRun = startPoint.Run.PrevRun; if (prevTxtRun != null) { newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, startPoint.X, prevTxtRun, startPoint.TextRunCharOffset - leftPart.CharacterCount, startPoint.TextRunPixelOffset - prevTxtRun.Width); } else { //no prev run, we are at the begining of the line newStartRangePointInfo = CreateTextPointInfo( startPoint.LineId, startPoint.LineCharIndex, 0, null, 0, 0); } } if (rightPart != null) { Run rightRun = line.AddAfter(toBeCutTextRun, rightPart); newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, null, ///?? startPoint.TextRunCharOffset + middlePart.CharacterCount, startPoint.TextRunPixelOffset + MeasureCopyRunLength(middlePart).Width); } else { Run nextTxtRun = endPoint.Run.NextRun; if (nextTxtRun != null) { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, null, ///?? endPoint.TextRunPixelOffset + endPoint.Run.CharacterCount, endPoint.TextRunPixelOffset + endPoint.Run.Width); } else { newEndRangePointInfo = CreateTextPointInfo( endPoint.LineId, endPoint.LineCharIndex, endPoint.X, null, endPoint.TextRunCharOffset, endPoint.TextRunPixelOffset); } } if (middlePart != null) { line.AddAfter(toBeCutTextRun, middlePart); } else { throw new NotSupportedException(); } line.Remove(toBeCutTextRun); line.LocalResumeLineReArrange(); return(new SelectionRangeInfo(newStartRangePointInfo, newEndRangePointInfo)); } else { TextLineBox workingLine = this; if (startPoint.LineId != _currentLineNumber) { workingLine = _textFlowLayer.GetTextLine(startPoint.LineId); } EditableVisualPointInfo newStartPoint = workingLine.Split(startPoint); workingLine = this; if (endPoint.LineId != _currentLineNumber) { workingLine = _textFlowLayer.GetTextLine(endPoint.LineId); } EditableVisualPointInfo newEndPoint = workingLine.Split(endPoint); return(new SelectionRangeInfo(newStartPoint, newEndPoint)); } }