当前位置: 首页>>代码示例>>C#>>正文


C# ITextPointer.GetTextRunLength方法代码示例

本文整理汇总了C#中ITextPointer.GetTextRunLength方法的典型用法代码示例。如果您正苦于以下问题:C# ITextPointer.GetTextRunLength方法的具体用法?C# ITextPointer.GetTextRunLength怎么用?C# ITextPointer.GetTextRunLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextPointer的用法示例。


在下文中一共展示了ITextPointer.GetTextRunLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTextInRun

        // Worker for GetText, accepts any ITextPointer.
        internal static string GetTextInRun(ITextPointer position, LogicalDirection direction)
        {
            char[] text;
            int textLength;
            int getTextLength;

            textLength = position.GetTextRunLength(direction);
            text = new char[textLength];

            getTextLength = position.GetTextInRun(direction, text, 0, textLength);
            Invariant.Assert(getTextLength == textLength, "textLengths returned from GetTextRunLength and GetTextInRun are innconsistent");

            return new string(text);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:15,代码来源:TextPointerBase.cs

示例2: WalkTextRun

        // GetText handler for text runs.
        private static bool WalkTextRun(ITextPointer navigator, ITextPointer limit, char[] text, int cchReq, ref int charsCopied, UnsafeNativeMethods.TS_RUNINFO[] runInfo, int cRunInfoReq, ref int cRunInfoRcv)
        {
            int runCount;
            int offset;
            bool hitLimit;

            Invariant.Assert(navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text);
            Invariant.Assert(limit == null || navigator.CompareTo(limit) <= 0);

            hitLimit = false;

            if (cchReq > 0)
            {
                runCount = TextPointerBase.GetTextWithLimit(navigator, LogicalDirection.Forward, text, charsCopied, Math.Min(cchReq, text.Length - charsCopied), limit);
                navigator.MoveByOffset(runCount);
                charsCopied += runCount;
                hitLimit = (text.Length == charsCopied) || (limit != null && navigator.CompareTo(limit) == 0);
            }
            else
            {
                // Caller doesn't want text, just run info.
                // Advance the navigator.
                runCount = navigator.GetTextRunLength(LogicalDirection.Forward);
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);

                // If the caller passed in a non-null limit, backup to the limit if
                // we've passed it.
                if (limit != null)
                {
                    if (navigator.CompareTo(limit) >= 0)
                    {
                        offset = limit.GetOffsetToPosition(navigator);
                        Invariant.Assert(offset >= 0 && offset <= runCount, "Bogus offset -- extends past run!");
                        runCount -= offset;
                        navigator.MoveToPosition(limit);
                        hitLimit = true;
                    }
                }
            }

            if (cRunInfoReq > 0 && runCount > 0)
            {
                // Be sure to merge this text run with the previous run, if they are both text runs.
                // (A good robustness fix would be to make cicero handle this, if we ever get the chance.)
                if (cRunInfoRcv > 0 && runInfo[cRunInfoRcv - 1].type == UnsafeNativeMethods.TsRunType.TS_RT_PLAIN)
                {
                    runInfo[cRunInfoRcv - 1].count += runCount;
                }
                else
                {
                    runInfo[cRunInfoRcv].count = runCount;
                    runInfo[cRunInfoRcv].type = UnsafeNativeMethods.TsRunType.TS_RT_PLAIN;
                    cRunInfoRcv++;
                }
            }

            return hitLimit;
        }
开发者ID:mind0n,项目名称:hive,代码行数:59,代码来源:TextStore.cs

示例3: PlainConvertTextRun

 // Part of plain text converter: called from GetTextInternal when processing Text runs 
 private static void PlainConvertTextRun(StringBuilder textBuffer, ITextPointer navigator, ITextPointer endPosition, ref Char[] charArray)
 { 
     // Copy this text run into destination
     int runLength = navigator.GetTextRunLength(LogicalDirection.Forward);
     charArray = EnsureCharArraySize(charArray, runLength);
     runLength = TextPointerBase.GetTextWithLimit(navigator, LogicalDirection.Forward, charArray, 0, runLength, endPosition); 
     textBuffer.Append(charArray, 0, runLength);
     navigator.MoveToNextContextPosition(LogicalDirection.Forward); 
 } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:10,代码来源:TextRangeBase.cs

