Beispiel #1
0
        public void PaintFill(IGraphics graphics, float angle, SizeF scale, RectangleF paintRect)
        {
            if (this.IsTransparent())
            {
                return;
            }
            Size desired = Size.Round(paintRect.Size);

            if (desired.Width <= 0 || desired.Height <= 0)
            {
                return;
            }
            graphics.ChangeSmoothingMode(this.fillElement.SmoothingMode);
            this.lastScale = scale;
            ElementShape elementShape = (ElementShape)null;

            if (this.primitiveElement != null)
            {
                elementShape = this.primitiveElement.GetCurrentShape();
            }
            else if (this.shapedElement != null)
            {
                elementShape = this.shapedElement.GetCurrentShape();
            }
            FillElementPaintBuffer elementPaintBuffer = this.FillElementPaintBuffer;

            if (elementShape != null && elementPaintBuffer != null)
            {
                string str       = elementShape.SerializeProperties();
                int    shapeHash = string.IsNullOrEmpty(str) ? elementShape.GetHashCode() : str.GetHashCode();
                elementPaintBuffer.SetShapeHash(shapeHash);
            }
            bool flag = elementPaintBuffer != null && !elementPaintBuffer.IsDisabled && elementPaintBuffer.ShouldUsePaintBuffer() && this.primitiveElement.ShouldUsePaintBuffer();

            try
            {
                if (flag)
                {
                    if (!this.primitiveElement.IsDesignMode && elementPaintBuffer.PaintFromBuffer(graphics, scale, desired))
                    {
                        graphics.RestoreSmoothingMode();
                        return;
                    }
                    graphics.ChangeOpacity(1.0);
                    if (!this.primitiveElement.IsDesignMode)
                    {
                        elementPaintBuffer.SetGraphics(graphics, scale);
                    }
                }
            }
            catch
            {
                flag = false;
            }
            GraphicsPath path = (GraphicsPath)null;

            if (elementShape != null)
            {
                path = elementShape.CreatePath(paintRect);
                graphics.PushCurrentClippingPath(path);
            }
            this.FillRectangle(graphics, paintRect);
            if (path != null)
            {
                graphics.PopCurrentClippingPath();
                path.Dispose();
            }
            if (flag)
            {
                graphics.RestoreOpacity();
                if (!this.primitiveElement.IsDesignMode)
                {
                    elementPaintBuffer.ResetGraphics(graphics, scale);
                }
            }
            graphics.RestoreSmoothingMode();
        }
Beispiel #2
0
        public void PaintFill(IGraphics graphics, float angle, SizeF scale, RectangleF paintRect)
        {
            if (this.IsTransparent())
            {
                return;
            }

            Size size = Size.Round(paintRect.Size);

            if ((size.Width <= 0) || (size.Height <= 0))
            {
                return;
            }

            this.lastScale = scale;

            ElementShape currentShape = this.primitiveElement.GetCurrentShape();

            //Check if we have already painded in PaintBuffer with this shape
            FillElementPaintBuffer paintBuffer = this.FillElementPaintBuffer;

            if (currentShape != null && paintBuffer != null)
            {
                string shapeProps = currentShape.SerializeProperties();
                int    shapeHash;
                if (!string.IsNullOrEmpty(shapeProps))
                {
                    shapeHash = shapeProps.GetHashCode();
                }
                else
                {
                    shapeHash = currentShape.GetHashCode();
                }

                paintBuffer.SetShapeHash(shapeHash);
            }

            //Graphics graphics = null;
            bool usePaintBuffer = paintBuffer != null && paintBuffer.ShouldUsePaintBuffer() && this.primitiveElement.ShouldUsePaintBuffer();

            try
            {
                if (usePaintBuffer)
                {
                    if (!this.primitiveElement.IsDesignMode && paintBuffer.PaintFromBuffer(graphics, scale, size))
                    {
                        return;
                    }
                    graphics.ChangeOpacity(1d);
                    if (!this.primitiveElement.IsDesignMode)
                    {
                        paintBuffer.SetGraphics(graphics, scale);
                    }
                }
            }
            catch
            {
                usePaintBuffer = false;
            }

            GraphicsPath clippingPath = null;

            if (currentShape != null)
            {
                clippingPath = currentShape.CreatePath(paintRect);
                graphics.PushCurrentClippingPath(clippingPath);
            }

            this.FillRectangle(graphics, paintRect);

            if (clippingPath != null)
            {
                graphics.PopCurrentClippingPath();
                clippingPath.Dispose();
            }

            if (usePaintBuffer)
            {
                graphics.RestoreOpacity();
                if (!this.primitiveElement.IsDesignMode)
                {
                    paintBuffer.ResetGraphics(graphics, scale);
                }
            }
        }