コード例 #1
0
        public override void FillPage(PrintPageEventArgs e, System.Collections.ArrayList items, System.Collections.ArrayList coords)
        {
            while (true)
            {
                ImagePrintItem item = GetNextItem(e);

                if (e.Cancel == true || item == null)
                {
                    break;
                }

                if (_beginNewPage)
                {
                    AddToNonPlacedItems(item);
                    _beginNewPage = false;
                    break;
                }

                int printerResolutionX, printerResolutionY;
                GetValidatedResolution(e, out printerResolutionX, out printerResolutionY);

                Point location = new Point(PrintUtils.InchHundredthsToPixels(_placeholderLocation.X, printerResolutionX), PrintUtils.InchHundredthsToPixels(_placeholderLocation.Y, printerResolutionY));
                items.Add(item);
                coords.Add(location);
            }

            e.HasMorePages = HasMorePages();
        }
コード例 #2
0
        public ImagePrintItem Detach()
        {
            Size size = _rect.Size;

            size.Width  -= _horizontalSpacing + 1;
            size.Height -= _verticalSpacing + 1;

            _item.SetSize(size);
            ImagePrintItem item = _item;

            _item = null;

            return(item);
        }
コード例 #3
0
        public ItemRectangle(ImagePrintItem item, int verticalSpacing, int horizontalSpacing)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            _horizontalSpacing = horizontalSpacing;
            _verticalSpacing   = verticalSpacing;
            _item = item;

            Size size = _item.GetSize();

            size.Width  += _horizontalSpacing + 1 /*shared border*/;
            size.Height += _verticalSpacing + 1 /*shared border*/;
            _rect        = new Rectangle(new Point(0, 0), size);

            _square = _rect.Width * _rect.Height;

            _neighbours      = new ArrayList();
            _hostedPositions = new ArrayList();
        }
コード例 #4
0
        public override void FillPage(PrintPageEventArgs e, System.Collections.ArrayList items, System.Collections.ArrayList coords)
        {
            System.Diagnostics.Debug.Assert(items != null, "pItems should be allocated by caller");
            System.Diagnostics.Debug.Assert(coords != null, "pCoords should be allocated by caller");

            ImagePrintItem item = GetNextItem(e);

            if (e.Cancel == true || item == null)
            {
                e.HasMorePages = HasMorePages();
                return;
            }

            int printerResolutionX, printerResolutionY;

            GetValidatedResolution(e, out printerResolutionX, out printerResolutionY);

            int pageWidth  = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Width, printerResolutionX),
                pageHeight = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Height, printerResolutionY),
                marginX    = PrintUtils.InchHundredthsToPixels(e.MarginBounds.X, printerResolutionX),
                marginY    = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Y, printerResolutionY);

            Size pageSize = new Size(pageWidth, pageHeight);

            item.FitSize(pageSize, _printOptions.PlaceholderAutoRotate);
            Size itemSize = item.GetSize();

            Point coord = new Point();

            coord.X = marginX + (pageWidth - itemSize.Width) / 2;
            coord.Y = marginY + (pageHeight - itemSize.Height) / 2;

            items.Add(item);
            coords.Add(coord);
            e.HasMorePages = HasMorePages();
        }
コード例 #5
0
        public override void FillPage(PrintPageEventArgs e, System.Collections.ArrayList items, System.Collections.ArrayList coords)
        {
            System.Diagnostics.Debug.Assert(items != null, "pItems should be allocated by caller");
            System.Diagnostics.Debug.Assert(coords != null, "pCoords should be allocated by caller");

            int printerResolutionX, printerResolutionY;

            GetValidatedResolution(e, out printerResolutionX, out printerResolutionY);

            ConvertSpacings(printerResolutionX, printerResolutionY);

            int curX       = 0,
                curY       = 0,
                leftMargin = PrintUtils.InchHundredthsToPixels(e.MarginBounds.X, printerResolutionX),
                topMargin  = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Y, printerResolutionY),
                maxHeight  = -1,
                pageWidth  = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Width, printerResolutionX),
                pageHeight = PrintUtils.InchHundredthsToPixels(e.MarginBounds.Height, printerResolutionY);

            Size pageSize = new Size(pageWidth, pageHeight);

            bool isPageFilled = false;

            while (!isPageFilled)
            {
                bool isRowFilled = false;
                maxHeight = -1;

                while (!isRowFilled)
                {
                    ImagePrintItem item = GetNextItem(e);
                    if (e.Cancel == true)
                    {
                        return;
                    }

                    if (item == null)
                    {
                        isPageFilled = true;
                        break;
                    }

                    item.FitSize(pageSize, _printOptions.PlaceholderAutoRotate);
                    Size itemSize    = item.GetSize();
                    Size rotatedSize = item.GetSizeOfRotated();

                    // Trying to insert (maybe with rotation, if it allowed)
                    int freeSpaceWidth  = pageWidth - curX,
                        freeSpaceHeight = pageHeight - curY;

                    if (itemSize.Width <= freeSpaceWidth && itemSize.Height <= freeSpaceHeight)
                    {
                        // Item placed successfully
                        items.Add(item);
                        coords.Add(new Point(curX + leftMargin, curY + topMargin));

                        curX += itemSize.Width;

                        if (itemSize.Height > maxHeight)
                        {
                            maxHeight = itemSize.Height;
                        }
                    }
                    else if (_printOptions.PlaceholderAutoRotate && (rotatedSize.Width <= freeSpaceWidth && rotatedSize.Height <= freeSpaceHeight))
                    {
                        // Item placed successfully after a 90-degree rotate.
                        items.Add(item);
                        coords.Add(new Point(curX + leftMargin, curY + topMargin));

                        item.SetSize(rotatedSize);

                        curX += rotatedSize.Width;

                        if (rotatedSize.Height > maxHeight)
                        {
                            maxHeight = rotatedSize.Height;
                        }
                    }
                    else
                    {
                        // Item cannot be inserted into current row - putting it into
                        // NonPlacedItems queue for trying to insert into next rows.
                        AddToNonPlacedItems(item);
                        isRowFilled = true;
                    }

                    curX += _horizontalSpacing;
                    if (curX >= pageWidth)
                    {
                        isRowFilled = true;
                    }
                }

                // Shifting to next row. If intMaxHeight == -1 - this means that
                // no one Item has been inserted on current step => current Item
                // of the queue can be placed only on next page => this page is filled.
                if (maxHeight == -1)
                {
                    isPageFilled = true;
                }
                else
                {
                    curX  = 0;
                    curY += maxHeight + _verticalSpacing;
                    if (curY > pageHeight)
                    {
                        isPageFilled = true;
                    }
                }
            }

            e.HasMorePages = HasMorePages();
        }
