Beispiel #1
0
        private void RectFromDcpCompositeLines( 
            int dcp,
            int originalDcp,
            LogicalDirection orientation,
            TextPointerContext context, 
            ref PTS.FSTEXTDETAILSFULL textDetails,
            ref Rect rect, 
            ref int vrBaseline) 
        {
            ErrorHandler.Assert(!PTS.ToBoolean(textDetails.fDropCapPresent), ErrorHandler.NotSupportedDropCap); 

            // Get list of lines
            PTS.FSLINEDESCRIPTIONCOMPOSITE [] arrayLineDesc;
            PtsHelper.LineListCompositeFromTextPara(PtsContext, _paraHandle.Value, ref textDetails, out arrayLineDesc); 

            // 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.
                    // But if this is the last line (EOP character), get rectangle form the last 
                    // character of the line.
                    if (   ((element.dcpFirst <= dcp) && (element.dcpLim > dcp)) 
                        || ((element.dcpLim == dcp) && (elIndex == arrayLineElement.Length - 1) && (index == arrayLineDesc.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 [....]");
 
                        // Get rect from cp
                        FlowDirection flowDirection; 
                        rect = line.GetBoundsFromTextPosition(dcp, out flowDirection); 
                        rect.X += TextDpi.FromTextDpi(element.urStart);
                        rect.Y += TextDpi.FromTextDpi(lineDesc.vrStart); 

                        // Return only TopLeft and Height.
                        // Adjust rect.Left by taking into account flow direction of the
                        // content and orientation of input position. 
                        if (ThisFlowDirection != flowDirection)
                        { 
                            if (orientation == LogicalDirection.Forward) 
                            {
                                rect.X = rect.Right; 
                            }
                        }
                        else
                        { 
                            // NOTE: check for 'originalCharacterIndex > 0' is only required for position at the beginning
                            //       content with Backward orientation. This should not be a valid position. 
                            //       Remove it later 
                            if (orientation == LogicalDirection.Backward && originalDcp > 0 && (context == TextPointerContext.Text || context == TextPointerContext.EmbeddedElement))
                            { 
                                rect.X = rect.Right;
                            }
                        }
                        rect.Width = 0; 

                        vrBaseline = line.Baseline + lineDesc.vrStart; 
 
                        // Dispose the line
                        line.Dispose(); 
                        break;
                    }
                }
            } 
        }