/// <summary> /// Reset all relevat status fields. /// </summary> private void ResetStatus() { _verticalOffset = 0d; _workArea = new Size(0, 0); _renderedPages.Clear(); _onTouchDownPage = null; }
/// <summary> /// <inheritdoc/> /// </summary> protected override void OnTouchDown(TouchEventArgs e) { base.OnTouchDown(e); if (e != null) { var point = e.GetTouchPoint(this).Position; _onTouchDownPage = _renderedPages.FirstOrDefault(p => point.X > p.Left && point.X <p.Right && point.Y> p.Top && point.Y < p.Bottom); } }
/// <summary> /// <inheritdoc/> /// </summary> public IList <IPDFPageRenderInfo> DeterminePagesToRender(IPDFPageRenderInfo pageOnCenter, ref double topLine, ref double bottomLine, double pageMargin, double zoomFactor) { return(DeterminePagesToRenderVirtual(pageOnCenter, ref topLine, ref bottomLine, pageMargin, zoomFactor)); }
/// <summary> /// Gets all pages to be drawn in specified region. /// </summary> /// <param name="pageOnCenter">The page on which is center of vertical direction of the viewport.</param> /// <param name="topLine">Top line of viewport.</param> /// <param name="bottomLine">Bottom line of viewport.</param> /// <param name="pageMargin">Margin around the page.</param> /// <param name="zoomFactor">Zoom factor to use for pages. Not for page margin.</param> /// <returns>Pages to draw in required region.</returns> protected virtual IList <IPDFPageRenderInfo> DeterminePagesToRenderVirtual(IPDFPageRenderInfo pageOnCenter, ref double topLine, ref double bottomLine, double pageMargin, double zoomFactor) { // Base check. if (pageOnCenter == null || !pageOnCenter.IsOnCenter || pageOnCenter.Page == null || pageOnCenter.Page.PageIndex >= PageComponent.PageCount) { // We don't have required information. return(DeterminePagesToRenderVirtual(topLine, bottomLine, pageMargin, zoomFactor)); } // Height of viewport. var height = bottomLine - topLine; // Let's say, the middle point of height is on position 0. Create virtual top line. var virtualTopLine = -1d * (bottomLine - topLine) / 2d; // List of all pages to render. var list = new List <IPDFPageRenderInfo>(); // Let's take the page witch vertical center on it has this point on position 0. // We'll correct all top and bottom lines later. var pageOnMiddle = new PDFPageRenderInfo(pageOnCenter.Page) { Left = 0, Right = PageWidth(pageOnCenter.Page) * zoomFactor, Top = -1d * pageOnCenter.PagePositionOnCenter * PageHeight(pageOnCenter.Page) * zoomFactor, Bottom = (1d - pageOnCenter.PagePositionOnCenter) * PageHeight(pageOnCenter.Page) * zoomFactor, IsOnCenter = pageOnCenter.IsOnCenter, PagePositionOnCenter = pageOnCenter.PagePositionOnCenter, }; // Add this page to the list. list.Add(pageOnMiddle); // Current position on Y-axis. var currentPositionOnY = pageOnMiddle.Top; currentPositionOnY -= pageMargin; // Iterate through pages from 'page on middle' to the first page. // Iterate through all of them, don't break on page above virtual top line. for (var index = pageOnCenter.Page.PageIndex - 1; index >= 0; index--) { // Get page to check. var page = PageComponent.Pages[index]; // Check the curreint position on y relative to the virtual top line. if (currentPositionOnY > virtualTopLine) { // This page is still visible. var nextPageToAdd = new PDFPageRenderInfo(page) { Left = 0, Right = PageWidth(page) * zoomFactor, Top = currentPositionOnY - (PageHeight(page) * zoomFactor), Bottom = currentPositionOnY, }; // Insert this page to the first position of list. list.Insert(0, nextPageToAdd); } // Adjust current position on y. currentPositionOnY -= PageHeight(page) * zoomFactor; currentPositionOnY -= pageMargin; } // Set new top and bottom line returned back. topLine = (-1d * currentPositionOnY) - (height / 2d); bottomLine = topLine + height; // A negative top line means that the first page is displayed and not positioned at the top. if (topLine < 0d) { topLine = 0d; bottomLine = topLine + height; currentPositionOnY = pageMargin; // Adjust top and bottom line of all already added pages to render. foreach (var pageRenderInfo in list) { pageRenderInfo.Top = currentPositionOnY; pageRenderInfo.Bottom = currentPositionOnY + (PageHeight(pageRenderInfo.Page) * zoomFactor); // Adjust current position on y axis. currentPositionOnY += pageMargin + (PageHeight(pageRenderInfo.Page) * zoomFactor); } } else { // Adjust top and bottom line of all already added pages to render. foreach (var pageRenderInfo in list) { pageRenderInfo.Top += topLine + (height / 2d); pageRenderInfo.Bottom += topLine + (height / 2d); currentPositionOnY = pageRenderInfo.Bottom; } // Adjust current position on y axis. currentPositionOnY += pageMargin; } // Iterate through pages from 'page on middle' to the last page. for (var index = pageOnCenter.Page.PageIndex + 1; index < PageComponent.Pages.Count; index++) { // Filter out all pages below bottom line. if (currentPositionOnY > bottomLine) { // Page is below bottom line. // End foreach. break; } // Part of this page is between top and bottom line. // Add this page to the list. var nextPageToAdd = new PDFPageRenderInfo(PageComponent.Pages[index]) { Left = 0, Right = PageWidth(PageComponent.Pages[index]) * zoomFactor, Top = currentPositionOnY, Bottom = currentPositionOnY + (PageHeight(PageComponent.Pages[index]) * zoomFactor), }; // Add the page to the list. list.Add(nextPageToAdd); // Adjust current position on y axis. currentPositionOnY += pageMargin + (PageHeight(PageComponent.Pages[index]) * zoomFactor); } return(list); }