Esempio n. 1
0
 /// <summary>
 /// get page async.
 /// </summary>
 /// <param name="pageNumber">The page number.</param>
 /// <param name="userState">The user state.</param>
 public override void GetPageAsync(int pageNumber, object userState)
 {
     flowDocPaginator.GetPageAsync(pageNumber, userState);
 }
        /// <summary>
        /// Content measurement.
        /// </summary>
        /// <param name="availableSize">Available size that parent can give to the child. This is soft constraint.</param>
        /// <returns>The DocumentPageView's desired size.</returns>
        protected override sealed Size MeasureOverride(Size availableSize)
        {
            Size newPageSize, pageZoom;
            Size pageSize;
            Size desiredSize = new Size(); // If no page is available, return (0,0) as size.

            CheckDisposed();

            if (_suspendLayout)
            {
                desiredSize = this.DesiredSize;
            }
            else if (_documentPaginator != null)
            {
                // Reflow content if needed.
                if (ShouldReflowContent())
                {
                    // Reflow is disabled when dealing with infinite size in both directions.
                    // If only one dimention is infinte, calculate value based on PageSize of the
                    // document and Stretching properties.
                    if (!Double.IsInfinity(availableSize.Width) || !Double.IsInfinity(availableSize.Height))
                    {
                        pageSize = _documentPaginator.PageSize;
                        if (Double.IsInfinity(availableSize.Width))
                        {
                            newPageSize = new Size();
                            newPageSize.Height = availableSize.Height / _pageZoom;
                            newPageSize.Width = newPageSize.Height * (pageSize.Width / pageSize.Height); // Keep aspect ratio.
                        }
                        else if (Double.IsInfinity(availableSize.Height))
                        {
                            newPageSize = new Size();
                            newPageSize.Width = availableSize.Width / _pageZoom;
                            newPageSize.Height = newPageSize.Width * (pageSize.Height / pageSize.Width); // Keep aspect ratio.
                        }
                        else
                        {
                            newPageSize = new Size(availableSize.Width / _pageZoom, availableSize.Height / _pageZoom);
                        }
                        if (!DoubleUtil.AreClose(pageSize, newPageSize))
                        {
                            _documentPaginator.PageSize = newPageSize;
                        }
                    }
                }

                // If the main page or pending async page are not available yet,
                // asynchronously request new page from Paginator.
                if (_documentPage == null && _documentPageAsync == null)
                {
                    if (PageNumber >= 0)
                    {
                        if (_useAsynchronous)
                        {
                            _documentPaginator.GetPageAsync(PageNumber, this);
                        }
                        else
                        {
                            _documentPageAsync = _documentPaginator.GetPage(PageNumber);
                            if (_documentPageAsync == null)
                            {
                                _documentPageAsync = DocumentPage.Missing;
                            }
                        }
                    }
                    else
                    {
                        _documentPage = DocumentPage.Missing;
                    }
                }

                // If pending async page is available, discard the main page and
                // set _documentPage to _documentPageAsync.
                if (_documentPageAsync != null)
                {
                    // Do cleanup for currently used page, because it gets replaced.
                    DisposeCurrentPage();
                    // DisposeCurrentPage raises PageDisposed and DocumentPage.PageDestroyed events.
                    // Handlers for those events may dispose _documentPageAsync. Treat this situation
                    // as missing page.
                    if (_documentPageAsync == null)
                    {
                        _documentPageAsync = DocumentPage.Missing;
                    }
                    if (_pageVisualClone != null)
                    {
                        RemoveDuplicateVisual();
                    }

                    // Replace the main page with cached async page.
                    _documentPage = _documentPageAsync;
                    if (_documentPage != DocumentPage.Missing)
                    {
                        _documentPage.PageDestroyed += new EventHandler(HandlePageDestroyed);
                        _documentPageAsync.PageDestroyed -= new EventHandler(HandleAsyncPageDestroyed);
                    }
                    _documentPageAsync = null;

                    // Set a flag that will indicate that a PageConnected must be fired in
                    // ArrangeOverride
                    _newPageConnected = true;
                }

                // If page is available, return its size as desired size.
                if (_documentPage != null && _documentPage != DocumentPage.Missing)
                {
                    pageSize = new Size(_documentPage.Size.Width * _pageZoom, _documentPage.Size.Height * _pageZoom);
                    pageZoom = Viewbox.ComputeScaleFactor(availableSize, pageSize, this.Stretch, this.StretchDirection);
                    desiredSize = new Size(pageSize.Width * pageZoom.Width, pageSize.Height * pageZoom.Height);
                }

                if (_pageVisualClone != null)
                {
                    desiredSize = _visualCloneSize;
                }
            }

            return desiredSize;
        }