Пример #1
0
        // Token: 0x0600676F RID: 26479 RVA: 0x001CECD4 File Offset: 0x001CCED4
        internal Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect)
        {
            Geometry geometry = null;

            if (endPosition.CompareTo(this.Cell.StaticElementEnd) >= 0)
            {
                geometry = new RectangleGeometry(this._rect.FromTextDpi());
            }
            else
            {
                SubpageParagraphResult            subpageParagraphResult = (SubpageParagraphResult)this.CreateParagraphResult();
                ReadOnlyCollection <ColumnResult> columns = subpageParagraphResult.Columns;
                Transform transform = new TranslateTransform(-TextDpi.FromTextDpi(base.ContentRect.u), -TextDpi.FromTextDpi(base.ContentRect.v));
                visibleRect = transform.TransformBounds(visibleRect);
                geometry    = TextDocumentView.GetTightBoundingGeometryFromTextPositionsHelper(columns[0].Paragraphs, subpageParagraphResult.FloatingElements, startPosition, endPosition, 0.0, visibleRect);
                if (geometry != null)
                {
                    Rect viewport = new Rect(0.0, 0.0, TextDpi.FromTextDpi(base.ContentRect.du), TextDpi.FromTextDpi(base.ContentRect.dv));
                    CaretElement.ClipGeometryByViewport(ref geometry, viewport);
                    transform = new TranslateTransform(TextDpi.FromTextDpi(base.ContentRect.u), TextDpi.FromTextDpi(base.ContentRect.v));
                    CaretElement.AddTransformToGeometry(geometry, transform);
                }
            }
            return(geometry);
        }
Пример #2
0
        /// <summary>
        ///  Gets the rectangle for this ITextPointer
        /// </summary>
        /// <param name="pointer">the pointer to examine</param>
        /// <returns>
        /// The anchor point of the selection;
        /// If there is no valid AnchorPoint returns Point(Double.NaN, Double.NaN).
        /// </returns>
        /// <exception cref="ArgumentNullException">pointer is null</exception>
        public static Rect GetAnchorRectangle(ITextPointer pointer)
        {
            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }
            bool extension = false;

            ITextView textView = GetDocumentPageTextView(pointer);

            if (pointer.CompareTo(pointer.TextContainer.End) == 0)
            {
                //we can not get rectangle for the end of the TextContainer
                //so get the last symbol
                Point endPoint = new Point(Double.MaxValue, Double.MaxValue);
                pointer = textView.GetTextPositionFromPoint(endPoint, true);
                //we need to move the resulting rectangle at half space because
                //the geometry calculating function does the same
                extension = true;
            }
            if (textView != null && textView.IsValid && TextDocumentView.Contains(pointer, textView.TextSegments))
            {
                Rect rect = textView.GetRectangleFromTextPosition(pointer);
                if (extension && rect != Rect.Empty)
                {
                    rect.X += rect.Height / 2.0;
                }
                return(rect);
            }

            return(Rect.Empty);
        }
        // Token: 0x06006858 RID: 26712 RVA: 0x001D6978 File Offset: 0x001D4B78
        private TextDocumentView GetTextView()
        {
            TextDocumentView textDocumentView = (TextDocumentView)((IServiceProvider)this).GetService(typeof(ITextView));

            Invariant.Assert(textDocumentView != null);
            return(textDocumentView);
        }
Пример #4
0
        /// <summary>
        /// Retrieves PageNumber for specified ContentPosition.
        /// </summary>
        /// <param name="contentPosition">
        /// Represents content position for which PageNumber is requested.</param>
        /// <param name="pageNumber">Starting index for search process.</param>
        /// <returns>
        /// Returns true, if successfull. 'pageNumber' is updated with actual
        ///     page number that contains specified ContentPosition.
        /// Returns false, if BreakRecordTable is missing information about
        /// page that contains specified ContentPosition. 'pageNumber'
        /// is updated with the last investigated page number.
        /// </returns>
        internal bool GetPageNumberForContentPosition(TextPointer contentPosition, ref int pageNumber)
        {
            bool foundPageNumber = false;
            ReadOnlyCollection <TextSegment> textSegments;

            Invariant.Assert(pageNumber >= 0 && pageNumber <= _breakRecords.Count, "Invalid PageNumber.");

            // Iterate through entries in the BreakRecordTable (starting from specified index)
            // and look for page that contains specified ContentPosition.
            // NOTE: For each cached page collection of TextSegments is stored to
            // optimize this search.
            while (pageNumber < _breakRecords.Count)
            {
                Invariant.Assert(_breakRecords[pageNumber] != null, "Invalid BreakRecordTable entry.");
                textSegments = _breakRecords[pageNumber].TextSegments;
                if (textSegments != null)
                {
                    if (TextDocumentView.Contains(contentPosition, textSegments))
                    {
                        foundPageNumber = true;
                        break;
                    }
                }
                else
                {
                    // There is no information about this page.
                    break;
                }
                ++pageNumber;
            }
            return(foundPageNumber);
        }
