public TextPointer GetPositionAtOffset (int offset, LogicalDirection direction) { return NativeDependencyObjectHelper.FromIntPtr (NativeMethods.text_pointer_get_position_at_offset (native, offset, direction)) as TextPointer; } }
TextPointer GetTextPositionAtOffset(TextPointer position, int characterCount) { while (position != null) { var context = position.GetPointerContext(LogicalDirection.Forward); if (context == TextPointerContext.Text) { var count = position.GetTextRunLength(LogicalDirection.Forward); if (characterCount <= count) { return position.GetPositionAtOffset(characterCount); } characterCount -= count; } else if (position.Parent is LineBreak) { var count = 2; if (characterCount <= count) { return position.GetPositionAtOffset(characterCount); } characterCount -= count; } var nextContextPosition = position.GetNextContextPosition(LogicalDirection.Forward); if (nextContextPosition == null) return position; position = nextContextPosition; } return position; }