Beispiel #1
0
 public void Subscribe(PageViewControlState state, Action <DjvuPage, TextLayerZone, CancellationToken> callback, CancellationToken ct)
 {
     lock (_tasks)
     {
         _tasks.Enqueue(new Obj {
             State = state, Callback = callback, CancellationToken = ct
         });
     }
 }
        private void OnStateChanged(PageViewControlState oldValue, PageViewControlState newValue)
        {
            CleanUp();

            _pageDecodingCts?.Cancel();

            if (newValue != null)
            {
                _pageDecodingCts = new CancellationTokenSource();
                PageLoadScheduler.Instance.Subscribe(newValue, PageDecodedHandler, _pageDecodingCts.Token);
            }
        }
        private void Load()
        {
            if (Source == null || _containerSize == null)
            {
                return;
            }

            _pageViewObserver = new PageViewObserver();

            var pageInfos    = Source.GetPageInfos();
            var maxPageWidth = pageInfos.Max(pageInfo => pageInfo.Width);

            _pageStates = new PageViewControlState[Source.PageCount];

            for (uint i = 0; i < _pageStates.Length; i++)
            {
                var    pageInfo   = pageInfos[i];
                double pageWidth  = pageInfo.Width;
                double pageHeight = pageInfo.Height;

                var scaleFactor = pageWidth / maxPageWidth;
                var aspectRatio = pageWidth / pageHeight;
                var width       = scaleFactor * _containerSize.Value.Width;
                var height      = width / aspectRatio;

                _pageStates[i] = new PageViewControlState(
                    document: Source,
                    pageNumber: i + 1,
                    width: width,
                    height: height,
                    zoomFactorObserver: _pageViewObserver);
            }

            PageNumber           = 1;
            listView.ItemsSource = _pageStates;
        }