Пример #5
0
        // Token: 0x06007C39 RID: 31801 RVA: 0x0022EDE4 File Offset: 0x0022CFE4
        public static Rect GetAnchorRectangle(ITextPointer pointer)
        {
            if (pointer == null)
            {
                throw new ArgumentNullException("pointer");
            }
            bool      flag = false;
            ITextView documentPageTextView = TextSelectionHelper.GetDocumentPageTextView(pointer);

            if (pointer.CompareTo(pointer.TextContainer.End) == 0)
            {
                Point point = new Point(double.MaxValue, double.MaxValue);
                pointer = documentPageTextView.GetTextPositionFromPoint(point, true);
                flag    = true;
            }
            if (documentPageTextView != null && documentPageTextView.IsValid && TextDocumentView.Contains(pointer, documentPageTextView.TextSegments))
            {
                Rect rectangleFromTextPosition = documentPageTextView.GetRectangleFromTextPosition(pointer);
                if (flag && rectangleFromTextPosition != Rect.Empty)
                {
                    rectangleFromTextPosition.X += rectangleFromTextPosition.Height / 2.0;
                }
                return(rectangleFromTextPosition);
            }
            return(Rect.Empty);
        }
Пример #6
0
        //-------------------------------------------------------------------
        //
        //  Private Methods
        //
        //-------------------------------------------------------------------

        #region Private Methods

        // This method calculates the height of the first line if the element is TextBlock or FlowDocumentScrollViewer
        // Otherwise returns the element height
        private double GetFirstLineHeight(UIElement element)
        {
            // We need to find TextBlock/FlowDocumentScrollViewer if it is nested inside ContentPresenter
            // Common scenario when used in styles is that BulletDecorator content is a ContentPresenter
            UIElement text = FindText(element);
            ReadOnlyCollection <LineResult> lr = null;

            if (text != null)
            {
                TextBlock textElement = ((TextBlock)text);
                if (textElement.IsLayoutDataValid)
                {
                    lr = textElement.GetLineResults();
                }
            }
            else
            {
                text = FindFlowDocumentScrollViewer(element);
                if (text != null)
                {
                    TextDocumentView tdv = ((IServiceProvider)text).GetService(typeof(ITextView)) as TextDocumentView;
                    if (tdv != null && tdv.IsValid)
                    {
                        ReadOnlyCollection <ColumnResult> cr = tdv.Columns;
                        if (cr != null && cr.Count > 0)
                        {
                            ColumnResult columnResult = cr[0];
                            ReadOnlyCollection <ParagraphResult> pr = columnResult.Paragraphs;
                            if (pr != null && pr.Count > 0)
                            {
                                ContainerParagraphResult cpr = pr[0] as ContainerParagraphResult;
                                if (cpr != null)
                                {
                                    TextParagraphResult textParagraphResult = cpr.Paragraphs[0] as TextParagraphResult;
                                    if (textParagraphResult != null)
                                    {
                                        lr = textParagraphResult.Lines;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (lr != null && lr.Count > 0)
            {
                Point ancestorOffset = new Point();
                text.TransformToAncestor(element).TryTransform(ancestorOffset, out ancestorOffset);
                return(lr[0].LayoutBox.Height + ancestorOffset.Y * 2d);
            }

            return(element.RenderSize.Height);
        }
Пример #7
0
        // Token: 0x06006792 RID: 26514 RVA: 0x001CF734 File Offset: 0x001CD934
        internal Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect)
        {
            bool flag;
            ReadOnlyCollection <ParagraphResult> childrenParagraphResults = this.GetChildrenParagraphResults(out flag);

            Invariant.Assert(childrenParagraphResults != null, "Paragraph collection is null.");
            if (childrenParagraphResults.Count > 0)
            {
                return(TextDocumentView.GetTightBoundingGeometryFromTextPositionsHelper(childrenParagraphResults, startPosition, endPosition, TextDpi.FromTextDpi(this._dvrTopSpace), visibleRect));
            }
            return(null);
        }
        /// <summary>
        /// Returns tight bounding path geometry.
        /// </summary>
        internal Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect)
        {
            bool hasTextContent;
            ReadOnlyCollection <ParagraphResult> paragraphs = GetChildrenParagraphResults(out hasTextContent);

            Invariant.Assert(paragraphs != null, "Paragraph collection is null.");

            if (paragraphs.Count > 0)
            {
                return(TextDocumentView.GetTightBoundingGeometryFromTextPositionsHelper(paragraphs, startPosition, endPosition, TextDpi.FromTextDpi(_dvrTopSpace), visibleRect));
            }

            return(null);
        }
Пример #9
0
        // Token: 0x0600650E RID: 25870 RVA: 0x001C5C3C File Offset: 0x001C3E3C
        private static void DumpFlowDocumentPage(XmlTextWriter writer, DocumentPage page)
        {
            FlowDocumentPage flowDocumentPage = page as FlowDocumentPage;

            writer.WriteStartElement("FormattedLines");
            writer.WriteAttributeString("Count", flowDocumentPage.FormattedLinesCount.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();
            TextDocumentView textDocumentView = (TextDocumentView)((IServiceProvider)flowDocumentPage).GetService(typeof(ITextView));

            if (textDocumentView.IsValid)
            {
                LayoutDump.DumpColumnResults(writer, textDocumentView.Columns, page.Visual);
            }
        }
Пример #10
0
        // Token: 0x06005BFA RID: 23546 RVA: 0x0019DB54 File Offset: 0x0019BD54
        private double GetFirstLineHeight(UIElement element)
        {
            UIElement uielement = this.FindText(element);
            ReadOnlyCollection <LineResult> readOnlyCollection = null;

            if (uielement != null)
            {
                TextBlock textBlock = (TextBlock)uielement;
                if (textBlock.IsLayoutDataValid)
                {
                    readOnlyCollection = textBlock.GetLineResults();
                }
            }
            else
            {
                uielement = this.FindFlowDocumentScrollViewer(element);
                if (uielement != null)
                {
                    TextDocumentView textDocumentView = ((IServiceProvider)uielement).GetService(typeof(ITextView)) as TextDocumentView;
                    if (textDocumentView != null && textDocumentView.IsValid)
                    {
                        ReadOnlyCollection <ColumnResult> columns = textDocumentView.Columns;
                        if (columns != null && columns.Count > 0)
                        {
                            ColumnResult columnResult = columns[0];
                            ReadOnlyCollection <ParagraphResult> paragraphs = columnResult.Paragraphs;
                            if (paragraphs != null && paragraphs.Count > 0)
                            {
                                ContainerParagraphResult containerParagraphResult = paragraphs[0] as ContainerParagraphResult;
                                if (containerParagraphResult != null)
                                {
                                    TextParagraphResult textParagraphResult = containerParagraphResult.Paragraphs[0] as TextParagraphResult;
                                    if (textParagraphResult != null)
                                    {
                                        readOnlyCollection = textParagraphResult.Lines;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (readOnlyCollection != null && readOnlyCollection.Count > 0)
            {
                Point inPoint = default(Point);
                uielement.TransformToAncestor(element).TryTransform(inPoint, out inPoint);
                return(readOnlyCollection[0].LayoutBox.Height + inPoint.Y * 2.0);
            }
            return(element.RenderSize.Height);
        }
        // Token: 0x06006815 RID: 26645 RVA: 0x001D4A00 File Offset: 0x001D2C00
        internal Geometry GetTightBoundingGeometryFromTextPositions(ReadOnlyCollection <ColumnResult> columns, ReadOnlyCollection <ParagraphResult> floatingElements, ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect)
        {
            Geometry result = null;

            Invariant.Assert(columns != null && columns.Count <= 1, "Columns collection is null.");
            Invariant.Assert(floatingElements != null, "Floating element collection is null.");
            ReadOnlyCollection <ParagraphResult> readOnlyCollection = (columns.Count > 0) ? columns[0].Paragraphs : new ReadOnlyCollection <ParagraphResult>(new List <ParagraphResult>(0));

            if (readOnlyCollection.Count > 0 || floatingElements.Count > 0)
            {
                result = TextDocumentView.GetTightBoundingGeometryFromTextPositionsHelper(readOnlyCollection, floatingElements, startPosition, endPosition, TextDpi.FromTextDpi(this._dvrTopSpace), visibleRect);
                Rect viewport = new Rect(0.0, 0.0, TextDpi.FromTextDpi(this._contentRect.du), TextDpi.FromTextDpi(this._contentRect.dv));
                CaretElement.ClipGeometryByViewport(ref result, viewport);
            }
            return(result);
        }
Пример #12
0
        // ------------------------------------------------------------------
        // Dump FlowDocumentPage specific data.
        // ------------------------------------------------------------------
        private static void DumpFlowDocumentPage(XmlTextWriter writer, DocumentPage page)
        {
            FlowDocumentPage flowDocumentPage = page as FlowDocumentPage;

            Debug.Assert(flowDocumentPage != null, "Dump function has to match page type.");

            // Dump private info.
            writer.WriteStartElement("FormattedLines");
            writer.WriteAttributeString("Count", flowDocumentPage.FormattedLinesCount.ToString(CultureInfo.InvariantCulture));
            writer.WriteEndElement();

            // Dump columns collection
            TextDocumentView tv = (TextDocumentView)((IServiceProvider)flowDocumentPage).GetService(typeof(ITextView));

            if (tv.IsValid)
            {
                DumpColumnResults(writer, tv.Columns, page.Visual);
            }
        }
Пример #13
0
        /// <summary>
        /// Returns tight bounding path geometry.
        /// </summary>
        internal Geometry GetTightBoundingGeometryFromTextPositions(ReadOnlyCollection <ColumnResult> columns, ReadOnlyCollection <ParagraphResult> floatingElements, ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect)
        {
            Geometry geometry = null;

            // Floater always has one column, so we can skip getting a column from the text position range
            Invariant.Assert(columns != null && columns.Count <= 1, "Columns collection is null.");
            Invariant.Assert(floatingElements != null, "Floating element collection is null.");
            ReadOnlyCollection <ParagraphResult> paragraphs = (columns.Count > 0) ? columns[0].Paragraphs : new ReadOnlyCollection <ParagraphResult>(new List <ParagraphResult>(0));

            if (paragraphs.Count > 0 || floatingElements.Count > 0)
            {
                geometry = TextDocumentView.GetTightBoundingGeometryFromTextPositionsHelper(paragraphs, floatingElements, startPosition, endPosition, TextDpi.FromTextDpi(_dvrTopSpace), visibleRect);

                //  restrict geometry to the floater's content rect boundary.
                //  because of end-of-line / end-of-para simulation calculated geometry could be larger.
                Rect viewport = new Rect(0, 0, TextDpi.FromTextDpi(_contentRect.du), TextDpi.FromTextDpi(_contentRect.dv));
                CaretElement.ClipGeometryByViewport(ref geometry, viewport);
            }
            return(geometry);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="startPosition"></param>
        /// <param name="endPosition"></param>
        /// <param name="visibleRect"></param>
        /// <returns></returns>
        internal Geometry GetTightBoundingGeometryFromTextPositions(ITextPointer startPosition, ITextPointer endPosition, Rect visibleRect)
        {
            Geometry geometry = null;

            // Find out if cell is selected. We consider cell selected if its end tag is crossed by selection.
            // The asymmetry is important here - it allows to use only normalized positions
            // and still be able to select individual cells.
            // Note that this logic is an assumption in textselection unit expansion mechanism
            // (TexSelection.ExtendSelectionToStructuralUnit method).
            if (endPosition.CompareTo(Cell.StaticElementEnd) >= 0)
            {
                geometry = new RectangleGeometry(_rect.FromTextDpi());
            }
            else
            {
                SubpageParagraphResult            paragraphResult = (SubpageParagraphResult)(CreateParagraphResult());
                ReadOnlyCollection <ColumnResult> colResults      = paragraphResult.Columns;
                Transform transform;

                transform   = new TranslateTransform(-TextDpi.FromTextDpi(ContentRect.u), -TextDpi.FromTextDpi(ContentRect.v));
                visibleRect = transform.TransformBounds(visibleRect);
                transform   = null;

                geometry = TextDocumentView.GetTightBoundingGeometryFromTextPositionsHelper(colResults[0].Paragraphs, paragraphResult.FloatingElements, startPosition, endPosition, 0.0, visibleRect);

                if (geometry != null)
                {
                    //  restrict geometry to the cell's content rect boundary.
                    //  because of end-of-line / end-of-para simulation calculated geometry could be larger.
                    Rect viewport = new Rect(0, 0, TextDpi.FromTextDpi(ContentRect.du), TextDpi.FromTextDpi(ContentRect.dv));
                    CaretElement.ClipGeometryByViewport(ref geometry, viewport);

                    transform = new TranslateTransform(TextDpi.FromTextDpi(ContentRect.u), TextDpi.FromTextDpi(ContentRect.v));
                    CaretElement.AddTransformToGeometry(geometry, transform);
                }
            }

            return(geometry);
        }
Пример #15
0
        // Token: 0x06006756 RID: 26454 RVA: 0x001CE084 File Offset: 0x001CC284
        internal bool GetPageNumberForContentPosition(TextPointer contentPosition, ref int pageNumber)
        {
            bool result = false;

            Invariant.Assert(pageNumber >= 0 && pageNumber <= this._breakRecords.Count, "Invalid PageNumber.");
            while (pageNumber < this._breakRecords.Count)
            {
                Invariant.Assert(this._breakRecords[pageNumber] != null, "Invalid BreakRecordTable entry.");
                ReadOnlyCollection <TextSegment> textSegments = this._breakRecords[pageNumber].TextSegments;
                if (textSegments == null)
                {
                    break;
                }
                if (TextDocumentView.Contains(contentPosition, textSegments))
                {
                    result = true;
                    break;
                }
                pageNumber++;
            }
            return(result);
        }