Пример #1
0
 /// <summary>
 /// Determine the visible page range
 /// </summary>
 /// <returns></returns>
 private PageRange FindVisibleRange()
 {
     // Find a visible page,
     int visiblePage = FindVisiblePage();
     if (visiblePage <= 0)
     {
         AppEventSource.Log.Warn("ViewerPage: No visible page found.");
         return new PageRange(1, 1);
     }
     // Find the pages that are currently visible
     PageRange range = new PageRange(visiblePage, visiblePage);
     // Find the first visible page
     for (int i = 1; i <= pageCount; i++)
     {
         if (!IsPageVisible(visiblePage - i))
         {
             range.first = visiblePage - i + 1;
             break;
         }
     }
     // Find the last visible page
     for (int i = 1; i <= pageCount; i++)
     {
         if (!IsPageVisible(visiblePage + i))
         {
             range.last = visiblePage + i - 1;
             break;
         }
     }
     return range;
 }
Пример #2
0
 /// <summary>
 /// This method is not used. 
 /// </summary>
 private void SetMinZoomFactor()
 {
     if (!this.fileLoaded) return;
     // Store current zoom factor
     double factor = scrollViewer.ZoomFactor;
     // Update visible page range
     this._visiblePageRange = FindVisibleRange();
     // Find the max page height and width in the visible pages
     double maxHeight = 0;
     double maxWidth = 0;
     for (int i = this.VisiblePageRange.first; i <= this.VisiblePageRange.last; i++)
     {
         Image image = (Image)this.imagePanel.FindName(PREFIX_PAGE + i.ToString());
         if (image.ActualHeight > maxHeight) maxHeight = image.ActualHeight;
         if (image.ActualWidth > maxWidth) maxWidth = image.MaxWidth;
     }
     // Recalculate min zoom factor
     double hZoomFactor = (this.scrollViewer.ActualHeight - SCROLLBAR_WIDTH
         - 2 * (PAGE_IMAGE_MARGIN + imagePanel.Margin.Top)) / maxHeight;
     double wZoomFactor = (this.scrollViewer.ActualWidth - SCROLLBAR_WIDTH
         - 2 * (PAGE_IMAGE_MARGIN + imagePanel.Margin.Left)) / maxWidth;
     if (hZoomFactor < 0.1)
     {
         hZoomFactor = 0.1;
         AppEventSource.Log.Debug("ViewerPage: Minimum vertical zoom factor is too small");
     }
     if (wZoomFactor < 0.1)
     {
         wZoomFactor = 0.1;
         AppEventSource.Log.Debug("ViewerPage: Minimum horizontal zoom factor is too small");
     }
     this.scrollViewer.MinZoomFactor = (float)Math.Min(hZoomFactor, wZoomFactor);
     // Recalculate offsets if zoom level changed
     if (this.scrollViewer.MinZoomFactor > factor)
     {
         factor = this.scrollViewer.MinZoomFactor / factor;
         scrollViewer.ChangeView(factor * scrollViewer.HorizontalOffset,
             factor * scrollViewer.VerticalOffset, scrollViewer.ZoomFactor, true);
         AppEventSource.Log.Debug("ViewerPage: zoom factor changed, offsets recalculated.");
     }
 }
Пример #3
0
 /// <summary>
 /// Prepare a range of pages to be displayed. Visiable pages and buffer pages (before/after the visible pages)
 /// are added to a queue for rendering. Other pages are added to the recycle queue so that memeory will be release
 /// when the a page is removed later.
 /// </summary>
 /// <param name="range"></param>
 private void PreparePages(PageRange range)
 {
     // Add invisible pages to recycle list
     for (int i = inkingPageRange.first - SIZE_PAGE_BUFFER; i <= inkingPageRange.last + SIZE_PAGE_BUFFER; i++)
     {
         if ((i < range.first - SIZE_PAGE_BUFFER || i > range.last + SIZE_PAGE_BUFFER)
             && i > 0 && i <= pageCount)
             this.recyclePagesQueue.Enqueue(i);
     }
     // Update inking range
     this.inkingPageRange = range;
     // Clear render page queue
     this.renderPagesQueue.Clear();
     // Add visible pages to queue
     for (int i = range.first; i <= range.last; i++)
     {
         if (i > 0 && i <= pageCount)
             renderPagesQueue.Enqueue(i);
     }
     // Add buffer pages to queue
     for (int i = range.first - SIZE_PAGE_BUFFER; i <= range.last + SIZE_PAGE_BUFFER; i++)
     {
         if (i > 0 && i <= pageCount && !renderPagesQueue.Contains(i))
             renderPagesQueue.Enqueue(i);
     }
     // Start rendering pages
     if (!this.isRenderingPage)
         RenderPages();
 }
