예제 #1
0
        private void PrintDocument_PrintTaskOptionsChanged(CanvasPrintDocument sender, CanvasPrintTaskOptionsChangedEventArgs args)
        {
            PrintPageDescription pageDesc = args.PrintTaskOptions.GetPageDescription(1);
            Vector2 newPageSize           = pageDesc.PageSize.ToVector2();

            if (_pageSize == newPageSize)
            {
                // We've already figured out the pages and the page size hasn't changed,
                // so there's nothing left for us to do here.
                return;
            }

            _pageSize = newPageSize;
            sender.InvalidatePreview();

            sender.SetPageCount(1);
            args.NewPreviewPageNumber = 1;
        }
예제 #2
0
        private async void PrintDocument_PrintTaskOptionsChanged(CanvasPrintDocument sender, CanvasPrintTaskOptionsChangedEventArgs args)
        {
            var deferral = args.GetDeferral();

            try
            {
                await EnsureBitmapsLoaded(sender);

                var pageDesc = args.PrintTaskOptions.GetPageDescription(1);
                var newPageSize = pageDesc.PageSize.ToVector2();

                if (pageSize == newPageSize && pageCount != -1)
                {
                    // We've already figured out the pages and the page size hasn't changed, so there's nothing left for us to do here.
                    return;
                }

                pageSize = newPageSize;
                sender.InvalidatePreview();

                // Figure out the bitmap index at the top of the current preview page.  We'll request that the preview defaults to showing
                // the page that still has this bitmap on it in the new layout.
                int indexOnCurrentPage = 0;
                if (pageCount != -1)
                {
                    indexOnCurrentPage = (int)(args.CurrentPreviewPageNumber - 1) * bitmapsPerPage;
                }

                // Calculate the new layout
                var printablePageSize = pageSize * 0.9f;

                cellSize = largestBitmap + imagePadding;

                var cellsPerPage = printablePageSize / cellSize;

                columns = Math.Max(1, (int)Math.Floor(cellsPerPage.X));
                rows = Math.Max(1, (int)Math.Floor(cellsPerPage.Y));

                bitmapsPerPage = columns * rows;

                // Calculate the page count
                bitmapCount = bitmaps.Count;
                pageCount = (int)Math.Ceiling(bitmapCount / (double)bitmapsPerPage);
                sender.SetPageCount((uint)pageCount);

                // Set the preview page to the one that has the item that was currently displayed in the last preview
                args.NewPreviewPageNumber = (uint)(indexOnCurrentPage / bitmapsPerPage) + 1;
            }
            finally
            {
                deferral.Complete();
            }
        }
        private async void PrintDocument_PrintTaskOptionsChanged(CanvasPrintDocument sender, CanvasPrintTaskOptionsChangedEventArgs args)
        {
            var deferral = args.GetDeferral();

            try
            {
                await EnsureBitmapsLoaded(sender);

                var pageDesc    = args.PrintTaskOptions.GetPageDescription(1);
                var newPageSize = pageDesc.PageSize.ToVector2();

                if (pageSize == newPageSize && pageCount != -1)
                {
                    // We've already figured out the pages and the page size hasn't changed, so there's nothing left for us to do here.
                    return;
                }

                pageSize = newPageSize;
                sender.InvalidatePreview();

                // Figure out the bitmap index at the top of the current preview page.  We'll request that the preview defaults to showing
                // the page that still has this bitmap on it in the new layout.
                int indexOnCurrentPage = 0;
                if (pageCount != -1)
                {
                    indexOnCurrentPage = (int)(args.CurrentPreviewPageNumber - 1) * bitmapsPerPage;
                }

                // Calculate the new layout
                var printablePageSize = pageSize * 0.9f;

                cellSize = largestBitmap + imagePadding;

                var cellsPerPage = printablePageSize / cellSize;

                columns = Math.Max(1, (int)Math.Floor(cellsPerPage.X));
                rows    = Math.Max(1, (int)Math.Floor(cellsPerPage.Y));

                bitmapsPerPage = columns * rows;

                // Calculate the page count
                bitmapCount = bitmaps.Count;
                pageCount   = (int)Math.Ceiling(bitmapCount / (double)bitmapsPerPage);
                sender.SetPageCount((uint)pageCount);

                // Set the preview page to the one that has the item that was currently displayed in the last preview
                args.NewPreviewPageNumber = (uint)(indexOnCurrentPage / bitmapsPerPage) + 1;
            }
            finally
            {
                deferral.Complete();
            }
        }