Alsing.Windows.Forms.SyntaxBox.Painter.NativePainter.ColumnFromPixel C# (CSharp) 메소드

ColumnFromPixel() 개인적인 메소드

private ColumnFromPixel ( int RowIndex, int X ) : TextPoint
RowIndex int
X int
리턴 Alsing.SourceCode.TextPoint
        private TextPoint ColumnFromPixel(int RowIndex, int X)
        {
            Row xtr = Control.Document[RowIndex];
            X -= Control.View.TextMargin - 2 - Control.View.FirstVisibleColumn*Control.View.CharWidth;

            if (xtr.Count == 0)
            {
                if (Control.VirtualWhitespace && Control.View.CharWidth > 0)
                {
                    return new TextPoint(X/Control.View.CharWidth, RowIndex);
                }

                return new TextPoint(0, RowIndex);
            }


            int taborig = -Control.View.FirstVisibleColumn*Control.View.CharWidth + Control.View.TextMargin;
            int xpos = Control.View.TextMargin - Control.View.ClientAreaStart;
            int CharNo = 0;
            int TotWidth = 0;
            Word Word = null;
            int WordStart = 0;
            foreach (Word w in xtr.FormattedWords)
            {
                Word = w;
                WordStart = TotWidth;

                if (w.Type == WordType.Word && w.Style != null)
                    SetStringFont(w.Style.Bold, w.Style.Italic, w.Style.Underline);
                else
                    SetStringFont(false, false, false);

                int tmpWidth = GFX.StringBuffer.DrawTabbedString(w.Text, xpos + TotWidth, 0, taborig, Control.PixelTabSize).Width;

                if (TotWidth + tmpWidth >= X)
                {
                    break;
                }

                //dont do this for the last word
                if (w != xtr.FormattedWords[xtr.FormattedWords.Count - 1])
                {
                    TotWidth += tmpWidth;
                    CharNo += w.Text.Length;
                }
            }

            //CharNo is the index in the text where 'word' starts
            //'Word' is the word object that contains the 'X'
            //'WordStart' contains the pixel start position for 'Word'

            if (Word != null)
                if (Word.Type == WordType.Word && Word.Style != null)
                    SetStringFont(Word.Style.Bold, Word.Style.Italic, Word.Style.Underline);
                else
                    SetStringFont(false, false, false);

            //now , lets measure each char and get a correct pos

            bool found = false;
            if (Word != null)
                foreach (char c in Word.Text)
                {
                    int tmpWidth = GFX.StringBuffer.DrawTabbedString(c + "", xpos + WordStart, 0, taborig, Control.PixelTabSize).Width;
                    if (WordStart + tmpWidth >= X)
                    {
                        found = true;
                        break;
                    }
                    CharNo++;
                    WordStart += tmpWidth;
                }

            if (!found && Control.View.CharWidth > 0 && Control.VirtualWhitespace)
            {
                int xx = X - WordStart;
                int cn = xx/Control.View.CharWidth;
                CharNo += cn;
            }

            if (CharNo < 0)
                CharNo = 0;

            return new TextPoint(CharNo, RowIndex);
        }