Exemple #1
0
        protected void FillImagePrintInfo(PrintPlaceholder placeholder, object source)
        {
            if (source == null)
            {
                return;
            }

            if (_receivesOnlyBitmaps)
            {
                placeholder.Image    = (Bitmap)source;
                placeholder.Location = Point.Empty;
                placeholder.Size     = Size.Empty;
                placeholder.Header   = null;
                placeholder.Footer   = null;
            }
            else
            {
                PrintPlaceholder receivedPlaceholder = (PrintPlaceholder)source;
                placeholder.Image    = receivedPlaceholder.Image;
                placeholder.Location = receivedPlaceholder.Location;
                placeholder.Size     = receivedPlaceholder.Size;
                placeholder.Header   = receivedPlaceholder.Header;
                placeholder.Footer   = receivedPlaceholder.Footer;
            }
        }
Exemple #2
0
        public FromIEnumeratorProvider(IEnumerator enumerator)
        {
            if (enumerator == null)
            {
                throw new ArgumentNullException("pEnumerator");
            }

            _enumerator = enumerator;
            _isEmpty    = !enumerator.MoveNext();
            if (!_isEmpty)
            {
                object obj = enumerator.Current;
                if (obj == null)
                {
                    _isEmpty = true;
                    return;
                }

                Type type = obj.GetType();
                if (type == typeof(Bitmap))
                {
                    _receivesOnlyBitmaps = true;
                }
                else if (type != typeof(PrintPlaceholder))
                {
                    throw new ArgumentException(StringResources.GetString("UnexpectedParameterType"), "pEnumerator");
                }

                _next = new PrintPlaceholder();
                FillImagePrintInfo(_next, obj);
            }
        }
Exemple #3
0
        public virtual PrintPlaceholder GetNext()
        {
            _isEmpty = !_enumerator.MoveNext();
            PrintPlaceholder result = _next;

            _next = null;

            if (!_isEmpty)
            {
                Object source = _enumerator.Current;
                if (source != null)
                {
                    _next = new PrintPlaceholder();
                    FillImagePrintInfo(_next, source);
                }
                else
                {
                    _isEmpty = true;
                }
            }

            return(result);
        }
        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);
        }