bool MoveToNextTextRun() { #if DEBUG if (_currentTextRun.IsLineBreak) { throw new NotSupportedException(); } #endif EditableRun nextTextRun = _currentTextRun.NextTextRun; if (nextTextRun != null && !nextTextRun.IsLineBreak) { _rCharOffset += _currentTextRun.CharacterCount; _rPixelOffset += _currentTextRun.Width; _currentTextRun = nextTextRun; caret_char_index = _rCharOffset; _caretXPos = _rPixelOffset + _currentTextRun.GetRunWidth(0); return(true); } return(false); }
public EditableVisualPointInfo GetTextPointInfoFromCharIndex(int charIndex) { int limit = CharCount - 1; if (charIndex > limit) { charIndex = limit; } EditableVisualPointInfo textPointInfo = new EditableVisualPointInfo(this, charIndex); int rCharOffset = 0; int rPixelOffset = 0; EditableRun lastestRun = null; foreach (EditableRun r in _runs) { lastestRun = r; int thisCharCount = lastestRun.CharacterCount; if (thisCharCount + rCharOffset > charIndex) { int localCharOffset = charIndex - rCharOffset; int pixelOffset = lastestRun.GetRunWidth(localCharOffset); textPointInfo.SetAdditionVisualInfo(lastestRun, localCharOffset, rPixelOffset + pixelOffset , rPixelOffset); return(textPointInfo); } else { rCharOffset += thisCharCount; rPixelOffset += r.Width; } } textPointInfo.SetAdditionVisualInfo(lastestRun, rCharOffset - lastestRun.CharacterCount, rPixelOffset, rPixelOffset - lastestRun.Width); return(textPointInfo); }
public void SetCurrentCharIndex(int newCharIndexPointTo) { #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.WriteInfo("TextLineReader::CharIndex_set=" + newCharIndexPointTo); dbugTextManRecorder.BeginContext(); } #endif if (newCharIndexPointTo < 0 || newCharIndexPointTo > _currentLine.CharCount) { throw new NotSupportedException("index out of range"); } if (newCharIndexPointTo == 0) { caret_char_index = 0; _caretXPos = 0; _rCharOffset = 0; _rPixelOffset = 0; _currentTextRun = _currentLine.FirstRun; } else { int diff = newCharIndexPointTo - caret_char_index; switch (diff) { case 0: { return; } default: { if (diff > 0) { do { if (_rCharOffset + _currentTextRun.CharacterCount >= newCharIndexPointTo) { caret_char_index = newCharIndexPointTo; _caretXPos = _rPixelOffset + _currentTextRun.GetRunWidth(caret_char_index - _rCharOffset); #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.EndContext(); } #endif return; } // } while (MoveToNextTextRun()); caret_char_index = _rCharOffset + _currentTextRun.CharacterCount; _caretXPos = _rPixelOffset + _currentTextRun.Width; return; } else { do { if (_rCharOffset - 1 < newCharIndexPointTo) { caret_char_index = newCharIndexPointTo; _caretXPos = _rPixelOffset + _currentTextRun.GetRunWidth(caret_char_index - _rCharOffset); #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.EndContext(); } #endif return; } } while (MoveToPreviousTextRun()); caret_char_index = 0; _caretXPos = 0; } } break; } } #if DEBUG if (dbugTextManRecorder != null) { dbugTextManRecorder.EndContext(); } #endif }