예제 #1
0
        public float GetXOffsetAtCharIndex(int charIndex)
        {
            float xoffset       = 0;
            int   acc_charCount = 0;

            Run r = this.FirstRun;

            while (r != null)
            {
                if (r.CharacterCount + acc_charCount >= charIndex)
                {
                    //found at this run
                    return(xoffset + r.GetRunWidth(charIndex - acc_charCount));
                }
                xoffset       += r.Width;
                acc_charCount += r.CharacterCount;
                r              = r.NextRun;
            }
            //foreach (Run r in _runs)
            //{
            //    if (r.CharacterCount + acc_charCount >= charIndex)
            //    {
            //        //found at this run
            //        return xoffset + r.GetRunWidth(charIndex - acc_charCount);
            //    }
            //    xoffset += r.Width;
            //    acc_charCount += r.CharacterCount;
            //}
            return(0);//?
        }
예제 #2
0
        public EditableVisualPointInfo GetTextPointInfoFromCharIndex(int charIndex)
        {
            int limit = CharCount() - 1;

            if (charIndex > limit)
            {
                charIndex = limit;
            }


            int rCharOffset  = 0;
            int rPixelOffset = 0;
            Run lastestRun   = null;
            EditableVisualPointInfo textPointInfo = null;

            foreach (Run r in _runs)
            {
                lastestRun = r;
                int thisCharCount = lastestRun.CharacterCount;
                if (thisCharCount + rCharOffset > charIndex)
                {
                    int localCharOffset = charIndex - rCharOffset;
                    int pixelOffset     = lastestRun.GetRunWidth(localCharOffset);
                    textPointInfo = new EditableVisualPointInfo(this, charIndex, lastestRun);
                    textPointInfo.SetAdditionVisualInfo(localCharOffset, rPixelOffset + pixelOffset, rPixelOffset);
                    return(textPointInfo);
                }
                else
                {
                    rCharOffset  += thisCharCount;
                    rPixelOffset += r.Width;
                }
            }


            textPointInfo = new EditableVisualPointInfo(this, charIndex, lastestRun);
            textPointInfo.SetAdditionVisualInfo(rCharOffset - lastestRun.CharacterCount, rPixelOffset, rPixelOffset - lastestRun.Width);
            return(textPointInfo);
        }
예제 #3
0
        bool MoveToNextTextRun()
        {
            //#if DEBUG
            //            if (_currentTextRun.IsLineBreak)
            //            {
            //                throw new NotSupportedException();
            //            }
            //#endif


            Run nextTextRun = _currentTextRun.NextRun;

            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);
        }
예제 #4
0
        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
        }