示例4: SetFindTextAndFindTextPositionMap

        /// <summary> 
        /// Set the find text content from reading the text on the current text position. 
        /// </summary>
        /// <returns> 
        /// Returns the number of characters actually loaded into the findText array.
        /// </returns>
        private static int SetFindTextAndFindTextPositionMap(
            ITextPointer startPosition, 
            ITextPointer endPosition,
            ITextPointer navigator, 
            LogicalDirection direction, 
            bool matchLast,
            char[] findText, 
            int[] findTextPositionMap)
        {
            Invariant.Assert(startPosition.CompareTo(navigator) <= 0);
            Invariant.Assert(endPosition.CompareTo(navigator) >= 0); 

            int runCount; 
            int inlineCount = 0; 
            int findTextLength = 0;
 
            // Set the first offset which is zero on TextBufferSize + 1 location of
            // the text position map in case of the backward searching
            if (matchLast && findTextLength == 0)
            { 
                findTextPositionMap[findTextPositionMap.Length - 1] = 0;
            } 
 
            while ((matchLast ? startPosition.CompareTo(navigator) : navigator.CompareTo(endPosition)) < 0)
            { 

                switch (navigator.GetPointerContext(direction))
                {
                    case TextPointerContext.Text: 
                        runCount = navigator.GetTextRunLength(direction);
                        runCount = Math.Min(runCount, findText.Length - findTextLength); 
 
                        if (!matchLast)
                        { 
                            runCount = Math.Min(runCount, navigator.GetOffsetToPosition(endPosition));
                            navigator.GetTextInRun(direction, findText, findTextLength, runCount);

                            for (int i = findTextLength; i < findTextLength + runCount; i++) 
                            {
                                findTextPositionMap[i] = i + inlineCount; 
                            } 
                        }
                        else 
                        {
                            runCount = Math.Min(runCount, startPosition.GetOffsetToPosition(navigator));
                            navigator.GetTextInRun(
                                direction, 
                                findText,
                                findText.Length - findTextLength - runCount, 
                                runCount); 

                            // Set the text offest for the amount of runCount from the last index 
                            // of text position map
                            int mapIndex = findText.Length - findTextLength - 1;
                            for (int i = findTextLength; i < findTextLength + runCount; i++)
                            { 
                                findTextPositionMap[mapIndex--] = i + inlineCount + 1;
                            } 
                        } 

                        // Move the navigator position for the amount of runCount 
                        navigator.MoveByOffset(matchLast ? - runCount : runCount);
                        findTextLength += runCount;
                        break;
 
                    case TextPointerContext.None:
                    case TextPointerContext.ElementStart: 
                    case TextPointerContext.ElementEnd: 
                        if (IsAdjacentToFormatElement(navigator, direction))
                        { 
                            // Filter out formatting tags since find text content is plain.
                            inlineCount++;
                        }
                        else 
                        {
                            if (!matchLast) 
                            { 
                                // Stick in a line break to account for the block element.
                                findText[findTextLength] = '\n'; 
                                findTextPositionMap[findTextLength] = findTextLength + inlineCount;
                                findTextLength++;
                            }
                            else 
                            {
                                // Increse the find text length first since adding text and map reversely 
                                findTextLength++; 

                                // Stick in a line break to account for the block element and 
                                // add text offset on the last index of text position map
                                findText[findText.Length - findTextLength] = '\n';
                                findTextPositionMap[findText.Length - findTextLength] = findTextLength + inlineCount;
                            } 
                        }
 
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextFindEngine.cs


注:本文中的ITextPointer.GetTextRunLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。