Exemplo n.º 1
0
        private void ReloadDocument()
        {
            if (Document == null)
            {
                return;
            }
            PageInfo.Clear();
            if (FThumbnailLarge != null)             //Reload document is always called first for the big preview and later for the thumbs.
            {
                FirstPageExportInfo = TImgExportInfo.Clone(FThumbnailLarge.FirstPageExportInfo);
            }
            else
            {
                FirstPageExportInfo = Document.GetFirstPageExportInfo();
            }

            FTotalPages    = FirstPageExportInfo.TotalPages;
            SavedStartPage = 0;

            ResizeCanvas(new Point(0, 0));
            OnZoomChanged(new EventArgs());
        }
Exemplo n.º 2
0
        internal Bitmap GetImage(int index)
        {
            TImgExportInfo ei = null;

            if (Count > 0)
            {
                ei = TImgExportInfo.Clone(this[Count - 1].ExportInfo);
            }
            else
            {
                ei = TImgExportInfo.Clone(Owner.FirstPageExportInfo);
            }

            for (int i = Count; i <= index; i++)
            {
                GetNextImage(ref ei, null);
                Add(new TPageInfo(TImgExportInfo.Clone(ei), null));
            }

            TPageInfo Pi = this[index];

            if (Pi.Bmp == null)
            {
                RectangleF Page = Pi.ExportInfo.ActiveSheet.PageBounds;
                Pi.Bmp = BitmapConstructor.CreateBitmap((int)(Page.Width * Owner.Zoom), (int)(Page.Height * Owner.Zoom));
                Pi.Bmp.SetResolution(96 * Owner.Zoom, 96 * Owner.Zoom);
                TImgExportInfo ExportInfo = null;
                if (index > 0)
                {
                    ExportInfo = TImgExportInfo.Clone(this[index - 1].ExportInfo);
                }
                else
                {
                    ExportInfo = TImgExportInfo.Clone(Owner.FirstPageExportInfo);
                }

                GetNextImage(ref ExportInfo, Pi.Bmp);
                CacheCount++;
            }

            //Bring the item to last position on the cache.
            if (Pi.Next != null)
            {
                Pi.Next.Prev = Pi.Prev;
                if (Pi.Prev != null)
                {
                    Pi.Prev.Next = Pi.Next;
                }
                else
                {
                    CacheFirst = Pi.Next;
                }
            }
            if (CacheFirst == null)
            {
                CacheFirst = Pi;
            }

            if (CacheLast != Pi)
            {
                Pi.Prev = CacheLast;
                if (CacheLast != null)
                {
                    CacheLast.Next = Pi;
                }
                CacheLast = Pi;
                Pi.Next   = null;
            }

            //If we have more bitmaps on the cache that what is allowed, delete the one at the first position.
            if (CacheFirst != null && CacheCount > 1 + Owner.CacheSize / (Owner.Zoom * Owner.Zoom))
            {
                if (CacheFirst.Next != null)
                {
                    CacheFirst.Bmp.Dispose();
                    CacheFirst.Bmp = null;
                    CacheCount--;

                    TPageInfo Next = CacheFirst.Next;
                    Next.Prev       = null;
                    CacheFirst.Next = null;
                    CacheFirst      = Next;
                }
            }

            Debug.Assert(CacheFirst == null || CacheFirst.Prev == null, "Error in cache");
            Debug.Assert(CacheLast == null || CacheLast.Next == null, "Error in cache");
            return(Pi.Bmp);
        }