Esempio n. 1
0
        /// <summary>
        /// Creates an image for the given arguments.
        /// </summary>
        public static Image CreateImage(mxGraph graph, Object[] cells, double scale, Color? background,
            bool antiAlias, mxRectangle clip, mxGdiCanvas graphicsCanvas)
        {
            mxImageCanvas canvas = (mxImageCanvas) DrawCells(graph, cells, scale, clip,
                new ImageCanvasFactory(graphicsCanvas, background, antiAlias));

            return canvas.Destroy();
        }
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="background"></param>
        /// <param name="antiAlias"></param>
        public mxImageCanvas(mxGdiCanvas canvas, int width, int height,
            Color? background, bool antiAlias)
        {
            this.canvas = canvas;
            previousGraphics = canvas.Graphics;
            image = mxUtils.CreateImage(width, height, background);

            if (image != null)
            {
                Graphics g = Graphics.FromImage(image);

                if (antiAlias)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;
                }

                canvas.Graphics = g;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Creates the canvas for rendering the stencil.
 /// </summary>
 /// <param name="gc"></param>
 /// <returns></returns>
 protected mxGdiCanvas2D CreateCanvas(mxGdiCanvas gc)
 {
     return new mxGdiCanvas2D(gc.Graphics);
 }
Esempio n. 4
0
        /// <summary>
        /// Paints the stencil for the given state.
        /// </summary>
        public void PaintShape(mxGdiCanvas gc, mxCellState state)
        {
            mxGdiCanvas2D canvas = CreateCanvas(gc);
            Dictionary<string, object> style = state.Style;

            double rotation = mxUtils.GetDouble(style, mxConstants.STYLE_ROTATION,
                    0);
            String direction = mxUtils.GetString(style,
                    mxConstants.STYLE_DIRECTION, null);

            // Default direction is east (ignored if rotation exists)
            if (direction != null)
            {
                if (direction.Equals("north"))
                {
                    rotation += 270;
                }
                else if (direction.Equals("west"))
                {
                    rotation += 180;
                }
                else if (direction.Equals("south"))
                {
                    rotation += 90;
                }
            }

            // New styles for shape flipping the stencil
            bool flipH = mxUtils.IsTrue(style, mxConstants.STYLE_STENCIL_FLIPH,
                    false);
            bool flipV = mxUtils.IsTrue(style, mxConstants.STYLE_STENCIL_FLIPV,
                    false);

            if (flipH && flipV)
            {
                rotation += 180;
                flipH = false;
                flipV = false;
            }

            // Saves the global state for each cell
            canvas.Save();

            // Adds rotation and horizontal/vertical flipping
            rotation = rotation % 360;

            if (rotation != 0 || flipH || flipV)
            {
                canvas.Rotate(rotation, flipH, flipV, state.GetCenterX(),
                        state.GetCenterY());
            }

            // Note: Overwritten in mxStencil.paintShape (can depend on aspect)
            double scale = state.View.Scale;
            double sw = mxUtils.GetDouble(style, mxConstants.STYLE_STROKEWIDTH, 1)
                    * scale;
            canvas.StrokeWidth = sw;

            double alpha = mxUtils.GetDouble(style, mxConstants.STYLE_OPACITY, 100) / 100;
            String gradientColor = mxUtils.GetString(style,
                    mxConstants.STYLE_GRADIENTCOLOR, null);

            // Converts colors with special keyword none to null
            if (gradientColor != null && gradientColor.Equals(mxConstants.NONE))
            {
                gradientColor = null;
            }

            String fillColor = mxUtils.GetString(style,
                    mxConstants.STYLE_FILLCOLOR, null);

            if (fillColor != null && fillColor.Equals(mxConstants.NONE))
            {
                fillColor = null;
            }

            String strokeColor = mxUtils.GetString(style,
                    mxConstants.STYLE_STROKECOLOR, null);

            if (strokeColor != null && strokeColor.Equals(mxConstants.NONE))
            {
                strokeColor = null;
            }

            // Draws the shadow if the fillColor is not transparent
            if (mxUtils.IsTrue(style, mxConstants.STYLE_SHADOW, false))
            {
                DrawShadow(canvas, state, rotation, flipH, flipV, state, alpha, fillColor != null);
            }

            canvas.Alpha = alpha;

            // Sets the dashed state
            if (mxUtils.IsTrue(style, mxConstants.STYLE_DASHED, false))
            {
                canvas.Dashed = true;
            }

            // Draws background and foreground
            if (strokeColor != null || fillColor != null)
            {
                if (strokeColor != null)
                {
                    canvas.StrokeColor = strokeColor;
                }

                if (fillColor != null)
                {
                    if (gradientColor != null
                            && !gradientColor.Equals("transparent"))
                    {
                        canvas.SetGradient(fillColor, gradientColor, state.X,
                                state.Y, state.Width, state.Height,
                                direction);
                    }
                    else
                    {
                        canvas.FillColor = fillColor;
                    }
                }

                // Draws background and foreground of shape
                DrawShape(canvas, state, state, true);
                DrawShape(canvas, state, state, false);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Constructs a new image canvas factors.
 /// </summary>
 /// <param name="graphicsCanvas">Specifies the graphics canvas for painting.</param>
 /// <param name="background">Specifies the background color of the image.</param>
 /// <param name="antiAlias">Specifies if antialiasing should be enabled.</param>
 public ImageCanvasFactory(mxGdiCanvas graphicsCanvas, Color? background, bool antiAlias)
 {
     this.graphicsCanvas = graphicsCanvas;
     this.background = background;
     this.antiAlias = antiAlias;
 }
Esempio n. 6
0
        /// <summary>
        /// Destroys this canvas and all allocated resources.
        /// </summary>
        public Image Destroy()
        {
            Image tmp = image;

            canvas.Graphics.Dispose();
            canvas.Graphics = previousGraphics;

            previousGraphics = null;
            canvas = null;
            image = null;

            return tmp;
        }