Пример #4
0
 private async void FinishInitialization()
 {
     this.fullScreenCover.Visibility = Visibility.Collapsed;
     this.imagePanel.UpdateLayout();
     // Load viewer state
     await LoadViewerState();
     RestoreViewerState();
     // Load inking
     inkManager = await InkingManager.InitializeInking(dataFolder);
     // Make sure about the visible page range
     this._visiblePageRange = FindVisibleRange();
     this.fileLoaded = true;
     this.fileLoadingWatch.Stop();
     RefreshViewer();
     AppEventSource.Log.Info("ViewerPage: Finished Preparing the file in " + fileLoadingWatch.Elapsed.TotalSeconds.ToString());
     this.zoomOutGrid.ItemsSource = pageThumbnails;
     this.recycleTimer.Start();
 }
Пример #5
0
 private void InitializeZoomInView()
 {
     this.imagePanel.Children.Clear();
     this.imagePanel.UpdateLayout();
     this.inkingPageRange = new PageRange();
     this._visiblePageRange = new PageRange();
     this._viewerKey = new Guid();
     this.pageCount = 0;
     this.inkCanvasList = new List<int>();
     this.renderedPages = new List<int>();
     this.recyclePagesQueue = new Queue<int>();
     this.renderPagesQueue = new Queue<int>();
     this.isRenderingPage = false;
     this.inkProcessMode = InkInputProcessingMode.Inking;
     this.recycleTimer.Stop();
     this.fullScreenCover.Visibility = Visibility.Visible;
     this.fullScreenMessage.Text = DEFAULT_FULL_SCREEN_MSG;
     this.pageNumberTextBlock.Text = "";
     this.filenameTextBlock.Text = "";
     this.imagePanel.Orientation = Orientation.Vertical;
     this.semanticZoom.IsZoomedInViewActive = true;
     ClearViewModeToggleBtn();
     this.VerticalViewBtn.IsChecked = true;
     this.pageThumbnails = null;
     if (NavigationPage.Current != null) NavigationPage.Current.InitializeViewBtn();
     AppEventSource.Log.Debug("ViewerPage: Viewer panel and settings initialized.");
 }
Пример #6
0
 private void scrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
 {
     // Determine visible page range
     this._visiblePageRange = FindVisibleRange();
     // Show page number
     this.pageNumberTextBlock.Text = this.VisiblePageRange.ToString() + " / " + this.pageCount.ToString();
     // Show zoom level
     this.zoomFactorTextBlock.Text = ((int)(this.scrollViewer.ZoomFactor * 100)).ToString() + "%";
     // Show information grid
     this.infoGrid.Opacity = INFO_GRID_OPACITY;
     // The following code acts like a filter to prevent the timer ticking too frequently
     if (fileLoaded && !e.IsIntermediate)
     {
         refreshTimer.Stop();
         refreshTimer.Start();
         pageNumberTextTimer.Stop();
         pageNumberTextTimer.Start();
     }
 }
Пример #7
0
        public static ViewerState SaveViewerState(string futureAccessToken, ScrollViewer scrollViewer, StackPanel imagePanel, PageRange visibleRange)
        {
            ViewerState viewerState = new ViewerState(futureAccessToken)
            {
                hOffset = scrollViewer.HorizontalOffset,
                vOffset = scrollViewer.VerticalOffset,
                zFactor = scrollViewer.ZoomFactor,

                panelWidth  = imagePanel.ActualWidth,
                panelHeight = imagePanel.ActualHeight,

                visibleRange = visibleRange,
                lastViewed   = DateTime.Now
            };

            if (imagePanel.Orientation == Orientation.Horizontal)
            {
                viewerState.isHorizontalView = true;
            }

            return(viewerState);
        }