LayoutFarm.Text.EditableTextLine.GetTextPointInfoFromCharIndex C# (CSharp) Метод

GetTextPointInfoFromCharIndex() публичный Метод

public GetTextPointInfoFromCharIndex ( int charIndex ) : EditableVisualPointInfo
charIndex int
Результат EditableVisualPointInfo
        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 this)
            {
                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;
        }

Usage Example

 public void UpdateSelectionRange()
 {
     if (startPoint.TextRun != null && !startPoint.TextRun.HasParent)
     {
         EditableTextLine startLine = startPoint.EditableLine;
         startPoint = startLine.GetTextPointInfoFromCharIndex(startPoint.LineCharIndex);
     }
     if (endPoint.TextRun != null && !endPoint.TextRun.HasParent)
     {
         EditableTextLine stopLine = endPoint.EditableLine;
         endPoint = stopLine.GetTextPointInfoFromCharIndex(endPoint.LineCharIndex);
     }
 }
All Usage Examples Of LayoutFarm.Text.EditableTextLine::GetTextPointInfoFromCharIndex