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


C# Line.GetBackspaceCaretCharacterHit方法代码示例

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


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

示例1: BackspaceCaretUnitPositionFromDcpCompositeLines

        private ITextPointer BackspaceCaretUnitPositionFromDcpCompositeLines(
            int dcp,
            ITextPointer position,
            ref PTS.FSTEXTDETAILSFULL textDetails) 
        {
            ErrorHandler.Assert(!PTS.ToBoolean(textDetails.fDropCapPresent), ErrorHandler.NotSupportedDropCap); 
 
            // Get list of lines
            PTS.FSLINEDESCRIPTIONCOMPOSITE[] arrayLineDesc; 
            PtsHelper.LineListCompositeFromTextPara(PtsContext, _paraHandle.Value, ref textDetails, out arrayLineDesc);

            // Declare backspace position and set it to initial position
            ITextPointer backspaceCaretPosition = position; 

            // First iterate through lines 
            for (int index = 0; index < arrayLineDesc.Length; index++) 
            {
                PTS.FSLINEDESCRIPTIONCOMPOSITE lineDesc = arrayLineDesc[index]; 
                if (lineDesc.cElements == 0) { continue; }

                // Get list of line elements.
                PTS.FSLINEELEMENT[] arrayLineElement; 
                PtsHelper.LineElementListFromCompositeLine(PtsContext, ref lineDesc, out arrayLineElement);
 
                for (int elIndex = 0; elIndex < arrayLineElement.Length; elIndex++) 
                {
                    PTS.FSLINEELEMENT element = arrayLineElement[elIndex]; 

                    // 'dcp' needs to be within line range. If position points to dcpLim,
                    // it means that the next line starts from such position, hence go to the next line.
                    if (((element.dcpFirst <= dcp) && (element.dcpLim > dcp)) 
                        || ((element.dcpLim == dcp) && (elIndex == arrayLineElement.Length - 1) && (index == arrayLineDesc.Length - 1)))
                    { 
                        if (dcp == element.dcpFirst) 
                        {
                            // Beginning of element. 
                            if (dcp == 0)
                            {
                                // Assert that this is first elment on first line
                                Debug.Assert(index == 0); 
                                Debug.Assert(elIndex == 0);
                                return position; 
                            } 
                            else
                            { 
                                if (elIndex > 0)
                                {
                                    // Beginning of element, but not of line
                                    --elIndex; 
                                    element = arrayLineElement[elIndex];
                                } 
                                else 
                                {
                                    // There must be at least one line above this 
                                    Debug.Assert(index > 0);

                                    // Go to previous line
                                    --index; 
                                    lineDesc = arrayLineDesc[index];
                                    if (lineDesc.cElements == 0) 
                                    { 
                                        // Stay in same position
                                        return position; 
                                    }
                                    else
                                    {
                                        // Get list of line elements. 
                                        PtsHelper.LineElementListFromCompositeLine(PtsContext, ref lineDesc, out arrayLineElement);
                                        element = arrayLineElement[arrayLineElement.Length - 1]; 
                                    } 
                                }
                            } 
                        }

                        // Create and format line
                        Line line = new Line(Paragraph.StructuralCache.TextFormatterHost, this, Paragraph.ParagraphStartCharacterPosition); 
                        Line.FormattingContext ctx = new Line.FormattingContext(false, PTS.ToBoolean(element.fClearOnLeft), PTS.ToBoolean(element.fClearOnRight), TextParagraph.TextRunCache);
 
                        if(IsOptimalParagraph) 
                        {
                            ctx.LineFormatLengthTarget = element.dcpLim - element.dcpFirst; 
                        }

                        TextParagraph.FormatLineCore(line, element.pfsbreakreclineclient, ctx, element.dcpFirst, element.dur, PTS.ToBoolean(lineDesc.fTreatedAsFirst), element.dcpFirst);
 
                        // Assert that number of characters in Text line is the same as our expected length
                        Invariant.Assert(line.SafeLength == element.dcpLim - element.dcpFirst, "Line length is out of [....]"); 
 
                        // Create CharacterHit from dcp, and get backspace
                        CharacterHit charHit = new CharacterHit(dcp, 0); 
                        CharacterHit backspaceCharacterHit = line.GetBackspaceCaretCharacterHit(charHit);
                        LogicalDirection logicalDirection;
                        if (backspaceCharacterHit.FirstCharacterIndex + backspaceCharacterHit.TrailingLength == element.dcpFirst)
                        { 
                            // Going forward brought us to the start of a line, context must be backward for previous line
                            if (index == 0) 
                            { 
                                // First line, so we will stay forward
                                logicalDirection = LogicalDirection.Forward; 
                            }
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextParaClient.cs

示例2: BackspaceCaretUnitPositionFromDcpSimpleLines

        private ITextPointer BackspaceCaretUnitPositionFromDcpSimpleLines( 
            int dcp,
            ITextPointer position, 
            ref PTS.FSTEXTDETAILSFULL textDetails)
        {
            ErrorHandler.Assert(!PTS.ToBoolean(textDetails.fDropCapPresent), ErrorHandler.NotSupportedDropCap);
 
            // Get list of lines
            PTS.FSLINEDESCRIPTIONSINGLE[] arrayLineDesc; 
            PtsHelper.LineListSimpleFromTextPara(PtsContext, _paraHandle.Value, ref textDetails, out arrayLineDesc); 

            // Declare backspace position and set it to initial position 
            ITextPointer backspaceCaretPosition = position;

            // First iterate through lines
            for (int index = 0; index < arrayLineDesc.Length; index++) 
            {
                PTS.FSLINEDESCRIPTIONSINGLE lineDesc = arrayLineDesc[index]; 
 
                // 'dcp' needs to be within line range. If position points to dcpLim,
                // it means that the next line starts from such position, hence go to the next line. 
                if (((lineDesc.dcpFirst <= dcp) && (lineDesc.dcpLim > dcp))
                    || ((lineDesc.dcpLim == dcp) && (index == arrayLineDesc.Length - 1)))
                {
                    if (dcp == lineDesc.dcpFirst) 
                    {
                        // Go to previous line 
                        if (index == 0) 
                        {
                            return position; 
                        }
                        else
                        {
                            // Update dcp, lineDesc 
                            Debug.Assert(index > 0);
                            --index; 
                            lineDesc = arrayLineDesc[index]; 
                        }
                    } 

                    // Create and format line
                    Line line = new Line(Paragraph.StructuralCache.TextFormatterHost, this, Paragraph.ParagraphStartCharacterPosition);
                    Line.FormattingContext ctx = new Line.FormattingContext(false, PTS.ToBoolean(lineDesc.fClearOnLeft), PTS.ToBoolean(lineDesc.fClearOnRight), TextParagraph.TextRunCache); 

                    if(IsOptimalParagraph) 
                    { 
                        ctx.LineFormatLengthTarget = lineDesc.dcpLim - lineDesc.dcpFirst;
                    } 

                    TextParagraph.FormatLineCore(line, lineDesc.pfsbreakreclineclient, ctx, lineDesc.dcpFirst, lineDesc.dur, PTS.ToBoolean(lineDesc.fTreatedAsFirst), lineDesc.dcpFirst);

                    // Assert that number of characters in Text line is the same as our expected length 
                    Invariant.Assert(line.SafeLength == lineDesc.dcpLim - lineDesc.dcpFirst, "Line length is out of [....]");
 
                    // Create CharacterHit and get backspace index from line API 
                    CharacterHit textSourceCharacterIndex = new CharacterHit(dcp, 0);
                    CharacterHit backspaceCharacterHit = line.GetBackspaceCaretCharacterHit(textSourceCharacterIndex); 
                    LogicalDirection logicalDirection;
                    if (backspaceCharacterHit.FirstCharacterIndex + backspaceCharacterHit.TrailingLength == lineDesc.dcpFirst)
                    {
                        // Going forward brought us to the start of a line, context must be backward for previous line 
                        if (index == 0)
                        { 
                            // First line, so we will stay forward 
                            logicalDirection = LogicalDirection.Forward;
                        } 
                        else
                        {
                            logicalDirection = LogicalDirection.Backward;
                        } 
                    }
                    else 
                    { 
                        logicalDirection = (backspaceCharacterHit.TrailingLength > 0) ? LogicalDirection.Backward : LogicalDirection.Forward;
                    } 
                    backspaceCaretPosition = GetTextPosition(backspaceCharacterHit.FirstCharacterIndex + backspaceCharacterHit.TrailingLength, logicalDirection);

                    // Dispose the line
                    line.Dispose(); 
                    break;
                } 
            } 
            Debug.Assert(backspaceCaretPosition != null);
            return backspaceCaretPosition; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:85,代码来源:TextParaClient.cs


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