コード例 #6
0
 protected void AddToNonPlacedItems(ImagePrintItem item)
 {
     _nonPlacedItems.Add(item);
 }
コード例 #7
0
        protected virtual ImagePrintItem GetNextItem(PrintPageEventArgs e)
        {
            if (!_eventHasMoreImages)
            {
                return(null);
            }

            // Getting next image & info from IImageProvider
            PrintPlaceholder imagePlaceholder;

            if (_imageProvider != null && !_imageProvider.IsEmpty())
            {
                imagePlaceholder = _imageProvider.GetNext();
            }
            else
            {
                imagePlaceholder = new PrintPlaceholder();
            }

            // Firing PrintImage event in ImagePrintDocument
            QueryImageEventArgs queryImageEventArgs = new QueryImageEventArgs();

            queryImageEventArgs.PrintPlaceholder = imagePlaceholder;
            queryImageEventArgs.PrintOptions     = _printOptions;
            OnQueryImageEvent(queryImageEventArgs);

            if (queryImageEventArgs.Cancel == true || queryImageEventArgs.PrintPlaceholder.Image == null)
            {
                e.Cancel = true;
                return(null);
            }

            int printerResolutionX, printerResolutionY;

            GetValidatedResolution(e, out printerResolutionX, out printerResolutionY);

            // If we didn't got image from IImageProvider or from user's handler
            // of PrintImage event - just return null.
            if (imagePlaceholder.Image == null)
            {
                return(null);
            }

            // Filling result ImagePrintItem
            ImagePrintItem item = new ImagePrintItem(printerResolutionX, printerResolutionY);

            item.Image             = imagePlaceholder.Image;
            item.ImageFitMode      = _printOptions.ImageFitMode;
            item.ImageAutoRotate   = _printOptions.ImageAutoRotate;
            item.InterpolationMode = _printOptions.InterpolationMode;
            item.HeaderFont        = _printOptions.HeaderFont;
            item.FooterFont        = _printOptions.FooterFont;
            item.HeaderColor       = _printOptions.HeaderColor;
            item.FooterColor       = _printOptions.FooterColor;
            item.HeaderTrimmming   = _printOptions.HeaderTrimming;
            item.FooterTrimmming   = _printOptions.FooterTrimming;
            item.HeaderAlignment   = _printOptions.HeaderAlignment;
            item.FooterAlignment   = _printOptions.FooterAlignment;

            // Header & footer
            if (_printOptions.HeaderEnabled)
            {
                item.HeaderText = imagePlaceholder.Header;
            }
            if (_printOptions.FooterEnabled)
            {
                item.FooterText = imagePlaceholder.Footer;
            }

            if (_printOptions.BorderEnabled)
            {
                int pixelWidth = PrintUtils.InchHundredthsToPixels(_printOptions.BorderWidth, printerResolutionX);
                item.BorderPen = new System.Drawing.Pen(_printOptions.BorderColor, pixelWidth);
            }

            // Setting external size. Size can be redefined in QueryImageEventHandler
            if (imagePlaceholder.Size.Width != 0 && imagePlaceholder.Size.Height != 0)
            {
                Size resizeSize = new Size();
                resizeSize.Width  = PrintUtils.InchHundredthsToPixels(imagePlaceholder.Size.Width, printerResolutionX);
                resizeSize.Height = PrintUtils.InchHundredthsToPixels(imagePlaceholder.Size.Height, printerResolutionY);

                item.SetSize(resizeSize);
            }
            else if (_printOptions.PlaceholderSize.Width != 0 && _printOptions.PlaceholderSize.Height != 0)
            {
                Size resizeSize = new Size();
                resizeSize.Width  = PrintUtils.InchHundredthsToPixels(_printOptions.PlaceholderSize.Width, printerResolutionX);
                resizeSize.Height = PrintUtils.InchHundredthsToPixels(_printOptions.PlaceholderSize.Height, printerResolutionY);

                item.SetSize(resizeSize);
            }

            return(item);
        }