Ejemplo n.º 1
0
        private static TextPointer LetterShift_Exact(TextPointer start, int numLetters)
        {
            if (numLetters == 0 || start == null)
            {
                return(start);
            }

            int         decrease     = (numLetters < 0 ? -1 : 1);
            TextPointer projectedEnd = start.GetPositionAtOffset(numLetters);

            if (projectedEnd == null)
            {
                while (projectedEnd == null)
                {
                    numLetters   = numLetters - decrease;
                    projectedEnd = start.GetPositionAtOffset(numLetters);
                    if (numLetters == 0)
                    {
                        return(start);
                    }
                }
                return(projectedEnd);
            }
            int mover = (numLetters > 0 ? 1 : -1);

            uint        letterCount = (uint)Math.Abs(numLetters);
            TextPointer ptrLastGood = projectedEnd;

            while (start.GetLetterOffset(projectedEnd) < letterCount)
            {
                projectedEnd = projectedEnd.GetPositionAtOffset(mover);
                if (projectedEnd == null)
                {
                    return(ptrLastGood);
                }
                ptrLastGood = projectedEnd;
            }
            return(projectedEnd);
        }
Ejemplo n.º 2
0
        private static TextPointer LetterShift_Guess(TextPointer start, int numLetters, out int numOff)
        {
            if (numLetters == 0)
            {
                numOff = 0;
                return(start);
            }

            TextPointer result = start.GetPositionAtOffset(numLetters);

            if (result == null)
            {
                numOff = 0;
                return(null);
            }
            if (!result.IsAtInsertionPosition)
            {
                TextPointer save;
                if ((save = result.GetNextInsertionPosition(LogicalDirection.Backward)) == null)
                {
                    if ((save = result.GetNextInsertionPosition(LogicalDirection.Forward)) == null)
                    {
                        numOff = 0;
                        return(null);
                    }
                }
                result = save;
            }

            bool wasNegative = numLetters < 0;

            numOff = Math.Abs(numLetters) - start.GetLetterOffset(result);
            if (wasNegative)
            {
                numOff *= -1;
            }
            return(result);
        }