Exemplo n.º 1
0
        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; 
                            }
                            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();
                        return backspaceCaretPosition; 
                    } 
                }
            } 
            return backspaceCaretPosition;
        }
Exemplo n.º 2
0
        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; 
        }